Jackie Thomas
Published © GPL3+

Mask with Blinking Eye

Make a great mask more eye-catching with a blinking eye, an on-off switch, powered by a cell and driven by an ATtiny85.

BeginnerProtip1 hour826
Mask with Blinking Eye

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
Programmed using Arduino IDE and Sparkfun Programmer
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
AllThingsTalk 8 pin dip ic socket
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Coin Cell Battery CR2032
Coin Cell Battery CR2032
×1
uArm battery holder for CR2032
×1

Story

Read more

Schematics

BLINKING LED

One LED blinks while the other stays on

Code

Blinking LED

Arduino
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

Jackie Thomas

Jackie Thomas

2 projects • 3 followers
Retired software engineer.

Comments