Go Down

Topic: led from blink to 2 sec on (Read 375 times) previous topic - next topic

artois

Hi all
I have already asked before to help to run a blink led to on for a time period. Can someone pls show how using what I have here, or if i'm wrong pls show how I go about it.  I want to blink a led for time period and then to on when  I press a switch.
Code: [Select]
[code]
/* led light
*/

int buttonPin = 2;
int ledPin = 13;
int buttonState = LOW;
int ledDelay = 2000;
int ledState = HIGH;

void setup() {   // put your setup code here, to run once:

  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
}

void loop()  {    // put your main code here, to run repeatedly:

   buttonState = digitalRead(buttonPin);
     (buttonState == HIGH);
  if (buttonState == HIGH) {

   for (int x = 0; x < 15; x++)
      digitalWrite(ledPin, HIGH);
      delay(80);
      digitalWrite(ledPin, LOW);
      delay(70);
      //digitalWrite(ledPin, HIGH);
      //delay(2000);
       
    if (buttonState == LOW) {
      digitalWrite(ledPin, LOW);

    } else {
       
      //(buttonState == HIGH);
      //delay(2000);
      digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin, LOW);
      //delay(2000);

    }
  }
}

[/code]Any help please txs

AWOL

Have a look at the blink without delay example in the IDE examples, and see if you can adapt it to your needs.
One problem with the code you have is if you hit the button during the for loop, you turn the LED off, then carry on blinking it.

Go Up