Skip to main content
Format sketch
Source Link
the busybee
  • 2.5k
  • 10
  • 19

I have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. I'm using Tinkercad with Arduino UNO.

int buttonPin = 7;
int redledpin = 11;

int orangeledpin = 12;

void setup() {
  pinMode(buttonPin, INPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);
}

void loop ()
{
  {
  if (digitalRead(buttonPin) == HIGH) {
  
   digitalWrite(11, LOW);

    digitalWrite(12, LOW);
  }
 
   } else {
   
  digitalWrite(11, HIGH);
   
  delay(500);
   
  digitalWrite(11, LOW);
   
  delay(500);
  }
  
   if (digitalRead(buttonPin) == HIGH) {
   
  digitalWrite(11, LOW);
 
    digitalWrite(12, LOW);
   }

  } else {
    
 digitalWrite(12, HIGH);
   
   delay(500);
  
   digitalWrite(12, LOW);
  
   delay(500);
  } 

  if (digitalRead(buttonPin) == HIGH) {
  
   digitalWrite(11, LOW);
  
    digitalWrite(12, LOW);
  
  }
 
}  

I have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. I'm using Tinkercad with Arduino UNO.

int buttonPin = 7;
int redledpin = 11;

int orangeledpin = 12;

void setup() {
  pinMode(buttonPin, INPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);
}

void loop ()
{
  
  if(digitalRead(buttonPin) == HIGH) {
  
  digitalWrite(11, LOW);

   digitalWrite(12, LOW);
  }
 
    else {
   
  digitalWrite(11, HIGH);
   
  delay(500);
   
  digitalWrite(11, LOW);
   
  delay(500);
  }
  
   if(digitalRead(buttonPin) == HIGH) {
   
 digitalWrite(11, LOW);
 
  digitalWrite(12, LOW);
   }

   else {
    
 digitalWrite(12, HIGH);
   
   delay(500);
  
   digitalWrite(12, LOW);
  
   delay(500);
  }
  if(digitalRead(buttonPin) == HIGH) {
  
  digitalWrite(11, LOW);
  
 digitalWrite(12, LOW);
   }
 
}  

I have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. I'm using Tinkercad with Arduino UNO.

int buttonPin = 7;
int redledpin = 11;

int orangeledpin = 12;

void setup() {
  pinMode(buttonPin, INPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);
}

void loop () {
  if (digitalRead(buttonPin) == HIGH) {
    digitalWrite(11, LOW);

    digitalWrite(12, LOW);

  } else {
    digitalWrite(11, HIGH);
    delay(500);
    digitalWrite(11, LOW);
    delay(500);
  }
  
  if (digitalRead(buttonPin) == HIGH) {
    digitalWrite(11, LOW);

    digitalWrite(12, LOW);

  } else {
    digitalWrite(12, HIGH);
    delay(500);
    digitalWrite(12, LOW);
    delay(500);
  } 

  if (digitalRead(buttonPin) == HIGH) {
    digitalWrite(11, LOW);
  
    digitalWrite(12, LOW);
 
  }
}  
Bumped by Community user
Bumped by Community user
Bumped by Community user
Backticked code, added a language specifier and corrected typos.
Source Link

iI have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. ImI'm using TinkercadTinkercad with Arduino UNO

int buttonPin = 7;

int redledpin = 11;

int orangeledpin = 12;

void setup() { pinMode(buttonPin, INPUT);

pinMode(11, OUTPUT);

pinMode(12, OUTPUT); }

void loop () {

if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

else {

digitalWrite(11, HIGH);

delay(500);

digitalWrite(11, LOW);

delay(500); }

if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

else {

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(500); } if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }.

}

int buttonPin = 7;
int redledpin = 11;

int orangeledpin = 12;

void setup() {
  pinMode(buttonPin, INPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);
}

void loop ()
{
  
  if(digitalRead(buttonPin) == HIGH) {
  
 digitalWrite(11, LOW);

   digitalWrite(12, LOW);
  }
 
    else {
   
 digitalWrite(11, HIGH);
   
 delay(500);
   
 digitalWrite(11, LOW);
   
 delay(500);
  }
  
   if(digitalRead(buttonPin) == HIGH) {
   
digitalWrite(11, LOW);
 
  digitalWrite(12, LOW);
   }

   else {
    
digitalWrite(12, HIGH);
   
  delay(500);
  
  digitalWrite(12, LOW);
  
  delay(500);
  }
  if(digitalRead(buttonPin) == HIGH) {
  
 digitalWrite(11, LOW);
  
 digitalWrite(12, LOW);
   }

}  

i have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. Im using Tinkercad with Arduino UNO

int buttonPin = 7;

int redledpin = 11;

int orangeledpin = 12;

void setup() { pinMode(buttonPin, INPUT);

pinMode(11, OUTPUT);

pinMode(12, OUTPUT); }

void loop () {

if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

else {

digitalWrite(11, HIGH);

delay(500);

digitalWrite(11, LOW);

delay(500); }

if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

else {

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(500); } if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

}

I have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. I'm using Tinkercad with Arduino UNO.

int buttonPin = 7;
int redledpin = 11;

int orangeledpin = 12;

void setup() {
  pinMode(buttonPin, INPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);
}

void loop ()
{
  
  if(digitalRead(buttonPin) == HIGH) {
  
 digitalWrite(11, LOW);

   digitalWrite(12, LOW);
  }
 
    else {
   
 digitalWrite(11, HIGH);
   
 delay(500);
   
 digitalWrite(11, LOW);
   
 delay(500);
  }
  
   if(digitalRead(buttonPin) == HIGH) {
   
digitalWrite(11, LOW);
 
  digitalWrite(12, LOW);
   }

   else {
    
digitalWrite(12, HIGH);
   
  delay(500);
  
  digitalWrite(12, LOW);
  
  delay(500);
  }
  if(digitalRead(buttonPin) == HIGH) {
  
 digitalWrite(11, LOW);
  
 digitalWrite(12, LOW);
   }

}  
Source Link

Alternate LED Blinking Using PushButton

i have an task for my class where we have to make 2 LEDS blink alternatively using a pushbutton. I've figured out how to do the blinking and alternating but from time to time one of the led would go twice in a row instead of the other led blinking. Need help figuring out what's making it do this in my code. Im using Tinkercad with Arduino UNO

int buttonPin = 7;

int redledpin = 11;

int orangeledpin = 12;

void setup() { pinMode(buttonPin, INPUT);

pinMode(11, OUTPUT);

pinMode(12, OUTPUT); }

void loop () {

if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

else {

digitalWrite(11, HIGH);

delay(500);

digitalWrite(11, LOW);

delay(500); }

if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

else {

digitalWrite(12, HIGH);

delay(500);

digitalWrite(12, LOW);

delay(500); } if(digitalRead(buttonPin) == HIGH) {

digitalWrite(11, LOW);

digitalWrite(12, LOW); }

}