Pages: [1]   Go Down
Author Topic: Compiling error: error: stray '\' in program  (Read 6336 times)
0 Members and 1 Guest are viewing this topic.
USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 686
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't see any "\" in this sketch.  But Arduino says there is.  What am I doing wrong?

Code:
// Which pins are connected to which LED
 const byte greenLED = 8 ;
 const byte redLED = 10 ;

// Time periods of blinks in milliseconds (1000 milliseconds to a second).
 // Time variable and constants are always unsigned long
 const unsigned long greenLEDinterval = 555UL;
 const unsigned long redLEDinterval = 1234UL;

// Variable holding the timer value so far. One for each “Timer”
 unsigned long greenLEDtimer = 0 ;
 unsigned long redLEDtimer = 0 ;

// Variable to know what the current LED state is
 int greenLEDState = LOW ;
 int redLEDState = LOW ;

void setup() {
 pinMode (greenLED,OUTPUT) ;
 pinMode (redLED,OUTPUT) ;
 greenLEDtimer = millis () ;
 redLEDtimer = millis () ;
 }

void loop() {

if ((millis() – greenLEDtimer) gt= greenLEDinterval) {
 if (greenLEDState == LOW)
 greenLEDState = HIGH ;
 else
 greenLEDState = LOW ;
 // Write new state
 digitalWrite (greenLED, greenLEDState ) ;
 // Reset timer
 greenLEDtimer = millis () ;
 }

// The other LED is controlled the same way. Repeat for more LEDs
if ( (millis () – redLEDtimer) gt= redLEDinterval ) {
 if (redLEDState == LOW)
 redLEDState = HIGH ;
 else
 redLEDState = LOW ;
 digitalWrite (redLED, redLEDState ) ;
 redLEDtimer = millis () ;
 }
Logged

//LiNK

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if ((millis() – greenLEDtimer) gt= greenLEDinterval) {

What's the gt= ...?
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (greenLEDState == LOW)
 greenLEDState = HIGH ;
 else
 greenLEDState = LOW ;
would be only one line of code as
Code:
greenLEDState = !greenLEDState;
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your long minuses, -, are becoming unicode and breaking stuff. Replace them with a normal dash/minus. This is what the compiler sees:
Code:
#line 1 "sketch_jun11a.ino"
// Which pins are connected to which LED
 #include "Arduino.h"
void setup();
void loop();
void loop();
#line 1
const byte greenLED = 8 ;
 const byte redLED = 10 ;

// Time periods of blinks in milliseconds (1000 milliseconds to a second).
 // Time variable and constants are always unsigned long
 const unsigned long greenLEDinterval = 555UL;
 const unsigned long redLEDinterval = 1234UL;

// Variable holding the timer value so far. One for each \u201cTimer\u201d
 unsigned long greenLEDtimer = 0 ;
 unsigned long redLEDtimer = 0 ;

// Variable to know what the current LED state is
 int greenLEDState = LOW ;
 int redLEDState = LOW ;

void setup() {
 pinMode (greenLED,OUTPUT) ;
 pinMode (redLED,OUTPUT) ;
 greenLEDtimer = millis () ;
 redLEDtimer = millis () ;
 }

void loop() {

if ((millis() \u2013 greenLEDtimer) gt= greenLEDinterval) {
 if (greenLEDState == LOW)
 greenLEDState = HIGH ;
 else
 greenLEDState = LOW ;
 // Write new state
 digitalWrite (greenLED, greenLEDState ) ;
 // Reset timer
 greenLEDtimer = millis () ;
 }

// The other LED is controlled the same way. Repeat for more LEDs
if ( (millis () \u2013 redLEDtimer) gt= redLEDinterval ) {
 if (redLEDState == LOW)
 redLEDState = HIGH ;
 else
 redLEDState = LOW ;
 digitalWrite (redLED, redLEDState ) ;
 redLEDtimer = millis () ;
 }


Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8431
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What's a "long minus" ?

(millis () – redLEDtimer)

Looks normal on my screen.

EDIT: I dropped his code into the IDE and it did break on the "long minus" (and the gt= of course), there's also a missing } at the end.

______
Rob
« Last Edit: June 11, 2012, 06:33:40 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

UK
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3969
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

In typesetting there are multiple lengths of dash used for different purposes.

The normal "hyphen" on your keyboard is used as a minus sign.

You then also have the "em dash" and the "en dash" which are both longer than a standard keyboard minus sign.

minus: -
en dash: –
em dash: —

If you use the wrong one in a program it throws a wobbly.
Logged

Why not visit my eBay shop? http://stores.ebay.co.uk/Majenko-Technologies
Replacement for the Arduino IDE: UECIDE - Proper serial terminal, graphing facilities, plugins, overhauled internals.
Java isn't bad in itself, but it has enabled morons to write programs.

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8431
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I see, I'm familiar with them because I've done a lot of desk top publishing, but how on earth did they wind up in a program, did he write it in a word processor instead of a text editor?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 547
Posts: 45982
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but how on earth did they wind up in a program
Probably cut-and-pasted from a web site.
Logged

USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 686
A life? Where can I download one of those?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks guys, i got it to compile.
« Last Edit: June 11, 2012, 07:53:25 pm by codlink » Logged

//LiNK

Pages: [1]   Go Up
Jump to: