py port runs, not tested on HW yet, need linting

This commit is contained in:
Mikey Sklar 2018-07-26 17:26:25 -06:00
parent 8de47deb87
commit f11f366460
2 changed files with 13 additions and 34 deletions

View file

@ -1,4 +1,4 @@
# Mindfulness Bracelet sketch for Adafruit/Arduino Gemma. Briefly runs
# Mindfulness Bracelet sketch for Adafruit Gemma. Briefly runs
# vibrating motor (connected through transistor) at regular intervals.
import time
@ -6,43 +6,22 @@ import board
import pulseio
from digitalio import DigitalInOut, Direction
on_time = 2 #
interval = 60
# vibrating disc mini motor disc connected on D2
vibrating_disc = DigitalInOut(board.D2)
vibrating_disc.direction = Direction.OUTPUT
on_time = 2 # Vibration motor run time, in seconds
interval = 60 # Time between reminders, in seconds
# digital LEDs connected on D2
digital_leds = DigitalInOut(board.D2)
digital_leds.direction = Direction.OUTPUT
brightness = 0 # how bright the LED is
fade_amount = 1285 # 2% steping of 2^16
counter = 0 # counter to keep track of cycles
start_time = time.monotonic()
while True:
# And send to LED as PWM level
pwm.duty_cycle = brightness
timer = time.monotonic() - start_time
# change the brightness for next time through the loop:
brightness = brightness + fade_amount
if timer >= interval and timer <= (interval + on_time):
vibrating_disc.value = True
print(brightness)
# reverse the direction of the fading at the ends of the fade:
if brightness <= 0:
fade_amount = -fade_amount
counter += 1
elif brightness >= 65535:
fade_amount = -fade_amount
counter += 1
# wait for 15 ms to see the dimming effect
time.sleep(.015)
# turns on the other LEDs every four times through the fade by
# checking the modulo of the counter.
# the modulo function gives you the remainder of
# the division of two numbers:
if counter % 4 == 0:
digital_leds.value = True
else:
digital_leds.value = False
elif timer >= (interval + on_time):
vibrating_disc.value = False
start_time = time.monotonic()