Project showcase
Flashlight Controller

Flashlight Controller © LGPL

Flashlight controller, 3 LED (White, Red, Green), 6 modes + and charging with solar panel. Consummation Power Off is < 1mAmp.

  • 748 views
  • 5 comments
  • 3 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Flash Light Controller, White LED, and navigation (red, green) and charging with Solar Panel.

6 modes, (work in progress)

  • Mcu atmega328P 3.3v
  • LiPo battery
  • 2n7000
  • Red LED 80ma
  • Green LED 80ma
  • White LED 100ma
  • pb switch
  • Shockley diode
  • few resistor
  • solar cell 5 volts 120 mamps

You will need to remove the Arduino power LED and the voltage regulator in order to minimize the power consumption. Mode: press and hold, wait for the green led flash the appropriate number and release.

  • Flash and release: Green/Red LED flashing every 1 sec (small boat navigation)
  • Flash and release: White LED 10%
  • Press and hold: set Level 10-100%. Off in 60 min
  • Press and release: Auto Off, slowly dimming down Off in 60 min, nightlights mode
  • Flash and release:release SOS
  • Flash release: RED 20% - Auto Off with Sun. Release

Press and release 100%. Off in 60 min

  • Flash and release: White Strobe 100%, every 2 sec, off with sun, on with the night release
  • Flash and release: Battery Level 1 to 10 flash (10-100%) release, auto off

And more... (any idea is welcome). Any time you can push the switch for turn off the (sleep mode).

Code

Norsak_11Arduino
// By Christian Roy
// Norsak LED controler
// rev_09
//#include <avr/sleep.h>

#include <avr/power.h>
#include <avr/sleep.h>
#include <Vcc.h>
#include <avr/wdt.h>

byte sw1 = 2 ;//pin
byte LED_White = 11;//pin
byte LED_Red1 = 6;//pin
byte LED_Red2 = 7;//pin
byte LED_Green1 = 5;//pin
byte LED_Green2 = 4;//pin
byte Read_Batt = 3;//pin
float LED_W_Max;
const float VccMin   = 2.7;           // Minimum expected Vcc level, in Volts.
const float VccMax   = 4.2;           // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0 / 1.0; // Measured Vcc by multimeter divided by reported Vcc
Vcc vcc(VccCorrection);
byte LED_W_pwr;
boolean dimmer = false ;
int timer;
int Tsel;
byte select;
int batt = 0 ;   //pin
int SolPanel = 1; //pin
float vSol;  // voltage at the solar panel
float V10;
boolean RedGreen = false;

///////////////////////////////////////////////////////////////
void setup()
///////////////////////////////////////////////////////////////
{
  analogReference(INTERNAL);//equal to 1.1 volts on ATmega328P
  //pinMode(LED_BUILTIN, OUTPUT);   digitalWrite (LED_Red1,LOW); // LED On
  pinMode(sw1, INPUT_PULLUP);
  pinMode(LED_White, OUTPUT);   digitalWrite (LED_Red1, LOW); // LED On
  analogWrite(LED_White, 0);  //0 = OFF & 255 ON
  pinMode (LED_Red1, INPUT); // High Impedence LED Off
  pinMode (LED_Red2, INPUT); // High Impedence LED Off
  pinMode (LED_Green1, INPUT); // High Impedence LED Off
  pinMode (LED_Green2, INPUT); // High Impedence LED Off
  //digitalWrite(LED_BUILTIN, LOW);


  Serial.begin(9600);
  attachInterrupt(0, SW_ISR, CHANGE);
  /*
    The 5 different modes are:
           SLEEP_MODE_IDLE         -the least power savings
           SLEEP_MODE_ADC
           SLEEP_MODE_PWR_SAVE
           SLEEP_MODE_STANDBY
           SLEEP_MODE_PWR_DOWN     -the most power savings
  */
}

