Free Gift 2020
STL files at:
https://cults3d.com/en/3d-model/various/gift-for-free-2020-christmas-tree-village
/*ATtiny85
+-|_|-+ Ain0 (D 5) PB5 1| |8 Vcc Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 pin2 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 pin1 GND 4| |5 PB0 (D 0) pwm0 pin0 +-----+Free Gift for all 2020Christmas tree light up
Sherman Stebbins8/14/20
*/#include <avr/sleep.h> // Sleep Modes#include <avr/power.h> // Power management#include <avr/wdt.h> // Watchdog timer
int yellow_small=0;int green_small=1;int candles=2;int blue_small=3;int multi=4;int MaxFunc=7; //max display stylesint Rand=0;
// the setup function runs once when you press reset or power the boardvoid setup() { randomSeed(analogRead(2)); pinMode(yellow_small, OUTPUT); pinMode(green_small, OUTPUT); pinMode(candles, OUTPUT); pinMode(blue_small, OUTPUT); pinMode(multi, OUTPUT); //Rand=random(MaxFunc);}
// the loop function runs over and over again forevervoid loop() {
// select
AllOn(); delay(5000); AllOff(); //delay(3000); SelectMode(); delay(100); goToSleep (random(5,9)); //7=2 seconds }
void AllOn(){ digitalWrite(yellow_small, HIGH); digitalWrite(green_small, HIGH); digitalWrite(candles, HIGH); digitalWrite(blue_small, HIGH); digitalWrite(multi, HIGH); }void AllOff(){ digitalWrite(yellow_small, LOW); digitalWrite(green_small, LOW); digitalWrite(candles, LOW); digitalWrite(blue_small, LOW); digitalWrite(multi, LOW); delay(100); }
void SelectMode(){ switch(random(0,MaxFunc)){ case 0: for(int i=0;i<=random(5,20);i++){ AllOn(); delay(i*1000); AllOff(); //goToSleep(2000); } break; case 1: AllOn(); delay(10000); AllOff(); delay(100); break;
case 2: digitalWrite(candles, HIGH); delay(random(5,10)*1000); AllOff(); break; case 3: digitalWrite(yellow_small, HIGH); delay(random(5,10)*1000); AllOff(); break;
case 4: digitalWrite(green_small, HIGH); delay(random(5,10)*1000); AllOff(); break; case 5: digitalWrite(blue_small, HIGH); delay(random(5,10)*1000); AllOff(); break; case 6: digitalWrite(multi, HIGH); delay(random(5,10)*1000); AllOff(); break; default: AllOff(); break; } // goToSleep(random(2,6));}
void goToSleep (int dt){ set_sleep_mode (SLEEP_MODE_PWR_DOWN); ADCSRA = 0; // turn off ADC power_all_disable (); // power off ADC, Timer 0 and 1, serial interface noInterrupts (); // timed sequence coming up resetWatchdog (dt); // get watchdog ready sleep_enable (); // ready to sleep interrupts (); // interrupts are required now sleep_cpu (); // sleep sleep_disable (); // precaution //ADCSRA = 1; //hope it works -- no luck power_all_enable (); // power everything back on} // end of goToSleep
void resetWatchdog (int dt){ // clear various "reset" flags MCUSR = 0; // allow changes, disable reset, clear existing interrupt WDTCR = bit (WDCE) | bit (WDE) | bit (WDIF); // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
switch(dt){ case 1: WDTCR = bit (WDIE) | bit (WDP0); // 32 milli seconds break; case 2: WDTCR = bit (WDIE) | bit (WDP1); // 64 milli seconds break; case 3: WDTCR = bit (WDIE) | bit (WDP1) | bit (WDP0); // .125 second break; case 4: WDTCR = bit (WDIE) | bit (WDP2); //.25 seconds break; case 5: WDTCR = bit (WDIE) | bit (WDP2) | bit (WDP0); // .5 seconds break; case 6: WDTCR = bit (WDIE) | bit (WDP2) | bit (WDP1); // 1 second break; case 7: WDTCR = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0); // 2 seconds break; case 8: WDTCR = bit (WDIE) | bit (WDP3); // 4 seconds break; case 9: WDTCR = bit (WDIE) | bit (WDP3) | bit (WDP0); // set WDIE, and 8 seconds delay break; default: break; } // pat the dog wdt_reset(); } // end of resetWatchdog
ISR (PCINT0_vect) { // do something interesting here} // end of PCINT0_vect // watchdog interruptISR (WDT_vect) { wdt_disable(); // disable watchdog} // end of WDT_vect