Over the past few years I've had a lot of fun working on Arduino projects with my kids. The idea has been to teach them a practical approach to coding as I see it practiced by efficient developers in the real world.
That typically means starting by finding some kind of sample code that is already out there on the internet, code that already kinda/sorta does what we want it to.
Then it's about cleaning in up – good use of white space, useful comments, better structure (things like moving variables up to the top).
It's been a lot of fun and very educational. This is the way I see coding done in the real world and believe it is a great programming foundation for them.
Be aware of a small encoding issue and the resulting "lt/gt was not declared in this scope" error when pasting into the excellent Arduino IDE for Mac.
The first part of this project (adding LED "eyes" to a skull, driven by an Arduino UNO) was about teaching code optimization, abstraction and commenting.
More variables and the addition of a "wink" effect to make the LED skull eyes seem more animated.
The next step involves adding a second "eye" (LED), independent of the first, to maintain the wink effect.
The next step in creating a spookier skull was to add an HC-SR04 ultrasonic module that would fire the LEDs based on proximity to a viewer.
A small change to another fire-breathing Arduino pumpkin replaces a proximity sensor with an small IR remote control.
This code was a great opportunity to introduce the idea of subroutines and returning values from subroutines (functions) with an Arduino Uno.