void loop() {
  /*
    pinMode(LED_Red1, INPUT_PULLUP);
    pinMode(LED_Red2, INPUT); // High Impedence LED Off
    pinMode (LED_Red1,OUTPUT); // LED On
    delay (5000);
    pinMode(LED_Red1, OUTPUT);   digitalWrite (LED_Red1,LOW); // LED On
    delay (5000);
  */

  ///////////////////////////////////////////////////////////////
  sleepNow();
  ///////////////////////////////////////////////////////////////

  Tsel = 0;
  select = 0;//                 SELECT

  while (digitalRead(sw1) == LOW)
  {
    select ++;
    pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On LED On
    delay (12);
    pinMode (LED_Green1, INPUT); // High Impedence LED Off
    delay (600);
  }

  delay (750);
  switch (select)
  {
    ////////////////////////////////////////////
    ///           Green RED                  ///
    ////////////////////////////////////////////
    case 1:
      attachInterrupt(0, SW_ISR, CHANGE);
      while (1)
      {
        pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On
        pinMode (LED_Red2, OUTPUT); digitalWrite (LED_Red2, LOW); // LED On
        delay (50);
        pinMode (LED_Red1, INPUT); // High Impedence LED Off
        pinMode (LED_Red2, INPUT); // High Impedence LED Off
        delay (450);
        pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On
        pinMode (LED_Green2, OUTPUT); digitalWrite (LED_Green2, LOW); // LED On
        delay (50);
        pinMode (LED_Green1, INPUT); // High Impedence LED Off
        pinMode (LED_Green2, INPUT); // High Impedence LED Off
        delay (450);
      }
      break;
    ////////////////////////////////////////////
    ///             WHITE LED                ///
    ////////////////////////////////////////////
    case 2:
      LED_W_pwr = 2;// minimum led white
      analogWrite(LED_White, LED_W_pwr);  //0 = OFF & 255 ON
      delay (2510); //waitnig for power LED up
      while (digitalRead(sw1) == LOW)
      {
        LED_W_pwr += 1;
        analogWrite(LED_White, LED_W_pwr);  //0 = OFF & 255 ON
        delay(50);
        if (LED_W_pwr > 240)// max led power
        {
          analogWrite(LED_White, 0);
          delay (500);
          analogWrite(LED_White, 240); // max led power
          delay (500);
          while (digitalRead(sw1) == LOW) {};
          break;
        }
      }
      delay (300);
      pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On
      delay (30);
      pinMode (LED_Green1, INPUT); // High Impedence LED Off
      delay (500);
      for (int t = 0; t < 100; t++) {  //2 sec
        if (digitalRead(sw1) == LOW) {
          // full power on
          pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On
          dimmer = true;
          while (digitalRead(sw1) == LOW) {};
          delay (25);
          pinMode (LED_Green1, INPUT); // High Impedence LED Off
        }
        delay (20);
      }
      if (dimmer == true) {
        float W_LED_Dim ;
        W_LED_Dim = (float)LED_W_pwr / 360;
        attachInterrupt(0, SW_ISR, CHANGE);
        for (float LED_W_pwrf = LED_W_pwr ; LED_W_pwrf > 0;  LED_W_pwrf = LED_W_pwrf - W_LED_Dim) {// 360 = 30 min.
          delay (5000);//5sec
          analogWrite(LED_White, LED_W_pwrf);
        }
      }
      else
      {
        attachInterrupt(0, SW_ISR, CHANGE);
        delay (3600000); //mSec
      }
      asm volatile ("  jmp 0");
      break;
    ////////////////////////////////////////////
    ///           S O S                      ///
    ////////////////////////////////////////////
    case 3:
      ////Serial.println("SOS");
      attachInterrupt(0, SW_ISR, CHANGE);
      while (1)
      {
        dot(); dot(); dot(); // S
        delay(700);
        dash(); dash(); dash(); // O
        delay(700);
        dot(); dot(); dot(); // S
        delay(6000);
      }
      break;
    ////////////////////////////////////////////
    ///           LED RED                    ///
    ////////////////////////////////////////////
    case 4:
      pinMode(LED_Red2, INPUT); // High Impedence LED Off
      pinMode (LED_Red1, OUTPUT);//digitalWrite (LED_Red1,LOW); // LED On
      analogWrite(LED_Red1, 235);//  15%,  255 = OFF & 0 ON
      delay (1500);
      if (digitalRead(sw1) == LOW) {
        pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On full power on
        pinMode (LED_Red2, OUTPUT); digitalWrite (LED_Red2, LOW); // LED On
        while (digitalRead(sw1) == LOW) {};
        attachInterrupt(0, SW_ISR, CHANGE);
        delay (3600000); //60 mins
        asm volatile ("  jmp 0");
      }
      ADCSRA = 135; //enable analog digi
      attachInterrupt(0, SW_ISR, CHANGE);
      delay (100);
      while (1) {                
        vSol = analogRead (SolPanel);
        //Serial.println(vSol);
        if (vSol > 600) { //no sun
          asm volatile ("  jmp 0");
        }
        delay (500);
      }
      break;
    ////////////////////////////////////////////
    ///       White Flaing with Sun          ///
    ////////////////////////////////////////////
    case 5:
      attachInterrupt(0, SW_ISR, CHANGE);
      while (1) {
        ADCSRA = 135; //enable analog digi
        delay (100);
        vSol = analogRead (SolPanel);
        if (vSol < 600) { //Volts or no sun
          digitalWrite(LED_White, HIGH);          
          delay(20);// mSec
          digitalWrite(LED_White, LOW);          
        }
        pause (2000);// msec
      }
      break;
    ////////////////////////////////////////////
    ///          B A T T E R Y               ///
    ////////////////////////////////////////////
    case 6:
      ADCSRA = 135; //enable analog digi
      delay (100);
      attachInterrupt(0, SW_ISR, CHANGE);
      timer = 0;
      while (digitalRead(sw1) == HIGH && timer < 4) //stop after n times
      {
        float p = vcc.Read_Perc(VccMin, VccMax);
        //Serial.print (p);
        //Serial.println ("%");
        V10 = int(p) / 10;
        for (int v = 0; v < V10; v++)
        {
          pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On
          delay (10);
          pinMode (LED_Green1, INPUT); // High Impedence LED Off
          delay (650);
        }
        for (int v = V10; v < 10; v++)
        {
          pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On
          delay (10);
          pinMode (LED_Red1, INPUT); // High Impedence LED Off
          delay (650);
        }
        delay (2000);
        timer++;
      }
      pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On
      while (digitalRead(sw1) == LOW) {}; delay(250);
      asm volatile ("  jmp 0");
      break;
  }

}

