Once upon a time there was a girl who wanted a Christmas Tree for her doll house. So she asked her grandfather if he would help. They found stickers to use for decorations and tiny fairy lights to make it glow.
And the grandfather designed a Christmas tree in Fusion 360 and printed it in red and green PLA on his Anycubic I3 Mega 3D printer.
The girl slotted the tree together and stuck it into the base. And then she decorated it with stickers and wrapped the lights around the tree.
But the girl had brothers and a sister and there was only one tree. So the next week they built more, one for each sibling. But the lights didn't blink. So the grandfather who liked to tinker with electronics measured the current necessary to light a string of fairy lights and found it to be about 6 mA with Vf approximately 2.6V. And they needed a microcontroller so the grandfather rummaged through his stuff and found a ESP8266 that would do the trick. Then he soldered a current limiting 150 ohm resistor between each string of lights and four pins on the microcontroller.
And he made a box with the 3D printer to hold the microcontroller.
And he wrote some code using the Arduino IDE.
/* Control of miniature Christmas trees * Written and tested on NodeMCU Amica ESP8266 (ESP12-E Module) * F Milburn, December 3, 2020 Rev1 */ void displayOff(){ digitalWrite(D5, LOW); digitalWrite(D6, LOW); digitalWrite(D7, LOW); digitalWrite(D8, LOW); } // numBlinks is number of times to blink LEDs void blinkDisplay(int numBlinks){ int i; for(i=0; i<numBlinks; i++){ digitalWrite(D5, HIGH); digitalWrite(D6, HIGH); digitalWrite(D7, HIGH); digitalWrite(D8, HIGH); delay(500); digitalWrite(D5, LOW); digitalWrite(D6, LOW); digitalWrite(D7, LOW); digitalWrite(D8, LOW); delay(500); } } // numFades is number of times to fade the LEDs void fadeUpfadeDownDisplay(int numFades){ int i; int j; for(i=0; i<numFades; i++){ for(j=0; j<1024; j++){ analogWrite(D5, j); analogWrite(D6, j); analogWrite(D7, j); analogWrite(D8, j); delay(5); } delay(100); for(j=1023; j>=0; j--){ analogWrite(D5, j); analogWrite(D6, j); analogWrite(D7, j); analogWrite(D8, j); delay(5); } delay(100); } } // numWaves is number of times to wave the LEDs void waveDisplay(int numFades){ int i; int j; for(i=0; i<numFades; i++){ for(j=0; j<1024; j++){ analogWrite(D5, j); delay(2); } delay(100); digitalWrite(D5, LOW); for(j=0; j<1024; j++){ analogWrite(D6, j); delay(2); } delay(100); digitalWrite(D6, LOW); for(j=0; j<1024; j++){ analogWrite(D7, j); delay(2); } delay(100); digitalWrite(D7, LOW); for(j=0; j<1024; j++){ analogWrite(D8, j); delay(2); } delay(100); digitalWrite(D8, LOW); } } // numSweeps is number of times to scan the Larson scanner void larsonDisplay(int numScans){ #define LEDS 4 #define FRAMES 14 bool larson[FRAMES][LEDS]={ {HIGH, LOW, LOW, LOW}, {HIGH, LOW, LOW, LOW}, {HIGH, HIGH, LOW, LOW}, {HIGH, HIGH, HIGH, LOW}, {LOW, HIGH, HIGH, HIGH}, {LOW, LOW, HIGH, HIGH}, {LOW, LOW, LOW, HIGH}, {LOW, LOW, LOW, HIGH}, {LOW, LOW, LOW, HIGH}, {LOW, LOW, HIGH, HIGH}, {LOW, HIGH, HIGH, HIGH}, {HIGH, HIGH, HIGH, LOW}, {HIGH, HIGH, LOW, LOW}, {HIGH, LOW, LOW, LOW}, }; int i; int j; for (i=0; i<numScans; i++){ for (j=0; j<FRAMES; j++) { digitalWrite(D5, larson[j][0]); delay(50); digitalWrite(D6, larson[j][1]); delay(50); digitalWrite(D7, larson[j][2]); delay(50); digitalWrite(D8, larson[j][3]); delay(50); } } } // numTimes is number of times to display void everyOtherDisplay(int numTimes){ int i; for (i=0; i<numTimes; i++){ digitalWrite(D5, HIGH); digitalWrite(D6, LOW); digitalWrite(D7, HIGH); digitalWrite(D8, LOW); delay(500); digitalWrite(D5, LOW); digitalWrite(D6, HIGH); digitalWrite(D7, LOW); digitalWrite(D8, HIGH); delay(500); } } // numTimes is number of times to display void innerOuterDisplay(int numTimes){ int i; for (i=0; i<numTimes; i++){ digitalWrite(D5, HIGH); digitalWrite(D6, LOW); digitalWrite(D7, LOW); digitalWrite(D8, HIGH); delay(500); digitalWrite(D5, LOW); digitalWrite(D6, HIGH); digitalWrite(D7, HIGH); digitalWrite(D8, LOW); delay(500); } } void setup() { // Initialize the output variables as outputs pinMode(D5, OUTPUT); pinMode(D6, OUTPUT); pinMode(D7, OUTPUT); pinMode(D8, OUTPUT); } void loop(){ blinkDisplay(5); delay(2000); fadeUpfadeDownDisplay(1); delay(2000); waveDisplay(1); delay(2000); larsonDisplay(2); displayOff(); delay(2000); everyOtherDisplay(5); displayOff(); delay(2000); innerOuterDisplay(5); displayOff(); delay(2000); }
The trees in the forest began to blink, and fade, and flash with different patterns.
And there was a Christmas Forest.
Additional notes on construction: The fairy lights came in a box of 10 with 2032 coin cell holders for $11 on Amazon. The "3D" stickers can be bought off Amazon or found in Dollar stores and other purveyors of inexpensive children's toys. Any Arduino or Arduino clone should work but be careful not to overload the pins and LEDs by keeping the current under 10 mA per string.
Wishing you and yours the best this Holiday Season.
Top Comments