Problem with program for controlling and LED with a pushbutton

:slight_smile: Hi :~,

I’m new to Arduino, I’ve recently invested some of my money into an Arduino Uno and some other starter equipment. I’m happy with my progress so far: I’ve read Massimo Banzi’s “Getting Started with Arduino (Make: Projects)” and have completed the first exercise to get an LED blinking. I’m on the second project where you learn how to control and LED with a pushbutton and am having some problems with the program. I :cold_sweat: can’t verify it :astonished:. I’ve written the program as follows:

#define LED 13 //the pin for the LED
#define BUTTON 7 //the input where the pushbutton is connected
int val=0; //val will be used to store the state of the pin
void setup()
{
** pinMode (LED, OUTPUT); //tell the Arduino LED is an output**
** pinMode (BUTTON, INPUT); //and BUTTON is an input**
}
void loop()
{
** val=digitalRead(BUTTON); //read input value and store it**
** //check whether the input is HIGH (button pressed)**
** if(val==HIGH_){**
** digitalWrite(LED, HIGH); //turn LED on**
** } else {**
** digitalWrite(LED, LOW);**
** }**
}

Whenever I try to verify it, it tells me that ‘HIGH’ was not declared in the scope and gives me the following error message:

sketch_aug24a.ino: In function 'void loop()':
sketch_aug24a:13: error: 'HIGH_' was not declared in this scope

Can anyone tell me what this means? Did I write the program incorrectly? I just want to know what I did wrong and how I can fix it, I’m going to continue to try to fix it myself, but any help would be greatly appreciated. :PThank you :).

  • :slight_smile: SonomaComa :slight_smile:

Did I write the program incorrectly?

Yes.
You wrote
HIGH_
You should have written
HIGH
( hint :- no underscore on the end )

Read this before posting a programming question

Code tags next time please.

Thank you so much, I fixed the error and it was able to verify the program. And I will include code tags. Thank you.