Things used in this project

Hardware components:
Attiny85
Microchip ATTiny85
Programmed using Arduino IDE and Sparkfun Programmer
×1
Omron b3f 1000 image 75px
SparkFun Pushbutton switch 12mm
×1
AllThingsTalk 8 pin dip ic socket
×1
Mfr 25frf52 10k sml
Resistor 10k ohm
×1
Adafruit industries ada654 image 75px
Coin Cell Battery CR2032
×1
uArm battery holder for CR2032
×1

Schematics

BLINKING LED
One LED blinks while the other stays on
button_switch_bStukqR8Ai.fzz

Code

Blinking LEDArduino
Program will blink 1 LED and keep the other on. There is a switch that will shut both on and off. Debouce is coded.
 int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 1;      // the number of the LED pin
const int ledPinB = 0;
const int heartBeat = 3;
const int heartBeat1 = 10;
// Variables will change:
int blinkLedState = LOW;

int ledState = LOW;         // the current state of the output pin
int buttonState;             // the current inputFromSwitch from the input pin
int lastButtonState = LOW;   // the previous inputFromSwitch from the input pin

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
unsigned long currentTime = 0;  // the last time the output pin was toggled
unsigned long blinkLastTime = 0;  // the debounce time; increase if the output flickers
unsigned long myTime = 0;  
int offTime = 200; // how long blink off
int onTime =  1500;  //how long blink off
unsigned long previousMillis = 0;
unsigned long currentMillis;
void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(heartBeat, OUTPUT);  // set initial LED state
  pinMode(heartBeat1, OUTPUT);  // set initial LED state
  pinMode(ledPin, OUTPUT);  // set initial LED state
  pinMode(ledPinB, OUTPUT);  // set initial LED state
  digitalWrite(ledPin, ledState);
  digitalWrite(ledPin, blinkLedState);
  digitalWrite(heartBeat, HIGH);
  digitalWrite(heartBeat1, HIGH);
  //Serial.begin(9600);
  int holdCurrentMillis = 0;
  int holdPreviousMillis = 0;
}

void loop() {
  // read the state of the switch into a local variable:
  int inputFromSwitch = digitalRead(buttonPin);
  //blinkLedState = LOW;
  
  

  // If the switch changed, due to noise or pressing:
  if (inputFromSwitch != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }
   
  if ((millis() - lastDebounceTime) > debounceDelay) 
    {
    if (inputFromSwitch != buttonState)             //  we only do this once, in a.m. and once in p.m. 
        {
        digitalWrite(heartBeat1, LOW);  
        buttonState = inputFromSwitch;
        if (buttonState == HIGH) // can be shutting LEDs off or turning on
           {         //  just changing state of the LEDs  
           ledState = !ledState; // change the LED state
           if (ledState == HIGH) // we just turned the LEDs ON
              {                  //  we want to set up blinking
              blinkLedState = HIGH;
     //         Serial.println("changed state ");
              previousMillis = 0;
              }  
           else
              blinkLedState = LOW;  // turning LEDs OFF, set blink for off            
         
           }
        }
        else digitalWrite(heartBeat1, HIGH); 

  if (ledState == HIGH)         //the mother state is LEDs ON   this is set in the morning/nite and fall thru here                                                      //  during day and nite 
     {
      currentMillis = millis();  // set current time
  //  Serial.println("blinkLedState:         ");
 //  Serial.print(blinkLedState);
     if ((blinkLedState == HIGH) && (currentMillis - previousMillis >= onTime)) // previous millis set in morning and nite first
       {                                            //  the blink LEDS were on and exceeded time
      //  Serial.println("in first ");
        blinkLedState = LOW;   // turn it off       //turn blinker OFF
        digitalWrite(ledPinB, blinkLedState);       // output the blinker with nothing
        previousMillis = currentMillis;             //  reset the previous to the current time 
       }
     else 
         if ((blinkLedState == LOW) && (currentMillis - previousMillis >= offTime))  
         {
      //    Serial.println("in second ");
       //   Serial.print("CURRENT MILLIS:         ");
      //    Serial.println(currentMillis);
      //    Serial.println("in second ");
      //    Serial.print("PREVIOUS MILLIS:        ");
     //    Serial.println(previousMillis);
          blinkLedState = HIGH;                         //  change state to ON 
         digitalWrite(ledPinB, blinkLedState);         //  output the LED ON
         previousMillis = currentMillis;               //  reset the previous time
         }
    } 
    else digitalWrite(ledPinB, LOW); 
 
   digitalWrite(ledPin, ledState);
    } 
   
   lastButtonState = inputFromSwitch;
}   //  end loop

Credits

93c8602115deba414b4046020951e2f1
Jackie Thomas

Retired software engineer.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

LED Roulette Game
Easy
  • 10
  • 2

Full instructions

A fun pocket-sized travel game for any age. Try your luck and make the light stop on the green LED.

PHPoC - Detect Someone Taking Your Stuff  and send Gmail
Easy
  • 632
  • 14

When your stuff is being taken away by a thief, PHPoC makes an alert and sends a notification to you via Gmail.

Safe City: A Device to Keep You Safe
Easy
  • 1,246
  • 9

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Scavenger Hunt Clues w/ Telephone Keypad
Easy
  • 1,109
  • 4

Full instructions

Type the correct code on the phone's keypad to hear the clue through the handset, then decode the message to finish before the other team.

Raspberry Pi Shutdown / Restart Button
Easy
  • 5,419
  • 20

Full instructions

Building an installation project? Shut down or reboot your project safely, without a keyboard or SSH!

tinyGlow Smart LEDs
Easy
  • 1,038
  • 9

Protip

Bring the ATtiny85 and NeoPixels together in affordable, addressable lights!

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog