/* Pumkin Lighting aka Pumkin Guts
Sherman Stebbins 20210929 generic ATtiny13a with 1mhz
Data Type Length (bits/bytes) Valuesuint8_t 8 / 1 0 to 255int8_t 8 / 1 -128 to 127uint16_t 16 / 2 0 to 65535int16_t 16 / 2 -32768 to 32767uint32_t 32 / 4 0 to 4294967295int32_t 32 / 4 -2147483648 to 2147483647uint64_t 64 / 8 0 to 1.8*1019int64_t 64 / 8 -9.2*1018 to 9.2*1018 *///later stuff to add.//#include <avr/sleep.h> // Sleep Modes//#include <avr/power.h> // Power management//#include <avr/wdt.h> // Watchdog timer//#include <util/delay.h>//#include <avr/interrupt.h>
#define LedEye1 PB0 // the PWM pin the LED is attached tochar brightness = 0; // how bright the LED is //same as uint8_t
#define LedEye2 PB1 //PB4 // the PWM pin the LED is attached touint8_t brightness2 = 100; // how bright the LED is
//must be > 2char fadeAmount = 10; // how many points to fade the LED bychar fadeAmount2 = -10; // how many points to fade the LED by unsigned long previousMillis = 0;
#define LFSR_SEED (91)const long interval = 80; //no diff//#define interval 80
#define LedYellow PB4 //PB1 //yellow ledconst char ranVar[3]={1,4,5};//,5,90,4,70,50,5,300,5};char ranSelect=0;const uint8_t ranMax=10;int countYellow = 0;int ranNumYellow=3;
#define LedWhite PB3 //white ledint countWhite=0;int ranNumWhite=3;int ledStateWhite = LOW;
#define LedOrange PB2 //orange led//unsigned long countOrange=0;int countOrange=0;int ranNumOrange=3;int ledStateOrange = LOW;
int countSleep=0;int sleepAfter=5;
// the setup routine runs once when you press reset:void setup() { //DDRB = 0b00011111; // set LED pins as OUTPUT PB0-PB4 //PORTB = (1<<PB4)|(1<<PB1)|(1<<PB0); DDRB = (1<<DDB4)|(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);}
//ISR(WDT_vect) {//}
// the loop routine runs over and over again forever:void loop() {
unsigned long currentMillis = millis(); /////////////////////EYES////////////////////////////// if (currentMillis - previousMillis >= interval) { // save the last time you blinked the LED previousMillis = currentMillis;
// set the brightness of pin 9: analogWrite(LedEye1, brightness); analogWrite(LedEye2, brightness2);
// change the brightness for next time through the loop: brightness = brightness + fadeAmount; brightness2 = brightness2 + fadeAmount2; if(brightness < 20){ brightness-(fadeAmount/2); } if(brightness2 < 20){ brightness2-(fadeAmount2/2); }
// reverse the direction of the fading at the ends of the fade: if (brightness <= 0 || brightness >= 100) { fadeAmount = -1*fadeAmount; //change from positive to neg or vise versa } if (brightness2 <= 0 || brightness2 >= 120) { fadeAmount2 = -fadeAmount2; //change from positive to neg or vise versa } /*if(countSleep>sleepAfter){ countSleep=0; //goToSleep(9); //sleepNow(); sleep_mode(); // go to sleep and wait for interrupt... } countSleep++;*/ } // wait for 30 milliseconds to see the dimming effect
//yellow countYellow++; if(countYellow>=ranNumYellow){ PORTB ^= _BV(LedYellow); //Toggle LED countYellow=0; ranNumYellow=((prng_lfsr16()/15));//Random number }
//white countWhite++; if(countWhite>ranNumWhite){ //digitalWrite(LedWhite, ledStateWhite = ledStateWhite ? LOW : HIGH); PORTB ^= _BV(LedWhite); countWhite=0; //ranNumWhite= 750;//random(1000); ranNumWhite=(prng_lfsr16()/30);//random number //delay(100); }
//orange countOrange++; if(countOrange>ranNumOrange){ //analogWrite(LedOrange, ledStateOrange = ledStateOrange ? 0 : 255); //PORTB ^= _BV(LedOrange); PORTB ^= (1<<LedOrange); countOrange=0; //ranNumOrange=350;//random(1800); ranNumOrange=(prng_lfsr16()/50);//random number }}
static uint16_t prng_lfsr16(void){ static uint16_t cnt16 = LFSR_SEED; return (cnt16 = (cnt16 >> 1) ^ (-(cnt16 & 1) & 0xB400));}