Go Down

Topic: 2 blink without delay LED and 1 push button with LED (Read 106 times) previous topic - next topic


Hello I am working on a code that lets 2 led blink without delay while at the same time allows me to press a push button to allow a 3rd to light up. The problem I am having is the code only runs the first part the 2 blink without delay but it does not run the second part which is  to turn the 3rd LED on with a button. I tried to combine the blink without delay code and a push button code to see if it would work but it did not here is my code.

const int LY=9;
const int LR=10;
const int LB=12;
const int BUTTON=11;
const int fade=10;
int ButtonState =0;
int ledState = LOW;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;
boolean ledOn1 = false;
unsigned long previousMillis = 0;
const long interval = 1;

void setup() {
  pinMode(LY, OUTPUT);
  pinMode(LR, OUTPUT);
  pinMode(BUTTON, INPUT);

boolean debounce(boolean last)
  boolean current = digitalRead(BUTTON);
  if (last != current)
    current = digitalRead(BUTTON);

void loop(){
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
    ledOn1 = !ledOn1;
  lastButton = currentButton;
  digitalWrite(LB, ledOn1);

   unsigned long currentMillis = millis();

   if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledOn == LOW) {
      ledOn = HIGH;
    } else {
      ledOn = LOW;

  digitalWrite(LR, ledOn);
  digitalWrite(LR, LOW);
  digitalWrite(LY, LOW);

 Any tips or advice for me?
Thank you for your time.


So you are using delay() in this sketch, no no no, go back and read about BWD.


No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.


Thank you I will read this and see what I was doing wrong and correct my code.

Go Up