注釈
こんにちは、SunFounderのRaspberry Pi & Arduino & ESP32愛好家コミュニティへようこそ!Facebook上でRaspberry Pi、Arduino、ESP32についてもっと深く掘り下げ、他の愛好家と交流しましょう。
Why Join?
エキスパートサポート:コミュニティやチームの助けを借りて、販売後の問題や技術的な課題を解決します。
学び&共有:ヒントやチュートリアルを交換してスキルを向上させましょう。
独占的なプレビュー:新製品の発表や先行プレビューに早期アクセスしましょう。
特別割引:最新製品の独占割引をお楽しみください。
祭りのプロモーションとギフト:ギフトや祝日のプロモーションに参加しましょう。
👉 私たちと一緒に探索し、創造する準備はできていますか?[here]をクリックして今すぐ参加しましょう!
フォトレジスタモジュールから読み取る
このプロジェクトでは、光の強度を検出し、I2C LCD1602に表示します。

手順
このプロジェクトではI2C LCD1602を使用しているため、関連するライブラリをダウンロードして機能させる必要があります。
cd ~/ wget https://github.com/sunfounder/raphael-kit/blob/master/python/LCD1602.py
I2C用に
smbus2
をインストールします。sudo pip3 install smbus2
以下のコードをRaspberry Piに保存し、例えば
photoresistor.ty
のような名前を付けます。from robot_hat import ADC import LCD1602 import time # Create an ADC object to read the value from the photoresistor a0 = ADC(0) def setup(): # Initialize the LCD1602 LCD1602.init(0x27, 1) time.sleep(2) def destroy(): # Clear the LCD display LCD1602.clear() def loop(): while True: # Read the value from the photoresistor value0 = a0.read() # Display the read value on the LCD LCD1602.write(0, 0, 'Value: %d ' % value0) # Reduce the refresh rate to update once per second time.sleep(0.2) if __name__ == '__main__': setup() try: loop() except KeyboardInterrupt: destroy() except Exception as e: # Clear the LCD and print error message in case of an exception destroy() print("Error:", e)
このコードを実行するには、コマンド
sudo python3 photoresistor.ty
を使用します。