////////////////////////////////////////////////////////
void dot()
////////////////////////////////////////////////////////
{
  analogWrite(LED_White, 160);  //0 = OFF & 255 ONdigitalWrite(LED_White, HIGH);
  delay(22);
  digitalWrite(LED_White, LOW);
  delay(500);
}

////////////////////////////////////////////////////////
void dash()
////////////////////////////////////////////////////////
{
  analogWrite(LED_White, 20);  //0 = OFF & 255 ONdigitalWrite(LED_White, HIGH);
  delay(150);
  digitalWrite(LED_White, LOW);
  delay(800);
}

////////////////////////////////////////////////////////
//                 sleep Now                          //
////////////////////////////////////////////////////////
void sleepNow()
{
  // disable ADC
  ADCSRA = 0;
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);//SLEEP_MODE_PWR_SAVE);
  interrupts();
  attachInterrupt(0, pinInterrupt, HIGH);
  sleep_enable();
  sleep_mode();
  sleep_disable();
}

////////////////////////////////////////////////////////
void pinInterrupt()
////////////////////////////////////////////////////////
{
  detachInterrupt(0);
  attachInterrupt(0, pinInterrupt, HIGH);
}
////////////////////////////////////////////////////////
//         Interrupt Service Routin                   //
////////////////////////////////////////////////////////
void SW_ISR() {
  analogWrite(LED_White, 0);
  MCUCR = bit (BODS) | bit (BODSE); // turn off brown-out enable in software
  MCUCR = bit (BODS);
  pinMode (LED_Green1, INPUT); // High Impedence LED Off
  pinMode (LED_Green2, INPUT); // High Impedence LED Off
  pinMode (LED_Red1, INPUT); // High Impedence LED Off
  pinMode (LED_Red2, INPUT); // High Impedence LED Off
  //pinMode(LED_Green1, OUTPUT);   digitalWrite (LED_Red1,LOW); // LED On
  for (long x = 0; x < 20000; x ++) {
    pinMode (LED_Red1, INPUT); //  delay
  }
  pinMode (LED_Red1, OUTPUT);   digitalWrite (LED_Red1, LOW); // LED On

  while (digitalRead(sw1) == LOW) {};
  delay(250);
  asm volatile ("  jmp 0");
}


