先看效果图
![]() |
GY-85.py:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import curses
from time import *
from i2clibraries import i2c_itg3205, i2c_adxl345, i2c_hmc5883l
#==========================================================
# GY-85传感器监控
#==========================================================
def displayITG3205(screen, col, temp, x, y, z):
"""
显示ITG3205读数的方法
"""
screen.addstr(1, col, "%.1f°℃ " % temp)
screen.addstr(2, col, "%.1f°/s " % x)
screen.addstr(3, col, "%.1f°/s " % y)
screen.addstr(4, col, "%.1f°/s " % z)
def displayADXL345(screen, col, x, y, z):
"""
显示ADXL345读数的方法
"""
screen.addstr(1, col, "%.2fmg " % x)
screen.addstr(2, col, "%.2fmg " % y)
screen.addstr(3, col, "%.2fmg " % z)
def displayHMC5883L(screen, col, heading, declination, x, y, z):
"""
显示MC5883L读数的方法
"""
screen.addstr(1, col, heading + " ")
screen.addstr(2, col, declination + " ")
screen.addstr(3, col, "%.2f " % x)
screen.addstr(4, col, "%.2f " % y)
screen.addstr(5, col, "%.2f " % z)
try:
myscreen = curses.initscr() #初始化curses
myscreen.border(0)
(screen_h, screen_w) = myscreen.getmaxyx() #获得屏幕高宽
curses.start_color() #设置颜色
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN) #绿底黑字
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) #白底蓝字
curses.init_pair(3, curses.COLOR_MAGENTA,curses.COLOR_BLACK) #黑底什么字
myscreen.clear() #清除画布
# 计算每块的坐标, 屏幕分3列, 每列显示一个传感器
col1 = screen_w / 3 * 0
col2 = screen_w / 3 * 1
col3 = screen_w / 3 * 2
# 屏幕横向分三块,每块中间写上标题
myscreen.addstr(0, int(col1 + screen_w / 3 / 2 - 3), "IGT3205", curses.color_pair(1))
myscreen.addstr(0, int(col2 + screen_w / 3 / 2 - 4), "ADXL345", curses.color_pair(1))
myscreen.addstr(0, int(col3 + screen_w / 3 / 2 - 4), "HMC5883L", curses.color_pair(1))
#画分割线,把屏幕分为3列
for col in range(1, screen_h):
myscreen.addstr(col, int(col2), "│")
myscreen.addstr(col, int(col3), "│")
# 事先打印IGT3205的各项值的名称
myscreen.addstr(1, int(col1), "Temp:", curses.color_pair(2))
myscreen.addstr(2, int(col1), "X :", curses.color_pair(2))
myscreen.addstr(3, int(col1), "Y :", curses.color_pair(2))
myscreen.addstr(4, int(col1), "z :", curses.color_pair(2))
# 事先打印ADXL345的各项值的名称
myscreen.addstr(1, int(col2) + 1, "X:", curses.color_pair(2))
myscreen.addstr(2, int(col2) + 1, "Y:", curses.color_pair(2))
myscreen.addstr(3, int(col2) + 1, "z:", curses.color_pair(2))
# 事先打印HMC5883L的各项值的名称
myscreen.addstr(1, int(col3) + 1, "Heading: ", curses.color_pair(2))
myscreen.addstr(2, int(col3) + 1, "Declination:", curses.color_pair(2))
myscreen.addstr(3, int(col3) + 1, "X: ", curses.color_pair(2))
myscreen.addstr(4, int(col3) + 1, "Y: ", curses.color_pair(2))
myscreen.addstr(5, int(col3) + 1, "z: ", curses.color_pair(2))
# センサーを初期化します
itg3205 = i2c_itg3205.i2c_itg3205(0)
adxl345 = i2c_adxl345.i2c_adxl345(0)
hmc5883l = i2c_hmc5883l.i2c_hmc5883l(0)
hmc5883l.setContinuousMode() #連続更新モードに設定します
hmc5883l.setDeclination(9,54) #真北磁偏角補正を設定します
while True:
#Read itg3205 data
(itgready, dataready) = itg3205.getInterruptStatus()
if dataready:
temp = itg3205.getD ieTemperature()
(x, y, z) = itg3205.getDegPerSecAxes()
displayITG3205(myscreen, 6, temp, x, y, z) #キャンバスを更新
#adxl345 データの読み取り
(x, y, z) = adxl345.getAxes()
displayADXL345(myscreen, int(col2) + 4, x, y, z) #キャンバスを更新
スルー ’ s ’ s ’ s ’ s ‐ ‐ ‐ ‐ to DeclinationString() #磁気偏角を取得補正情報
displayHMC5883L(myscreen, int(col3) + 13, 方位, 赤緯, x, y, z) #キャンバスを更新
myscreen.refresh() #アプリケーションキャンバス
sleep(0.1) #0.1 秒間一時停止
myscreen.getch()
curses.endwin()

Arraysinpython、特にvianumpy、arecrucialinscientificComputing fortheirefficienty andversitility.1)彼らは、fornumericaloperations、data analysis、andmachinelearning.2)numpy'simplementation incensuresfasteroperationsthanpasteroperations.3)arayableminablecickick

Pyenv、Venv、およびAnacondaを使用して、さまざまなPythonバージョンを管理できます。 1)Pyenvを使用して、複数のPythonバージョンを管理します。Pyenvをインストールし、グローバルバージョンとローカルバージョンを設定します。 2)VENVを使用して仮想環境を作成して、プロジェクトの依存関係を分離します。 3)Anacondaを使用して、データサイエンスプロジェクトでPythonバージョンを管理します。 4)システムレベルのタスク用にシステムPythonを保持します。これらのツールと戦略を通じて、Pythonのさまざまなバージョンを効果的に管理して、プロジェクトのスムーズな実行を確保できます。

numpyarrayshaveveraladvantages-averstandardpythonarrays:1)thealmuchfasterduetocベースのインプレンテーション、2)アレモレメモリ効率、特にlargedatasets、および3)それらは、拡散化された、構造化された形成術科療法、

パフォーマンスに対する配列の均一性の影響は二重です。1)均一性により、コンパイラはメモリアクセスを最適化し、パフォーマンスを改善できます。 2)しかし、タイプの多様性を制限し、それが非効率につながる可能性があります。要するに、適切なデータ構造を選択することが重要です。

craftexecutablepythonscripts、次のようになります

numpyarraysarasarebetterfornumeroperations andmulti-dimensionaldata、whilethearraymoduleissuitable forbasic、1)numpyexcelsinperformance and forlargedatasentassandcomplexoperations.2)thearraymuremememory-effictientivearientfa

NumPyArraySareBetterforHeavyNumericalComputing、whilethearrayarayismoreSuitableformemory-constrainedprojectswithsimpledatatypes.1)numpyarraysofferarays andatiledance andpeperancedatasandatassandcomplexoperations.2)thearraymoduleisuleiseightweightandmemememe-ef

ctypesallowsinging andmanipulatingc-stylearraysinpython.1)usectypestointerfacewithclibrariesforperformance.2)createc-stylearraysfornumericalcomputations.3)passarraystocfunctions foreffientientoperations.how、how、becuutiousmorymanagemation、performanceo


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

mPDF
mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

ホットトピック









