-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequence.py
67 lines (52 loc) · 1.75 KB
/
sequence.py
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
from machine import Pin, PWM, Timer, I2C
import utime
import machine
inled = Pin("LED", Pin.OUT)
# PIR (Motion) Sensor
PIR = Pin(0, Pin.IN, Pin.PULL_DOWN)
# RGB LED
Led_R = PWM(Pin(4))
Led_G = PWM(Pin(3))
Led_B = PWM(Pin(2))
# Set the frequency to 2KHz
Led_R.freq(2000)
Led_G.freq(2000)
Led_B.freq(2000)
# Buzzer
buzzer = PWM(Pin(15, Pin.IN)) #Sound
def LEDon(): # Onboard LED - Flash setting
utime.sleep_ms(100)
inled.value(1)
utime.sleep_ms(100)
inled.value(0)
def Active(): # Activating the alarm system
if PIR.value() == 1:
buzzer.freq(500)
buzzer.duty_u16(1000)
Led_R.duty_u16(65535)
Led_G.duty_u16(0)
Led_B.duty_u16(0)
# Time Delay for 3 seconds
utime.sleep(3)
buzzer.duty_u16(0) # loudness set to 0 = sound off
# Onboard Tempreture Sensor
sensor_temp = machine.ADC(machine.ADC.CORE_TEMP)
conversion_factor = 3.3 / (65535)
rtc=machine.RTC()
# Appending data log file with each new dection
file = open("datalog.txt", "a")
reading = sensor_temp.read_u16() * conversion_factor
# Timestamp
timestamp=rtc.datetime()
temperature = 27 - (reading - 0.706)/0.001721
timestring="Date: %04d-%02d-%02d | Time: %02d:%02d:%02d | "%(timestamp[0:3] + timestamp[4:7])
file.write(timestring + "State: Motion Detected! | Temp: " + str(temperature) + "\n")
file.flush()
else:
Led_R.duty_u16(0)
Led_G.duty_u16(65535)
Led_B.duty_u16(0)
def InActive():
Led_R.duty_u16(0)
Led_G.duty_u16(0)
Led_B.duty_u16(65535)