/////////////////////////////////////////////////////////////////////
//              P A U S E and S L E E P                            //
/////////////////////////////////////////////////////////////////////
void pause(int WDPset)
{
  // disable ADC
  ADCSRA = 0;
  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset
  WDTCSR = bit (WDCE) | bit (WDE);
  // set interrupt mode and an interval
  switch (WDPset) {
    case 125:
      WDTCSR = bit (WDIE) | bit (WDP1) | bit (WDP0);    // set WDIE, and .125 second delay
      break;
    case 250:
      WDTCSR = bit (WDIE) | bit (WDP2);    // set WDIE, and .25 second delay
      break;
    case 500:
      WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP0);    // set WDIE, and .5 second delay
      break;
    case 1000:
      WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1);    // set WDIE, and 1 second delay
      break;
    case 2000:
      WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 second delay
      break;
    case 4000:
      WDTCSR = bit (WDIE) | bit (WDP3) ;    // set WDIE, and 4 second delay
      break;
    case 8000:
      WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 8 second delay
      break;
  }
  wdt_reset();  // pat the dog

  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts ();           // timed sequence follows
  sleep_enable();

  // turn off brown-out enable in software
  MCUCR = bit (BODS) | bit (BODSE);
  MCUCR = bit (BODS);
  interrupts ();             // guarantees next instruction executed
  sleep_cpu ();

  // cancel sleep as a precaution
  sleep_disable();
}
ISR (WDT_vect)
{
  wdt_disable();  // disable watchdog
}  // end of WDT_vect
Flash Light contrecoller Norsak_12Arduino
small change, white led 5 min dimming down after 60 min
// By Christian Roy
// Norsak LED controler
// rev_09
//#include <avr/sleep.h>

#include <avr/power.h>
#include <avr/sleep.h>
#include <Vcc.h>
#include <avr/wdt.h>

byte sw1 = 2 ;//pin
byte LED_White = 11;//pin
byte LED_Red1 = 6;//pin
byte LED_Red2 = 7;//pin
byte LED_Green1 = 5;//pin
byte LED_Green2 = 4;//pin
byte Read_Batt = 3;//pin
float LED_W_Max;
const float VccMin   = 2.7;           // Minimum expected Vcc level, in Volts.
const float VccMax   = 4.2;           // Maximum expected Vcc level, in Volts.
const float VccCorrection = 1.0 / 1.0; // Measured Vcc by multimeter divided by reported Vcc
Vcc vcc(VccCorrection);
byte LED_W_pwr;
boolean dimmer = false ;
int timer;
int Tsel;
byte select;
int batt = 0 ;   //pin
int SolPanel = 1; //pin
float vSol;  // voltage at the solar panel
float V10;
boolean RedGreen = false;

