I am trying to write code to buzz randomly once every 30 minutes
I added a pushbutton on pin D2 in order to log my feedback on a file every time the buzzer vibrates (single click log “ok”, double click log “no”)
This is the circuitpython code I have written so far and I know there are gaps and mistakes and I am trying to solve them one by one.
Code: Select all
import datetime
from random import randint
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_debouncer import Button
# vibrating disc mini motor disc connected on D1
vibrating_disc = DigitalInOut(board.D1)
vibrating_disc.direction = Direction.OUTPUT
pulsante = DigitalInOut(board.D2)
pulsante.direction = Direction.INPUT
pulsante.pull = Pull.UP
switch = Button(pulsante)
on_time = 2 # Vibration motor run time, in seconds
now = datetime.now()
begin = datetime.datetime.strptime("07:00", "%H:%M")
end = datetime.datetime.strptime("23:00", "%H:%M")
delta = datetime.timedelta(minutes=30)
while begin <= end:
r = begin + datetime.timedelta(seconds=randint(0, 1800))
if now >= r and now <= (r + on_time):
vibrating_disc.value = True
elif now >= (r + on_time):
vibrating_disc.value = False
begin = begin + delta
When I load on the gemma I get the following message from MU REPL:
Traceback (most recent call last):
File "code.py", line 2, in <module>
ImportError: no module named 'datetime'
The led is going green-yellow-flashing blue.
One other thing I need to make sure of is the capability to append data to a file stored on the board and I have read this topic https://learn.adafruit.com/circuitpytho ... on-storage which is making me think that if I put the BOOT.PY file on the Gemma I will be no longer able to edit the code from my pc. Is this correct? What is going to happen?
Any help really precious!
Angelo