Repository navigation
Expand file tree
/
Copy pathradiationIN.py
More file actions
55 lines (46 loc) · 1.55 KB
/
Copy pathradiationIN.py
File metadata and controls
55 lines (46 loc) · 1.55 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
import machine
import utime
import _thread
import os
import random
import playRandom # Import the sound playback module
#60000 kHz seems to create the most voltage
# Create PWM on GPIO 41
pwm = machine.PWM(machine.Pin(41))
pwm.freq(60000) # Set PWM frequency to 100 kHz (5µs high, 5µs low)
pwm.duty_u16(32767) # 50% duty cycle (range 0-65535, so 32767 is 50%)
# Set up the LED on GPIO 2
led = machine.Pin(2, machine.Pin.OUT)
led.value(0)
# Set up the beeper on GPIO 6
beep = machine.Pin(6, machine.Pin.OUT)
beep.value(0)
# Set up GPIO 15 as input (default pulled up, LOW when triggered)
trigger = machine.Pin(15, machine.Pin.IN)
#flag for radiation detection
radiation_detected = False
# Interrupt handler function
def handle_radiation(pin):
global radiation_detected
radiation_detected = True #set flag on detection
# Attach interrupt to GPIO15 (triggers on FALLING EDGE)
trigger.irq(trigger=machine.Pin.IRQ_FALLING, handler=handle_radiation)
# Keep the script running
while True:
if radiation_detected:
for _ in range(1): # Blink LED 5 times
led.value(1)
beep.value(0)
utime.sleep(1)
led.value(0)
beep.value(0)
utime.sleep(1)
led.value(1)
utime.sleep(1)
led.value(0)
utime.sleep(1)
#playRandom.play_random_sound() # Call function to play a random sound
#playRandom.play_specific_sound()
#playRandom.list_sd_files()
radiation_detected = False
utime.sleep(1) # Keep the script alive