///////////////////////////////////////////////////////////////
void setup()
///////////////////////////////////////////////////////////////
{
  analogReference(INTERNAL);//equal to 1.1 volts on ATmega328P
  //pinMode(LED_BUILTIN, OUTPUT);   digitalWrite (LED_Red1,LOW); // LED On
  pinMode(sw1, INPUT_PULLUP);
  pinMode(LED_White, OUTPUT);   digitalWrite (LED_Red1, LOW); // LED On
  analogWrite(LED_White, 0);  //0 = OFF & 255 ON
  pinMode (LED_Red1, INPUT); // High Impedence LED Off
  pinMode (LED_Red2, INPUT); // High Impedence LED Off
  pinMode (LED_Green1, INPUT); // High Impedence LED Off
  pinMode (LED_Green2, INPUT); // High Impedence LED Off
  //digitalWrite(LED_BUILTIN, LOW);


  Serial.begin(9600);
  attachInterrupt(0, SW_ISR, CHANGE);
  /*
    The 5 different modes are:
           SLEEP_MODE_IDLE         -the least power savings
           SLEEP_MODE_ADC
           SLEEP_MODE_PWR_SAVE
           SLEEP_MODE_STANDBY
           SLEEP_MODE_PWR_DOWN     -the most power savings
  */
}

