Beginner needs help

Hi, There.

I’m working my way through “Make: Getting Started with Arduino” and I have hit a brick wall with Example 4-4.

I’ll show you the Sketch as it is in the book (I’m pretty sure that I have done it exactly, apart from my notes) then I’ll put the error message.

But it’s the first thing : invalid suffix “val” on integer constant
I expect when I’ve sorted this, there will be some butterfly effect to my advantage.

The Sketch:

const int LED = 13;   // LED in 13
const int BUTTON = 7; // Button in 7
int val=0;            // used to store the state 
                      // of the input pin
int old_val=0;        // stores the previous value of "val"
int state =0,         // 0=LED off, 1=LED on

void setup() {
pinMode(LED, Output);   //pin 13 = output
pinMode(BUTTON, Input); //pin 7 = input0
}

void loop() {
val = digitalRead(BUTTON); //read input value and store it

//check if there was a transition
if 99val == HIGH) && (old_val == LOW)){
  state = 1 - state;

old_val = val; // val is now old, let's store it

if (state == 1) {
  digitalWrite(LED, HIGH); //turn LED on
} else {
  digitalWrite(LED, LOW); //turn LED off
}
}

the error message:

ImprovedPushButtonToggle.ino:17:4: error: invalid suffix "val" on integer constant

ImprovedPushButtonToggle.ino:8:1: error: expected unqualified-id before 'void'

ImprovedPushButtonToggle.ino: In function 'void loop()':

ImprovedPushButtonToggle.ino:17:4: error: expected '(' before numeric constant

ImprovedPushButtonToggle.ino:27:1: error: expected '}' at end of input

Error compiling.

ImprovedPushButtonToggle.ino (705 Bytes)

if 99val == HIGH) && (old_val == LOW)){

Did you miss the shift key?

Note: Format your code with (CTRL) T

Welcome to the Forum. Please read Nick gammon’s two posts at the top of this Forum for guidelines on posting here. Before you post your code, reformat in the IDE with Ctrl-T and then copy it within the code tags (i.e., click the </> symbol). It will help us help you.

Also, your statement:

int state =0,

probably should be a semicolon, not a comma.

  // int = integer   vs byte     Do look up these two types on the Internet.

const byte LED = 13;   // LED on pin 13       const(constant) = all fixed(unchanged)
const byte BUTTON = 7; // Button on pin 7    const(constant) = all fixed(unchanged)

byte Current_Val = 0;            //  try to use a name for everyone and yourself to understand the code
byte Last_Val = 0;              // stores the previous value of "val"
byte LED_State = 0;       // 0=LED off, 1=LED on (use ; here, not  a comma)

void setup()

{

pinMode(LED, OUTPUT);   // pin 13 = output (OUTPUT -- ALL CAPITAL LETTERS)
pinMode(BUTTON, INPUT_PULLUP); // Internal pull up button pin 7 
                               // so you just connect a switch to pin 7 to gnd no need to use any resistors
}

 Look at the second if statement in your main loop and correct the mistake in your first if statement then.

I usually do this for my if statements:

if( x == y)  // NO ; HERE

one line of code here;

else

one line of code here; 

// you may skip the  {   }  if  there is only one line of code in between
if ( x == y)  //NO ; HERE

{ do this;  // one line of code

   do this;  // the second line of code and so on
}

else

{ do that; // two(or more) lines of code here
   do that;
}

//  use {    } to include what you expect the programme to do for you  in your statements

That error message is marked as coming from line number 17. Just look there.

Thanks for the debugging practice. I found 4 more problems similar to the 2 already pointed out and it's working for me now. it's good practice for you to find them yourself.

this line:

state = 1 - state;

had me confused as I hadn't seen it before(yes I'm a newb also) was sure it needed to be:

state = !state;

but it does work either way. so you only have the 4 more typo's to find.

EDIT: guess I'm too slow .

"val" may be in conflict with a library variable, try changing to "myval" or something similar.

if 99val == HIGH) && (old_val == LOW)){

Your problem is the missing left parenthesis between the "if" and the "99val"

Thanks, guys. it seemed the val problem was that I had accidentally put down 99val instead of (val the bleedin' shift key was to blame. haha couple of other things regarding syntax holding me back.

I'll get used to it, and i shall certainly format correctly next time i post here.

cheers.