This is so simple yet soooo satisfying. Not mega coding, not even something that is that taxing to think of
I adapted the example https://github.com/lawsie/guizero/blob/ ... _waffle.py
to an 8x8 grid,
and added the sense_hat (or sense_emu, which makes it even more flexible for teaching)
then just get it to colour the grid when clicked
Code: Select all
from guizero import App, Waffle, PushButton from sense_hat import SenseHat sense=SenseHat() sense.clear(255,255,255) def change_pixel(x,y): if big_waffle.get_pixel(x,y) == "white": big_waffle.set_pixel(x, y, "red") sense.set_pixel( x,y, [255,0,0] ) else: big_waffle.set_pixel(x, y, "white") sense.set_pixel( x,y, [255,255,255] ) app = App("Waffle!", height=20*20, width=20*20) big_waffle = Waffle(app, height=8, width=8, dim=25, pad=2, dotty=True, command=change_pixel) enable_button = PushButton(app, big_waffle.enable, text="Enable") disable_button = PushButton(app, big_waffle.disable, text="Disable") app.display()
They both work well together.
GuiZero can control the display.
SenseHAT can give GuiZero it's sensor to create a display for.
Sense_emu can also be used, though does lack the bright light 'wow' factor
Extensions (off the top of my head)
-Add a clear(0,0,0) on windows close
-Change the colour for the click, e.g. RGB sliders
-Create an image in the waffle and see it on screen/hat, then figure out a way of exporting the colours (get_pixels?) in to a cut and paste list for use in SenseHat code.
-Sensor display, since sense-emu is built in to Raspberry Pi Desktop Raspbian/x86
-Text in a text box and display it on the SenseHat.
SenseHAT LED https://pythonhosted.org/sense-hat/api/#led-matrix
GuiZero Waffle https://lawsie.github.io/guizero/waffle/
Note to self/ check code as it's from memory so technically untested, mainly the waffle grid and size.
/Code checked and added the missed off set_pixel, oops