ajout quelques scripts de test + WIP morse

pour projet lumières dans la nuit, sense_morse.py
This commit is contained in:
Jérémie DUCASTEL
2020-05-24 00:31:51 +02:00
parent 8ceeeedad4
commit c02d69229f
4 changed files with 161 additions and 0 deletions

41
sense_stick.py Normal file
View File

@ -0,0 +1,41 @@
from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
from signal import pause
x = 3
y = 3
sense = SenseHat()
def clamp(value, min_value=0, max_value=7):
return min(max_value, max(min_value, value))
def pushed_up(event):
global y
if event.action != ACTION_RELEASED:
y = clamp(y - 1)
def pushed_down(event):
global y
if event.action != ACTION_RELEASED:
y = clamp(y + 1)
def pushed_left(event):
global x
if event.action != ACTION_RELEASED:
x = clamp(x - 1)
def pushed_right(event):
global x
if event.action != ACTION_RELEASED:
x = clamp(x + 1)
def refresh():
sense.clear()
sense.set_pixel(x, y, 255, 255, 255)
sense.stick.direction_up = pushed_up
sense.stick.direction_down = pushed_down
sense.stick.direction_left = pushed_left
sense.stick.direction_right = pushed_right
sense.stick.direction_any = refresh
refresh()
pause()