Go Down

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


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]
/* 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);
      digitalWrite(ledPin, LOW);
      //digitalWrite(ledPin, HIGH);
    if (buttonState == LOW) {
      digitalWrite(ledPin, LOW);

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


[/code]Any help please txs


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