I'm trying to run a serial command test sketch, that switches an LED 13 off & on, when an 'On' and 'off' is received via serial, using Hyperterminal I assume.
When uploaded does not function, (old LED blink sketch continues to run)
Errors produced:
sketch_feb22a:17: error: stray '@' in program
sketch_feb22a:18: error: stray '@' in program
sketch_feb22a:6: error: 'to' does not name a type
sketch_feb22a:8: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:9: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:3: error: expected unqualified-id before '/' token
sketch_feb22a:25: error: expected unqualified-id before '/' token
sketch_feb22a.ino: In function 'void setup()':
sketch_feb22a:29: error: expected primary-expression before '/' token
sketch_feb22a:29: error: expected primary-expression before '/' token
sketch_feb22a:29: error: 'Initialize' was not declared in this scope
sketch_feb22a:29: error: expected ;' before 'the' sketch_feb22a:32: error: 'ledPin' was not declared in this scope sketch_feb22a:33: error: expected primary-expression before '/' token sketch_feb22a:33: error: expected primary-expression before '/' token sketch_feb22a:33: error: 'Displays' was not declared in this scope sketch_feb22a:33: error: expected ;' before 'a'
sketch_feb22a.ino: In function 'void loop()':
sketch_feb22a:40: error: expected primary-expression before '/' token
sketch_feb22a:40: error: expected primary-expression before '/' token
sketch_feb22a:40: error: 'Check' was not declared in this scope
sketch_feb22a:40: error: expected ;' before 'if' sketch_feb22a:97: error: expected }' at end of input
/ * Command String In String using Serial Port
The program waits for a command arrives on the serial monitor.
Make sure the serial monitor of Arduino is well set to "Carriage Return"
Enter 'on' turns on the LED connected to pin 13.
Enter 'off' turns off the LED connected to pin 13.
This provides an alternative to Bitlash.
The circuit:
The Pin 13 is connected to a 220-ohm resistor, which is then
connected to a LED and then to ground (GND). As an alternative,
you can watch the LED "L" visible on the Arduino board and
already connected to pin 13.
Created on July 21, 2010 by Mark Aosawa. mark.aosawa @ yahoo.com
Deeply modified April 7, 2012 by C. Hobby, info@mchobby.be
* /
/ / String buffer / buffer
String cmd = String ("");
/ / Initialize the LED pin 13 as output (OUTPUT)
int ledPin = 13;
void setup () {
/ / Initialize the serial communication (baud rate and 9600):
Serial.begin (9600);
pinMode (ledPin, OUTPUT);
/ / Displays a message when the serial port is open.
/ / Ensures that the program is running short
Serial.println ("Serial communication is ready.");
}
void loop () {
/ / Check if characters are received on the serial port
if (Serial.available ()> 0) {
/ / Temporary variable to copy the character read
SerialInByte char;
/ / Read a character (byte)
SerialInByte Serial.read = ();
/ / If this is <CR> -> process the order
if (SerialInByte == 13) {
ProcessCmd ();
Else {}
/ / Otherwise, add the character to the buffer (cmd)
cmd + = String (SerialInByte);
/ / Display a message and debug
Serial.print ("SerialInByte:");
Serial.print (SerialInByte, DEC);
Serial.print ("Buffer");
Serial.println (cmd);
}
}
}
/ / Return the control (buffer contents) to the serial port
printCmd void () {
Serial.println (cmd);
}
/ / Reset the buffer (and empty the serial port)
clearCmd void () {
cmd = "";
Serial.flush ();
}
/ / Interpret the command received
/ /
ProcessCmd void () {
/ / A small debug message. The command is surrounded with [] to clear
/ / Identify each of the characters that compose (even spaces).
Serial.print ("ProcessCmd for [");
Serial.print (cmd);
Serial.println ("]");
if (cmd.equals ("on")) {
printCmd ();
digitalWrite (ledPin, HIGH);
clearCmd ();
} Else if (cmd.equals ("off")) {
printCmd ();
digitalWrite (ledPin, LOW);
clearCmd ();
Else {}
/ / All other commands are ignored.
Serial.println ("unknown command");
clearCmd ();
}
}
I did change all of the comment marks to eliminate the spaces, error count drops to the below.
Errors with corrected comment marks:
sketch_feb22a:24: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:25: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:26: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a.ino: In function 'void loop()':
sketch_feb22a:42: error: 'SerialInByte' was not declared in this scope
sketch_feb22a:42: error: expected ;' before 'char' sketch_feb22a:44: error: expected ;' before 'Serial'
sketch_feb22a:48: error: 'ProcessCmd' was not declared in this scope
sketch_feb22a:49: error: 'Else' was not declared in this scope
sketch_feb22a:49: error: expected `;' before '{' token
sketch_feb22a:51: error: expected primary-expression before '=' token
sketch_feb22a.ino: At global scope:
sketch_feb22a:63: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:68: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:75: error: expected constructor, destructor, or type conversion before 'void'
Updated code:
/* Command String In String using Serial Port
The program waits for a command arrives on the serial monitor.
Make sure the serial monitor of Arduino is well set to "Carriage Return"
Enter 'on' turns on the LED connected to pin 13.
Enter 'off' turns off the LED connected to pin 13.
This provides an alternative to Bitlash.
The circuit:
The Pin 13 is connected to a 220-ohm resistor, which is then
connected to a LED and then to ground (GND). As an alternative,
you can watch the LED "L" visible on the Arduino board and
already connected to pin 13.
Created on July 21, 2010 by Mark Aosawa. mark.aosawa @ yahoo.com
Deeply modified April 7, 2012 by C. Hobby, info@mchobby.be
*/
// String buffer / buffer
String cmd = String ("");
// Initialize the LED pin 13 as output (OUTPUT)
int ledPin = 13;
void setup () {
// Initialize the serial communication (baud rate and 9600):
Serial.begin (9600);
pinMode (ledPin, OUTPUT);
// Displays a message when the serial port is open.
// Ensures that the program is running short
Serial.println ("Serial communication is ready.");
}
void loop () {
// Check if characters are received on the serial port
if (Serial.available ()> 0) {
// Temporary variable to copy the character read
SerialInByte char;
// Read a character (byte)
SerialInByte Serial.read = ();
// If this is <CR> -> process the order
if (SerialInByte == 13) {
ProcessCmd ();
Else {}
// Otherwise, add the character to the buffer (cmd)
cmd + = String (SerialInByte);
// Display a message and debug
Serial.print ("SerialInByte:");
Serial.print (SerialInByte, DEC);
Serial.print ("Buffer");
Serial.println (cmd);
}
}
}
// Return the control (buffer contents) to the serial port
printCmd void () {
Serial.println (cmd);
}
// Reset the buffer (and empty the serial port)
clearCmd void () {
cmd = "";
Serial.flush ();
}
// Interpret the command received
//
ProcessCmd void () {
// A small debug message. The command is surrounded with [] to clear
// Identify each of the characters that compose (even spaces).
Serial.print ("ProcessCmd for [");
Serial.print (cmd);
Serial.println ("]");
if (cmd.equals ("on")) {
printCmd ();
digitalWrite (ledPin, HIGH);
clearCmd ();
} Else if (cmd.equals ("off")) {
printCmd ();
digitalWrite (ledPin, LOW);
clearCmd ();
Else {}
// All other commands are ignored.
Serial.println ("unknown command");
clearCmd ();
}
}
Ashton:
I did change all of the comment marks to eliminate the spaces, but my error count goes to 26.
Errors with corrected comment marks:
sketch_feb22a:26: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:27: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:28: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a.ino: In function 'void loop()':
sketch_feb22a:44: error: 'SerialInByte' was not declared in this scope
sketch_feb22a:44: error: expected ;' before 'char' sketch_feb22a:46: error: expected ;' before 'Serial'
sketch_feb22a:50: error: 'ProcessCmd' was not declared in this scope
sketch_feb22a:51: error: 'Else' was not declared in this scope
sketch_feb22a:51: error: expected `;' before '{' token
sketch_feb22a:53: error: expected primary-expression before '=' token
sketch_feb22a.ino: At global scope:
sketch_feb22a:65: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:70: error: expected constructor, destructor, or type conversion before 'void'
sketch_feb22a:77: error: expected constructor, destructor, or type conversion before 'void'
Yet, you're not going to give us the updated code?