-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaveshare_version.py
More file actions
98 lines (69 loc) · 1.95 KB
/
waveshare_version.py
File metadata and controls
98 lines (69 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from machine import Pin, I2C, ADC, Timer
from ir_rx.nec import NEC_16
from neopixel import NeoPixel
from time import sleep
import random
ldr = ADC(Pin(26))
rgb_led_num = 22
rgb_led_pin = Pin(rgb_led_num, Pin.OUT)
rgb_led = NeoPixel(rgb_led_pin, 1)
led = Pin(25,Pin.OUT)
isLDRActive = False
ldr_timer = Timer()
def remoteSwitch(data, addr, ctrl):
global readCount, isLDRActive
if data > 0:
if data == 0x09:
if rgb_led[0]==(0,0,0):
LightSwitchOn()
else:
LightSwitchOff()
if data == 0x15:
if led.value() == 1:
led.value(0)
print("LDR OFF")
isLDRActive = False
else:
led.value(1)
print("LDR ON")
isLDRActive = True
# Start the timer to periodically check LDR conditions
ldr_timer.init(period=2000, mode=Timer.PERIODIC, callback=readLDR)
print('data {:02x}'.format(data))
ir = NEC_16(Pin(15,Pin.IN),remoteSwitch)
def LightSwitchOff():
rgb_led[0]=(0,0,0)
rgb_led.write()
def LightSwitchOn():
r= random.randint(0, 255)
g = random.randint(0, 255)
b =random.randint(0, 255)
print("r", r)
print("g", g)
print("b", b)
rgb_led[0]=(r,g,b)
rgb_led.write()
r=0
g=0
b=0
def getLedValue():
return led.value()
voltage = ldr.read_u16()*3.3/65535
#resistance = ((10*3.3)/voltage)-10
print(voltage)
def readLDR(timer):
global isLDRActive
if isLDRActive:
voltage = ldr.read_u16() * 3.3 / 65535
x = int(voltage)
if x > 0:
LightSwitchOn()
print("reading ", ":", "night")
else:
LightSwitchOff()
print("reading ", ":", "Day")
else:
# Turn off LDR and stop the timer after exiting the loop
led.value(0)
ldr_timer.deinit()
print("LDR Switch OFF")