Compare commits
2 Commits
b656f348f8
...
20dcf41bf4
| Author | SHA1 | Date | |
|---|---|---|---|
| 20dcf41bf4 | |||
| 3919b9a91a |
@ -5,7 +5,7 @@ import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
class LED(object):
|
||||
"""class for SSD1306 128*64 0.96inch OLED displays."""
|
||||
"""class for LED."""
|
||||
|
||||
def __init__(self, led):
|
||||
LED = led
|
||||
@ -13,15 +13,3 @@ class LED(object):
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
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()
|
||||
|
||||
|
||||
@ -166,7 +166,3 @@ class SSD1306(object):
|
||||
contrast = 0x9F
|
||||
else:
|
||||
contrast = 0xCF
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,14 +1,22 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import spidev as SPI
|
||||
import SSD1306
|
||||
import time
|
||||
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
|
||||
# Raspberry Pi pin configuration:
|
||||
OLED_GPIO_RST = 19
|
||||
OLED_GPIO_DC = 16
|
||||
OLED_SPI_BUS = 0
|
||||
OLED_SPI_CS = 0
|
||||
|
||||
# Raspberry Pi pin configuration:
|
||||
GPIO_RST = 19
|
||||
GPIO_DC = 16
|
||||
SPI_BUS = 0
|
||||
SPI_CS = 0
|
||||
SPI_BUS = 0
|
||||
SPI_CS = 0
|
||||
|
||||
# 128x64 display with hardware SPI:
|
||||
disp = SSD1306.SSD1306(GPIO_RST, GPIO_DC, SPI.SpiDev(SPI_BUS, SPI_CS))
|
||||
|
||||
43
main.py
43
main.py
@ -1,38 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import RPi.GPIO as GPIO
|
||||
import spidev as SPI
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'Led'))
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__),'Oled'))
|
||||
import Pioneer600.Led.LED as LED
|
||||
import Pioneer600.Oled.SSD1306 as SSD1306
|
||||
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
import threading
|
||||
|
||||
# Raspberry Pi pin configuration:
|
||||
LED_GPIO_RED = 26
|
||||
|
||||
OLED_GPIO_RST = 19
|
||||
OLED_GPIO_DC = 16
|
||||
OLED_SPI_BUS = 0
|
||||
OLED_SPI_CS = 0
|
||||
|
||||
LED_GPIO_RED = 26
|
||||
|
||||
# 128x64 display with hardware SPI:
|
||||
disp = SSD1306.SSD1306(OLED_GPIO_RST, OLED_GPIO_DC, SPI.SpiDev(OLED_SPI_BUS, OLED_SPI_CS))
|
||||
|
||||
# 128x64 display with hardware SPI:
|
||||
led = LED.LED(LED_GPIO_RED)
|
||||
|
||||
def main():
|
||||
|
||||
# 新线程执行的代码:
|
||||
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():
|
||||
|
||||
# 128x64 display with hardware SPI:
|
||||
led = LED.LED(LED_GPIO_RED)
|
||||
|
||||
try:
|
||||
led_blink = threading.Thread(target=blink_loop, name='led_blink', args=(LED_GPIO_RED,))
|
||||
led_blink.start()
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except:
|
||||
print("Except")
|
||||
led_blink.join()
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user