diff --git a/08-74HC595-Snake/08-74HC595-Snake.ino b/08-74HC595-Snake/08-74HC595-Snake.ino index 405b9e9..7d4e93e 100644 --- a/08-74HC595-Snake/08-74HC595-Snake.ino +++ b/08-74HC595-Snake/08-74HC595-Snake.ino @@ -93,6 +93,7 @@ void collide_player() } else if ( (entity & ENTITY_FOOD) == ENTITY_FOOD ) { Serial.printf("Found food!\n"); found_food = 1; + score += 1; } } } diff --git a/08-74HC595-Snake/README.md b/08-74HC595-Snake/README.md index ec57442..048a8e9 100644 --- a/08-74HC595-Snake/README.md +++ b/08-74HC595-Snake/README.md @@ -1,14 +1,17 @@ # Breadboard -This project uses 3 74HC595 serial to parallel shift registers, a 7-segment display multi unit, an 8x8 LED matrix, an active buzzer, an NPN transistor, a joystick, a handful of resistors and a potentiometer to make a playable Snake game. +This project uses 3 74HC595 serial to parallel shift registers, a 7-segment display multi unit, an 8x8 LED matrix, an active buzzer, an NPN transistor, a joystick (later replaced with 4 buttons), a handful of resistors and a potentiometer to make a playable Snake game. + +This was easily the most challenging project so far, taking me well over a week to get it working right. # Lessons Learned +* The Arduino IDE debugger really sucks * Compiling, uploading, and debugging Arduino code from the CLI * Breadboards probably introduce just as many bugs as I do -* How to write data to a 74HC595 shift register without using the Arduino HAL * How to drive a 7-segment display * How to drive an 8x8 LED matrix +* Embedded platforms have undocumented limits that may surprise you * You don't need lots of pixels, or even colors, to make it fun ## Compiling, uploading, and debugging from the CLI @@ -147,9 +150,13 @@ I didn't actually wind up figuring this out. I wrestled with it for a bit, check ... Once I got all that working, I discovered that the wire between the potentiometer and pin 10 was bad. No continuity through the wire. Had it been that way all along? I don't think so. But sure as shit it's dead now. Replaced that and the wierd analog readings on the potentiometer went away. I had already ripped out the joystick handling code, so I didn't try putting it back in. There's no turning back now. -## Custom 74HC595 driver code +## Arduino IDE debugger woes and ESP32 limits -* Managing the clock signal +I spent about an hour struggling with a `Stack smashing protection` fault. Try as I might, I couldn't get the Arduino IDE debugger to show me where the actual crash was in my code. All I was getting was a fault with some addresses in memory for a backtrace. Sure, I could objdump the binary, figure out the addresses, and figure it out that way. But if I'm gonna do that, WTF is the point of having a GUI debugger? There are some GUI tools for decoding ESP32 stacktraces, but the Arduino IDE integration for them hasn't worked in at least one whole major version, and the newer versions want to run in some IDE I don't want to use. + +I wound up figuring it out essentially through trial and error. The `place_random_entity()` function uses an array of 64 bytes to store references to entries on the LED matrix where there are currently no actors. I had originally allocated that inside of the function itself - on the stack. Apparently this was the *wrong* place to put it. Moving this to a global variable resolved my problem. I have to assume that the default stack size was something ridiculously small, even though the scant documentation I could find said it would be something like 8Kb. + +I'm sure there was a more elegant solution than just moving it in to a global variable. But at this point, 9 days in to the project, lol bitch please, you're getting a global variable and we're making this damn thing run. ## Driving 7-segment displays