Raspberry Pi (8) Nokia 5110 LCD 2nd
|ä¸å¹´åã«Nokia 5110 LCDã®è¡¨ç¤ºãåºæ¥ãããä»åã¯ãããRaspberry Pi ã«çµã¿è¾¼ã¿ãããã«ãã¿ã³ã追å ããã
ãã¿ã³ã¯çæ¼ãæ¤ç¥ããã¨ãLCDã®ããã¯ã©ã¤ãã®on/offã§ãããã«é·æ¼ãããã¨ãRaspberry Piã·ã£ãããã¦ã³æ©è½ãæãããã
GPIOã¸ã®ã¹ã¤ãããªã³ã»ãªãæ¤ç¥åè·¯ã
Pythonããã°ã©ã
#!/usr/local/bin/python # -*- coding: utf-8 -*- import time import RPi.GPIO as GPIO import os # LEDã®GPIOãã³ã®çªå·ãã»ã³ãµã¼ã®GPIOãã³ã®çªå· let_pin = 18 sw1_pin = 16 sleeptime = 1 led_01 = 0 GPIO.setmode(GPIO.BCM) GPIO.setup(sw1_pin, GPIO.IN) GPIO.setup(let_pin, GPIO.OUT) GPIO.output(let_pin, GPIO.LOW) def switch_detected(sw1_pin): global led_01 led_01 = 1 - led_01 if led_01 == 1: # ç¹ç¯ GPIO.output(let_pin, GPIO.HIGH) else: # æ¶ç¯ GPIO.output(let_pin, GPIO.LOW) sw_counter = 0 while True: sw_status = GPIO.input(sw1_pin) if sw_status == 0: sw_counter = sw_counter + 1 if sw_counter >= 50: print("é·æ¼ãæ¤ç¥ï¼") os.system("sudo shutdown -h now") break else: print("çæ¼ãæ¤ç¥") break time.sleep(0.01) time.sleep(sleeptime) # ã³ã¼ã«ããã¯ç»é² GPIO.add_event_detect(sw1_pin, GPIO.FALLING, callback=switch_detected) try: print "ctrl+c : if you want to stop app" print "App Start" while True: time.sleep(sleeptime) except KeyboardInterrupt: print "Quit" finally: print "clean up" GPIO.cleanup()
ãããèµ·åæèªåçã«ä½åããå¿ è¦ãããã
åèï¼
- https://qiita.com/clses/items/e701c1cb6490751a6040 – ã©ãºãã¤ã§ã·ã£ãããã¦ã³ãã¿ã³ãä»ãã(ã¤ãã§ã«èµ·åãã¿ã³)