griguoli
Posts: 1
Joined: Thu Aug 16, 2018 10:38 am

Interactive menu with the sense hat

Sat Aug 18, 2018 2:13 pm

Hi guys,
I'm doing an exciting project with the the sense hat, but i have some trouble doing this, because i'm not sure this can be possible :) , so I need your help.
The project consists of an interactive menu with sense hat using the joystick. Ok, for the joystick there isn't any problem, but I would create a virtual button on sense hat(button = one pixel), I tried to do it, but surely I got some mistakes:

Code: Select all

from sense_hat import SenseHat
import time

sense = SenseHat()
sense.clear()

temp = sense.get_temperature()
humidity = sense.get_humidity()
pressure = sense.get_pressure()
A = [0, 255, 0]
B = [0, 255, 255]
C = [255, 0, 0]
O = [255, 255, 255]

menu = [
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, A, O, B, O, C, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O,
O, O, O, O, O, O, O, O
]

sense.set_pixels(menu)

button_t = sense.get_pixel(2, 4) #temperature button
button_h = sense.get_pixel(4, 4) #humidity button
button_p = sense.get_pixel(2, 2) #pressure button

x = 0
y = 0

while True:
    for event in sense.stick.get_events():
        sense.set_pixel(x, y, 0, 0, 0)
        if event.action == 'pressed' and event.direction == 'up':
            if y > 0:
                y -= 1
        if event.action == 'pressed' and event.direction == 'down':
            if y < 7:
                y += 1
        if event.action == 'pressed' and event.direction == 'right':
            if x < 7:
                x += 1
        if event.action == 'pressed' and event.direction == 'left':
            if x > 0:
                x -= 1
        if event.action == 'pressed' and event.direction == 'middle':
            

Obviously the project it's unfinished, just because I didn't find a way to say that if i push the button only on the colored pixel the sense hat have to show me temperature or pressure or humidity.
Can be this possible?...I HOPEEE

P.S I'm not sure with the command:

Code: Select all

sense.get_pixel()
my intent was of name each pixel with this command, but i'm very unsure.

Return to “Advanced users”