Sounds the piezo alarm when the vibration switch is disturbed
initial commit
This commit is contained in:
parent
bdf115c127
commit
561730f137
1 changed files with 29 additions and 0 deletions
29
GemmaM0_Vibration_Switch_Motion_Alarm/main.py
Normal file
29
GemmaM0_Vibration_Switch_Motion_Alarm/main.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# Motion Sensor Alarm
|
||||
# uses Gemma M0, vibration sensor on A0/GND, & piezo on D0/GND
|
||||
import pulseio
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
from analogio import AnalogIn
|
||||
import board
|
||||
import time
|
||||
|
||||
piezo = pulseio.PWMOut(board.D0, duty_cycle=0, frequency=440,
|
||||
variable_frequency=True)
|
||||
|
||||
vibrationPin = AnalogIn(board.A0)
|
||||
|
||||
def get_voltage(pin):
|
||||
return (pin.value * 3.3) / 65536
|
||||
|
||||
while True:
|
||||
print((get_voltage(vibrationPin),))
|
||||
vibration = get_voltage(vibrationPin)
|
||||
|
||||
if vibration < 1: # the sensor has been tripped, you can adjust this value
|
||||
# for sensitivity
|
||||
for f in (2620, 4400, 2620, 4400, 2620, 4400, 2620, 4400):
|
||||
piezo.frequency = f
|
||||
piezo.duty_cycle = 65536//2 # on 50%
|
||||
time.sleep(0.2) # on 1/5 second
|
||||
piezo.duty_cycle = 0 # off
|
||||
time.sleep(0.02) # pause
|
||||
time.sleep(0.01) # debounce delay
|
||||
Loading…
Reference in a new issue