Pages: [1]   Go Down
Author Topic: void loop() not looping?  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
Orlando, FL
Offline Offline
Full Member
***
Karma: 0
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

when i put an If statment inside of a loop() function it does not continue looping.  Once the if statment is true the board remains in that state and doesn't change anymore.  attached is my code.  Any suggustions or is this a bug in the board?


int ledPin = 13;                 // LED connected to digital pin 13
int buttonPin = 7;              // pushbutton connect to digital pin 7
int val = 0;                    // Set initial state to LED off

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
  pinMode(buttonPin, INPUT);    // sets the gitial pin 7 as an input
}

void loop()
{
  val = digitalRead(buttonPin); //read the input of pin 7
  if(val == 1)
  {
    digitalWrite(ledPin, val);   // sets the LED of pin 13
  }
}
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have any code that would turn off the LED.  You don't actually need an if-statement at all, just do:

Code:
void loop()
{
  val = digitalRead(buttonPin); //read the input of pin 7
  digitalWrite(ledPin, val);   // sets the LED of pin 13
}
Logged

Orlando, FL
Offline Offline
Full Member
***
Karma: 0
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

acutually the code i posted is not the code i had in question.  I aplogise.  I'll put the right code up here with my question once i get get home and copy and paste it again.
« Last Edit: July 15, 2006, 01:01:56 am by stealthtransam » Logged

Pages: [1]   Go Up
Jump to: