So, I was looking for something to do at HackWimbledon today and as I'd just
So, I was looking for something to do at HackWimbledon today and as I'd just got my hands on the Hex Neopixel panels from M5Stack, I thought I'd see what I could get going. And down I fell into a hole which lead to playing with spreadsheets. Lets look at the device in question:
Pretty neat eh. The demo code was easy enough to get going and it slaps a rainbow over all the pixels. Super.
Then I decided I wanted to roll a pixel around the hex. Now, your Neopixels are chained so there's an effective strip of 0 to 36 pixels and... well how do you know which ones next to the other. Well, thats where the spreadsheet came in. Surely there was a simple and effective algorithm to work it out and after careful pondering I... well... I decided to just use the raw data in the spreadsheet.
I'd taken each hex and gone around clockwise to see what pixel was adjacent to that side and noted them all. I just took that data set and turned it into a C array of 8 bit ints...
Well let's look at the code...
It the array, where there's no pixel to go to, it's marked with -99. We start out pixel off at position 18, dead center. To move one pixel, we select a value 1 to 6 and look at the 18th entry in our array and that values entry in the array there we get what pixel we will be at if we went in that direction. (It's 1 to 6 because for simplicitly, the first element of the array is the start pixel number). Anyway, in a loop, we flicker through and repeat. Oh, and if there's no pixel to move to - the -99 - we just pick another direction. It all comes out as a nice wandering pixel with a steady pace as you can see here:
Now, the questions are
- Is there a better way to map the hex
- Can I make this work with an M5Stick
- Can I make it react to an accelerometer
- Can I chain lots of these together to make a huge hex
Hope you enjoy...