[修改] 增加LEd线程
This commit is contained in:
@ -13,23 +13,3 @@ class LED(object):
|
|||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setup(LED,GPIO.OUT)
|
GPIO.setup(LED,GPIO.OUT)
|
||||||
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
GPIO.output(LED,GPIO.HIGH)
|
|
||||||
time.sleep(1)
|
|
||||||
GPIO.output(LED,GPIO.LOW)
|
|
||||||
time.sleep(1)
|
|
||||||
except:
|
|
||||||
print("except")
|
|
||||||
GPIO.output(LED,GPIO.HIGH)
|
|
||||||
GPIO.cleanup()
|
|
||||||
|
|
||||||
LED_GPIO_RED = 26
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# 128x64 display with hardware SPI:
|
|
||||||
led = LED.LED(LED_GPIO_RED)
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
|
||||||
main()
|
|
||||||
|
|||||||
@ -166,7 +166,3 @@ class SSD1306(object):
|
|||||||
contrast = 0x9F
|
contrast = 0x9F
|
||||||
else:
|
else:
|
||||||
contrast = 0xCF
|
contrast = 0xCF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
20
main.py
20
main.py
@ -9,6 +9,7 @@ import spidev as SPI
|
|||||||
import Pioneer600.Led.LED as LED
|
import Pioneer600.Led.LED as LED
|
||||||
import Pioneer600.Oled.SSD1306 as SSD1306
|
import Pioneer600.Oled.SSD1306 as SSD1306
|
||||||
from PIL import Image,ImageDraw,ImageFont
|
from PIL import Image,ImageDraw,ImageFont
|
||||||
|
import threading
|
||||||
|
|
||||||
# Raspberry Pi pin configuration:
|
# Raspberry Pi pin configuration:
|
||||||
LED_GPIO_RED = 26
|
LED_GPIO_RED = 26
|
||||||
@ -18,16 +19,33 @@ OLED_GPIO_DC = 16
|
|||||||
OLED_SPI_BUS = 0
|
OLED_SPI_BUS = 0
|
||||||
OLED_SPI_CS = 0
|
OLED_SPI_CS = 0
|
||||||
|
|
||||||
|
# 新线程执行的代码:
|
||||||
|
def blink_loop(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
GPIO.output(args, GPIO.HIGH)
|
||||||
|
time.sleep(1)
|
||||||
|
GPIO.output(args, GPIO.LOW)
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
print("except")
|
||||||
|
GPIO.output(args, GPIO.HIGH)
|
||||||
|
GPIO.cleanup()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
# 128x64 display with hardware SPI:
|
# 128x64 display with hardware SPI:
|
||||||
led = LED.LED(LED_GPIO_RED)
|
led = LED.LED(LED_GPIO_RED)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
led_blink = threading.Thread(target=blink_loop, name='led_blink', args=(LED_GPIO_RED,))
|
||||||
|
led_blink.start()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except:
|
except:
|
||||||
print("except")
|
print("Except")
|
||||||
|
led_blink.join()
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user