I just started using the book Making Things Talk and I keep getting an error for the ‘Simple Serial’ sketch on page 29.
these are the error that keep coming back:
sketch_feb27a:29: error: expected unqualified-id before 'if'
sketch_feb27a:33: error: expected unqualified-id before 'if'
sketch_feb27a:37: error: expected declaration before '}' token
Code: Select all
/*
Simple Serial
Listens for an incoming serial byte, adds one to the byte
and sends the result back out serially.
Also blink a LED on pin 13 every half second.
*/
int LEDPin = 13; //you can use any I/O pin you want
int inByte = 0; //variable to hold incoming serial data
long blinkTimer = 0; //keeps track of how long since the LED was last turned off
int blinkInterval = 1000; //a full second from on to off to on again
void setup() {
pinMode(LEDPin, OUTPUT); //set pin 13 to be an output
Serial.begin(9600); //configure the serial port for 9600 bps data rate
}
void loop () {
//if there are any incoming bytes to read: if (Serial.available() > 0) {
//then read the first available byte:
inByte = Serial.read();
//and add one to it, then send the result out:
Serial.write(inByte+1);
}
//Meanwhile, keep blinking the LED.
//after a half of a second, turn the LED on:
if (millis() - blinkTimer >= blinkInterval / 2) {
digitalWrite(LEDPin, HIGH); //turn the LED pin 13 on
}
//after half a second, turn the LED off and reset the timer:
if (millis() - blinkTimer >=blinkInterval) {
digitalWrite(LEDPin, LOW); //turn the LED pin 13 off
blinkTimer = millis(); //reset the timer
}
}
Any ideas?? Thank you
--
Alexandre Balcer