how to blink forever

Hello again :grinning: i would like to know how to use the arduino as a pulse generator... i mean we all know the Blink Example and also de Button Example...

the blink one turn on an off a led placing a HIGH and a LOW in pin 13
the button one read the state of pin 2 and if is HIGH turn HIGH pin 13 else turn it LOW

how can i mix this two examples?

this is what i want to do

first as pin 8 Turn HIGH i want Pin 13 turn on an off (forever)

an meanwhile

i want the arduino from the beginning start reading the state of pin 2 and if is HIGH turn Pin 3 LOW else turn it HIGH

thanks for reading :smiley:

It seems easy, and a good project to start. What is the problem?

i dont know how i try this way but is not working

/*
  Button
 
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 2. 
 
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int restart =  4;      // the number of the LED pin
const int pulso =  13;  

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  
    // wait
  // initialize the LED pin as an output:
  pinMode(restart, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
 pinMode(pulso, OUTPUT);       
}

void loop(){
  {
   digitalWrite(pulso, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);              // wait for a second
  digitalWrite(pulso, LOW);    // turn the LED off by making the voltage LOW
  delay(200);  
  }
    
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
 if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(restart, LOW);  
  } 
  else {
    // turn LED off:
    digitalWrite(restart, HIGH); 
  }
}

but is not working

Define "working"
Describe how that differs from your observations.

Probably a good idea to get rid of delay() and use millis() for timing. See several things at a time.

The Thread planning and implementing a program may also be useful.

...R

For what I read you need 2 "buttons":

  • pin 8;
  • pin 2;

but you only have one in your code:

(...)
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
 if (buttonState == HIGH) {     
(...)

You need the same thing here:

(...)
  {
   digitalWrite(pulso, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(200);              // wait for a second
  digitalWrite(pulso, LOW);    // turn the LED off by making the voltage LOW
  delay(200);  
  }
(...)

Don't you agree?

BTW, look to what Robin2 wrote:

Robin2:
Probably a good idea to get rid of delay() and use millis() for timing. (...)

Look to the example of BlinkWithoutDelay, instead of Blink.