Go Down

Topic: Problem with error message (Read 883 times) previous topic - next topic

Grumpy_Mike

I imagine that this is what you want, but I am not sure.
Code: [Select]

const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;
void setup() {
pinMode(hl, OUTPUT);

pinMode(buttonPin, INPUT);
}
void loop(){

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(hl, LOW);
}
else {
// turn LED off:
digitalWrite(hl, HIGH);
}

digitalWrite(hl, HIGH);
delay(1000);
digitalWrite(hl, LOW);
delay(1000);
}

robtillaart

First, if you post please use the # button to tag code correctly

Give this a try, I removed a { and added an extra delay(200) , .. (code not tested)
Code: [Select]

const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;

void setup()
{
 pinMode(hl, OUTPUT);
 pinMode(buttonPin, INPUT);
}

void loop()
{
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH)
 {
   digitalWrite(hl, LOW);
 }
 else
 {
   digitalWrite(hl, HIGH);
 }
 delay(200);  // extra

 digitalWrite(hl, HIGH);
 delay(1000);

 digitalWrite(hl, LOW);
 delay(1000);
}
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

UKHeliBob

Problem 1 - all the statements should end with a semi-colon like this
Code: [Select]
    digitalWrite(hl, HIGH);

Are there any lines in your sketch that don't ?

Problem 2 - when, if ever, is this code going to be executed ?

Code: [Select]
{
  digitalWrite(hl, HIGH)
  delay(1000);
  digitalWrite(hl, low)
  delay(1000)
}
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sakfromdk


First, if you post please use the # button to tag code correctly

Give this a try, I removed a { and added an extra delay(200) , .. (code not tested)
Code: [Select]

const int buttonPin = 2;
const int hl = 3;
int buttonState = 0;

void setup()
{
 pinMode(hl, OUTPUT);
 pinMode(buttonPin, INPUT);
}

void loop()
{
 buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH)
 {
   digitalWrite(hl, LOW);
 }
 else
 {
   digitalWrite(hl, HIGH);
 }
 delay(200);  // extra

 digitalWrite(hl, HIGH);
 delay(1000);

 digitalWrite(hl, LOW);
 delay(1000);
}



Hi, it worked, thanks, but why did you make an extra delay, and why did it work???

Nick Gammon

Please don't cross post. Threads merged.

Go Up