void loop() {
  
  ///////////////////////////////////////////////////////////////
  sleepNow();
  ///////////////////////////////////////////////////////////////

  Tsel = 0;
  select = 0;//                 SELECT

  while (digitalRead(sw1) == LOW)
  {
    select ++;
    pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On LED On
    delay (12);
    pinMode (LED_Green1, INPUT); // High Impedence LED Off
    delay (600);
  }

  delay (750);
  switch (select)
  {
    ////////////////////////////////////////////
    ///           Green RED                  ///
    ////////////////////////////////////////////
    case 1:
      attachInterrupt(0, SW_ISR, CHANGE);
      while (1)
      {
        pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On
        pinMode (LED_Red2, OUTPUT); digitalWrite (LED_Red2, LOW); // LED On
        delay (50);
        pinMode (LED_Red1, INPUT); // High Impedence LED Off
        pinMode (LED_Red2, INPUT); // High Impedence LED Off
        delay (450);
        pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On
        pinMode (LED_Green2, OUTPUT); digitalWrite (LED_Green2, LOW); // LED On
        delay (50);
        pinMode (LED_Green1, INPUT); // High Impedence LED Off
        pinMode (LED_Green2, INPUT); // High Impedence LED Off
        delay (450);
      }
      break;

      
    ////////////////////////////////////////////
    ///             WHITE LED                ///
    ////////////////////////////////////////////
    case 2:
      LED_W_pwr = 2;// minimum led white
      analogWrite(LED_White, LED_W_pwr);  //0 = OFF & 255 ON
      delay (2510); //waitnig for power LED up
      while (digitalRead(sw1) == LOW)   // adjust white LED power
      {
        LED_W_pwr += 1;
        analogWrite(LED_White, LED_W_pwr);  //0 = OFF & 255 ON
        delay(50);
        if (LED_W_pwr > 240)// max led power
        {
          analogWrite(LED_White, 0);
          delay (500);
          analogWrite(LED_White, 240); // max led power
          delay (500);
          while (digitalRead(sw1) == LOW) {};
          break;
        }
      }
      attachInterrupt(0, SW_ISR, CHANGE);
      delay (3600000); // 60 min
      //diming off//
      for (int LED_W_dimer = LED_W_pwr ; LED_W_dimer > 0;  LED_W_dimer--) {    // 360 = 30 min.
        delay (300000/LED_W_pwr);
        analogWrite(LED_White, LED_W_dimer);
      }
      asm volatile ("  jmp 0");
      break;

      
    ////////////////////////////////////////////
    ///           S O S                      ///
    ////////////////////////////////////////////
    case 3:
      ////Serial.println("SOS");
      attachInterrupt(0, SW_ISR, CHANGE);
      while (1)
      {
        dot(); dot(); dot(); // S
        delay(700);
        dash(); dash(); dash(); // O
        delay(700);
        dot(); dot(); dot(); // S
        delay(6000);
      }
      break;

      
    ////////////////////////////////////////////
    ///           LED RED                    ///
    ////////////////////////////////////////////
    case 4:
      pinMode(LED_Red2, INPUT); // High Impedence LED Off
      pinMode (LED_Red1, OUTPUT);//digitalWrite (LED_Red1,LOW); // LED On
      analogWrite(LED_Red1, 235);//  15%,  255 = OFF & 0 ON
      delay (2000);
      if (digitalRead(sw1) == LOW) {
        pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On full power on
        pinMode (LED_Red2, OUTPUT); digitalWrite (LED_Red2, LOW); // LED On
        while (digitalRead(sw1) == LOW) {};
        attachInterrupt(0, SW_ISR, CHANGE);
        delay (3600000); //60 mins
        asm volatile ("  jmp 0");
      }
      ADCSRA = 135; //enable analog digi
      attachInterrupt(0, SW_ISR, CHANGE);
      delay (100);
      while (1) {
        vSol = analogRead (SolPanel);
        //Serial.println(vSol);
        if (vSol > 600) { //no sun
          asm volatile ("  jmp 0");
        }
        delay (500);
      }
      break;

      
    ////////////////////////////////////////////
    ///       White Flashing with night      ///
    ////////////////////////////////////////////
    case 5:
      attachInterrupt(0, SW_ISR, CHANGE);
      while (1) {
        ADCSRA = 135; //enable analog digi
        delay (100);
        vSol = analogRead (SolPanel);
        if (vSol < 600) { //Volts or no sun
          digitalWrite(LED_White, HIGH);
          delay(20);// mSec
          digitalWrite(LED_White, LOW);
        }
        pause (2000);// msec
      }
      break;

      
    ////////////////////////////////////////////
    ///        B A T T E R Y   level         ///
    ////////////////////////////////////////////
    case 6:
      ADCSRA = 135; //enable analog digi
      delay (100);
      attachInterrupt(0, SW_ISR, CHANGE);
      timer = 0;
      while (digitalRead(sw1) == HIGH && timer < 4) //stop after n times
      {
        float p = vcc.Read_Perc(VccMin, VccMax);
        //Serial.print (p);
        //Serial.println ("%");
        V10 = int(p) / 10;
        for (int v = 0; v < V10; v++)
        {
          pinMode (LED_Green1, OUTPUT); digitalWrite (LED_Green1, LOW); // LED On
          delay (10);
          pinMode (LED_Green1, INPUT); // High Impedence LED Off
          delay (650);
        }
        for (int v = V10; v < 10; v++)
        {
          pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On
          delay (10);
          pinMode (LED_Red1, INPUT); // High Impedence LED Off
          delay (650);
        }
        delay (2000);
        timer++;
      }
      pinMode (LED_Red1, OUTPUT); digitalWrite (LED_Red1, LOW); // LED On
      while (digitalRead(sw1) == LOW) {}; delay(250);
      asm volatile ("  jmp 0");
      break;
  }

}

////////////////////////////////////////////////////////
void dot()
////////////////////////////////////////////////////////
{
  analogWrite(LED_White, 160);  //0 = OFF & 255 ONdigitalWrite(LED_White, HIGH);
  delay(22);
  digitalWrite(LED_White, LOW);
  delay(500);
}

////////////////////////////////////////////////////////
void dash()
////////////////////////////////////////////////////////
{
  analogWrite(LED_White, 20);  //0 = OFF & 255 ONdigitalWrite(LED_White, HIGH);
  delay(150);
  digitalWrite(LED_White, LOW);
  delay(800);
}

////////////////////////////////////////////////////////
//                 sleep Now                          //
////////////////////////////////////////////////////////
void sleepNow()
{
  // disable ADC
  ADCSRA = 0;
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);//SLEEP_MODE_PWR_SAVE);
  interrupts();
  attachInterrupt(0, pinInterrupt, HIGH);
  sleep_enable();
  sleep_mode();
  sleep_disable();
}

