So far the kids have wired up one LED, and modified a basic fade in/out program. The modifications included making the code more readable, adding some pauses and creating a wink effect. Also – moving all the pause and brightness values up into let statements at the top of the code to make fine-tuning them easier.
But, of course, a skull has two eyes, and we only had one LED. They had the option of taking the laze way out – we talked about putting a pirate-style patch over one eye. But they decided they wanted to see it through and add a second LED, and change the code so that only one of them "winked".
The added a second LED to pin 10, and altered the code accordingly – declaring the new pin at the outset, and setting the brightness of each led at each step along the way. Except of course during the wink effect, where only one led (the one winking) is turned down to zero for the wink interval.
After the changes and testing the revised code looked like this:
// BRIGHTNESS // minimum brightness level for the led int brightness_minimum = 1; // maximum brightness level for the led int brightness_maximum = 75; // PAUSES // pause between each increase in brightness int pause_between_increase = 12; // pause between each decrease in brightness int pause_between_decrease = 64; // pause at max brightness, before the wink effect int pause_at_max_before_wink = 2000; // pause for the wink effect int pause_for_wink = 100; // pause at max brightness, after the wink effect int pause_at_max_after_wink = 200; // the pause at min brightness int pause_at_min_brightness = 600; const int ledPin1 = 9; // the pin that the LED is attached to const int ledPin2 = 10; // the pin that the LED is attached to void setup () { pinMode(ledPin1, OUTPUT); // declare pin 9 to be an output: pinMode(ledPin2, OUTPUT); // declare pin 10 to be an output: } void loop() { // ramp up led brightness for (int brightness_current = brightness_minimum; brightness_current <= brightness_maximum; brightness_current++) //loop from brightness_minimum to brightness_maximum { analogWrite(ledPin1, brightness_current); // set the brightness of pin 9: analogWrite(ledPin2, brightness_current); // set the brightness of pin 10: delay(pause_between_increase); } // hold at max brightness before wink delay(pause_at_max_before_wink); // wink (optional) if (pause_for_wink > 0) { analogWrite(ledPin1, 0); // turn first led off, creating the wink effect: delay(pause_for_wink); analogWrite(ledPin1, brightness_maximum); // restore first led to max brightness, ending the wink effect: } // hold at max brightness after wink delay(pause_at_max_after_wink); // ramp down led brightness for (int brightness_current = brightness_maximum; brightness_current >= brightness_minimum; brightness_current--) //loop from brightness_maximum down to brightness_minimum { analogWrite(ledPin1, brightness_current); // set the brightness of pin 9: analogWrite(ledPin2, brightness_current); // set the brightness of pin 10: delay(pause_between_decrease); } // hold at minimum brightness delay(pause_at_min_brightness); }
It looks good. The next step will be moving the wiring off the breadboard and mounting it into the skull.