Skip to content

Commit 3645b94

Browse files
authored
Add files via upload
1 parent 503285b commit 3645b94

File tree

1 file changed

+34
-0
lines changed
  • Gemma/GemmaM0_Vibration_Switch_Motion_Alarm

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# Motion Sensor Alarm
6+
# uses Gemma M0, vibration sensor on A0/GND, & piezo on D0/GND
7+
import time
8+
import pwmio
9+
from analogio import AnalogIn
10+
import board
11+
12+
piezo = pwmio.PWMOut(board.D0, duty_cycle=0, frequency=440,
13+
variable_frequency=True)
14+
15+
vibrationPin = AnalogIn(board.A0)
16+
17+
18+
def get_voltage(pin):
19+
return (pin.value * 3.3) / 65536
20+
21+
22+
while True:
23+
print((get_voltage(vibrationPin),))
24+
vibration = get_voltage(vibrationPin)
25+
26+
if vibration < 1: # the sensor has been tripped, you can adjust this value
27+
# for sensitivity
28+
for f in (2620, 4400, 2620, 4400, 2620, 4400, 2620, 4400):
29+
piezo.frequency = f
30+
piezo.duty_cycle = 65536 // 2 # on 50%
31+
time.sleep(0.2) # on 1/5 second
32+
piezo.duty_cycle = 0 # off
33+
time.sleep(0.02) # pause
34+
time.sleep(0.01) # debounce delay

0 commit comments

Comments
 (0)