Things used in this project

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


One LED blinks while the other stays on


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);
  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;
              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 
         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


Jackie Thomas

Retired software engineer.



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


Similar projects you might like

LED Roulette Game
  • 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
  • 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
  • 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
  • 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
  • 5,419
  • 20

Full instructions

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

tinyGlow Smart LEDs
  • 1,038
  • 9


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

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog