Thursday, July 20, 2023

Solar Super Capacitor Resin Creation with Attiny85

 


watch whole diy video on youtube:https://youtu.be/81VuIfaRIzI


Code below for this solar supercapacitor resin creation


#include <avr/sleep.h>

#include <avr/wdt.h> 


#ifndef cbi

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#endif

#ifndef sbi

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#endif 


volatile boolean f_wdt = 1; 

int pinLed0 = PB0;

int pinLed1 = PB1;

int pinLed2 = PB2;

int pinLDR = A2;



void setup() 

  {

    pinMode(pinLed0, OUTPUT);

    pinMode(pinLed1, OUTPUT);

    pinMode(pinLed2, OUTPUT);

    pinMode(pinLDR, INPUT_PULLUP);    setup_watchdog(7);// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms

                      // 6=1sec, 7=2 sec, 8=4 sec, 9= 8sec

  } 


void loop()

  {

    if (f_wdt == 1)

    {

      f_wdt = 0;

      if(digitalRead(pinLDR) == HIGH)

      {

    

          digitalWrite(pinLed0, HIGH);

        delay(100);

        digitalWrite(pinLed0, LOW);

        delay(100);

        digitalWrite(pinLed1, HIGH);

        delay(100);

        digitalWrite(pinLed1, LOW);

        delay(100);

         digitalWrite(pinLed2, HIGH);

        delay(100);

        digitalWrite(pinLed2, LOW);

         delay(10000);

      

        

        

        

        

         }



      

      system_sleep();

    }

  }



  void system_sleep()

  {

    cbi(ADCSRA, ADEN);

    set_sleep_mode(SLEEP_MODE_PWR_DOWN);

    sleep_enable();

    sleep_mode();

    sleep_disable();

    sbi(ADCSRA, ADEN);

  }



  void setup_watchdog(int ii)

  {

    byte bb;

    int ww;

    if (ii > 9 ) ii = 9;

    bb = ii & 7;

    if (ii > 7) bb |= (1 << 5);

    bb |= (1 << WDCE);

    ww = bb;

    MCUSR &= ~(1 << WDRF);

    WDTCR |= (1 << WDCE) | (1 << WDE);

    WDTCR = bb;

    WDTCR |= _BV(WDIE);

  }

  ISR(WDT_vect)

  {

    f_wdt = 1;

  }


end of code



No comments:

Post a Comment