////////////////////////////////////////////////////////
void pinInterrupt()
////////////////////////////////////////////////////////
{
  detachInterrupt(0);
  attachInterrupt(0, pinInterrupt, HIGH);
}
////////////////////////////////////////////////////////
//         Interrupt Service Routin                   //
////////////////////////////////////////////////////////
void SW_ISR() {
  analogWrite(LED_White, 0);
  MCUCR = bit (BODS) | bit (BODSE); // turn off brown-out enable in software
  MCUCR = bit (BODS);
  pinMode (LED_Green1, INPUT); // High Impedence LED Off
  pinMode (LED_Green2, INPUT); // High Impedence LED Off
  pinMode (LED_Red1, INPUT); // High Impedence LED Off
  pinMode (LED_Red2, INPUT); // High Impedence LED Off
  //pinMode(LED_Green1, OUTPUT);   digitalWrite (LED_Red1,LOW); // LED On
  for (long x = 0; x < 20000; x ++) {
    pinMode (LED_Red1, INPUT); //  delay
  }
  pinMode (LED_Red1, OUTPUT);   digitalWrite (LED_Red1, LOW); // LED On

  while (digitalRead(sw1) == LOW) {};
  delay(250);
  asm volatile ("  jmp 0");
}


/////////////////////////////////////////////////////////////////////
//              S L E E P with delay                               //
/////////////////////////////////////////////////////////////////////
void pause(int WDPset)
{
  // disable ADC
  ADCSRA = 0;
  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset
  WDTCSR = bit (WDCE) | bit (WDE);
  // set interrupt mode and an interval
  switch (WDPset) {
    case 125:
      WDTCSR = bit (WDIE) | bit (WDP1) | bit (WDP0);    // set WDIE, and .125 second delay
      break;
    case 250:
      WDTCSR = bit (WDIE) | bit (WDP2);    // set WDIE, and .25 second delay
      break;
    case 500:
      WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP0);    // set WDIE, and .5 second delay
      break;
    case 1000:
      WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1);    // set WDIE, and 1 second delay
      break;
    case 2000:
      WDTCSR = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 second delay
      break;
    case 4000:
      WDTCSR = bit (WDIE) | bit (WDP3) ;    // set WDIE, and 4 second delay
      break;
    case 8000:
      WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0);    // set WDIE, and 8 second delay
      break;
  }
  wdt_reset();  // pat the dog

  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts ();           // timed sequence follows
  sleep_enable();

  // turn off brown-out enable in software
  MCUCR = bit (BODS) | bit (BODSE);
  MCUCR = bit (BODS);
  interrupts ();             // guarantees next instruction executed
  sleep_cpu ();

  // cancel sleep as a precaution
  sleep_disable();
}
ISR (WDT_vect)
{
  wdt_disable();  // disable watchdog
}  // end of WDT_vect

Schematics

Norsak 1 LED Controller
norsak_1_sHIWuMJp5Z.fzz

Comments

Similar projects you might like

Simple DALI Controller

Project in progress by NabiyevTR

  • 32,437 views
  • 55 comments
  • 35 respects

DC Motors Controller Board

Project showcase by Shahariar

  • 2,027 views
  • 0 comments
  • 6 respects

Multi-Dashboard Display with Arduino Controller

Project showcase by Colin O'Dell

  • 24,870 views
  • 6 comments
  • 67 respects

Soldering Iron Controller for Hakko 907 v.2

Project tutorial by Alexander

  • 20,013 views
  • 133 comments
  • 41 respects

MKR1000 RGB Strip Controller

Project showcase by Keith Mitchell

  • 7,588 views
  • 0 comments
  • 11 respects

Controlling a Robot with a PlayStation Controller

Project tutorial by Andrew R Gross and Jonathan Gross

  • 2,849 views
  • 0 comments
  • 7 respects
Add projectSign up / Login