Compiling error: error: stray '\' in program

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

// 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 () ;
 }

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

What's the gt= ...?

if (greenLEDState == LOW)
 greenLEDState = HIGH ;
 else
 greenLEDState = LOW ;

would be only one line of code as

 greenLEDState = !greenLEDState;

Your long minuses, -, are becoming unicode and breaking stuff. Replace them with a normal dash/minus. This is what the compiler sees:

#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 () ;
 }

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

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.

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

but how on earth did they wind up in a program

Probably cut-and-pasted from a web site.

Thanks guys, i got it to compile.

Arduino: 1.5.6-r2 (Windows XP), Board: "Arduino Uno"

_2014:29: error: stray '\' in program _2014:24: error: expected initializer before 'code_table' _2014.ino: In function 'void send(unsigned char)': _2014:29: error: expected initializer before 'uff0ctemp' _2014:30: error: 'i' was not declared in this scope _2014:32: error: 'P2' was not declared in this scope _2014:32: error: expected primary-expression before '=' token _2014:33: error: 'temp' was not declared in this scope _2014:35: error: expected primary-expression before '=' token _2014:36: error: 'else' without a previous 'if' _2014:37: error: expected primary-expression before '=' token _2014:39: error: expected primary-expression before '=' token _2014.ino: In function 'void MAX7219_Write(unsigned char, unsigned char)': _2014:45: error: 'P2' was not declared in this scope _2014:45: error: expected primary-expression before '=' token _2014:48: error: expected primary-expression before '=' token _2014.ino: In function 'void MAX7219_Write_1(unsigned char, unsigned char)': _2014:53: error: 'P2' was not declared in this scope _2014:53: error: expected primary-expression before '=' token _2014:54: error: 'sent' was not declared in this scope _2014:56: error: expected primary-expression before '=' token _2014:59: error: expected primary-expression before '=' token _2014.ino: In function 'void MAX7219_Init()': _2014:113: error: 'P2' was not declared in this scope _2014:113: error: expected primary-expression before '=' token _2014:114: error: expected primary-expression before '=' token _2014:115: error: expected primary-expression before '=' token

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.

I don't know how to fix it. Please help me !!!!`

I don't know how to fix it.

What is the "it" you cannot fix?

void send (uchar datain)
{
char I?temp;
for (i=8; i>0; i–)
{
CLK=0;
temp=datain&0x80;
if (temp==0x80)
DATA=1;
else
DATA=0;
datain<<=1;
CLK=1;
}
}

void MAX7219_Write (uchar add1, uchar dat1)
{
CS=0;
send(add1);
send(dat1);
CS=1;

void MAX7219_Write_1(uchar add2,uchar dat2)
{
CS=0;
sent(add2);
sent(dat2);
CLK=1;
sent(REG_NO_OP);
sent(0x00);
CS=1;
}

Whee is "setup()"? Where is "loop()"? Where are the code tags?

#define uchar unsigned char

#define REG_NO_OP 0x00 // ??? register
#define DIG_1 0x01 // ???1 register
#define DIG_2 0x02 // ???2 register
#define DIG_3 0x03 // ???3 register
#define DIG_4 0x04 // ???4 register
#define DIG_5 0x05 // ???5 register
#define DIG_6 0x06 // ???6 register
#define DIG_7 0x07 // ???7 register
#define DIG_8 0x08 // ???8 register
#define REG_DECODE 0x09 // ??? register
#define REG_INTENSITY 0x0a // ??? register
#define REG_SCAN_LIMIT 0x0b // ??? register
#define REG_SHUTDOWN 0x0c // ??“shutdown”?? register
#define REG_DISPLAY_TEST 0x0f // ??“display test”?? register
#define INTENSITY_MIN 0x00 // ???
#define INTENSITY_MAX 0x0f // ???

#define DATA P2^3; //??P3_5??MAX7219 DATA??
#define CLK P2^5; //??P3_4??MAX7219 CLK ??
#define CS P2^4; //??P3_3??MAX7219 CS ??

uchar code code_table[10]=
{0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b};

void send (uchar datain)
{
char I?temp;
for (i=8; i>0; i–)
{
CLK=0; // CLK ??
temp=datain&0x80;
if (temp==0x80) // ???
DATA=1; // ??“1”
else // ?
DATA=0; // ??“0”
datain<<=1; //datain???0x80???
CLK=1; // CLK ??
}
}

void MAX7219_Write (uchar add1, uchar dat1) //???MAX7219???
{
CS=0; // CS??? MAX7219
send(add1); // ?register number ? MAX7219
send(dat1); // ? data ? MAX7219
CS=1; // ??CS???16???
}

void MAX7219_Write_1(uchar add2,uchar dat2) //???MAX7219???
{
CS=0;
sent(add2);
sent(dat2);
CLK=1; // ?16.5???MAX7219?DOUT???
sent(REG_NO_OP); //???MAX7219???
sent(0x00);
CS=1;
}

void MAX7219_DisplayChar (char digit, char character)
{ MAX7219_Write(digit, character);
}

void MAX7219_Clear ()
{
uchar i;
for (i=0; i < 8; i++)
MAX7219_Write(i, 0x00); // ???MAX7219???
}

void MAX7219_Clear_1()
{
uchar i;
for(i=1;i<=8;i++)
MAX7219_Write_1(i,0x00); //???MAX7219???
}

void MAX7219_SetBrightness (char brightness)
{
brightness &= 0x0f; // ???
MAX7219_Write(REG_INTENSITY, brightness); // ???
MAX7219_Write_1(REG_INTENSITY, brightness); //???MAX7219
}

void MAX7219_DisplayTestStart ()
{
MAX7219_Write(REG_DISPLAY_TEST, 1); //?MAX7219? test ??
MAX7219_Write_1(REG_DISPLAY_TEST, 1); //???MAX7219
}

void MAX7219_DisplayTestStop ()
{
MAX7219_Write(REG_DISPLAY_TEST, 0); //? MAX7219???
MAX7219_Write_1(REG_DISPLAY_TEST, 0); //???MAX7219
}

void MAX7219_ShutdownStart ()
{
MAX7219_Write(REG_SHUTDOWN, 0); //?MAX7219? shutdown ??
MAX7219_Write_1(REG_SHUTDOWN, 0); //???MAX7219
}

void MAX7219_ShutdownStop ()
{
MAX7219_Write(REG_SHUTDOWN, 1); //?MAX7219???
MAX7219_Write_1(REG_SHUTDOWN, 1); //???MAX7219
}

void MAX7219_Init ()
{
DATA=1; // ?DATA?1
CLK=1; // ?CLK ?1
CS=1; // ?CS ?1
MAX7219_Write(REG_SCAN_LIMIT, 7); // ???
MAX7219_Write_1(REG_SCAN_LIMIT, 7); //???MAX7219
MAX7219_Write(REG_DECODE, 0x00); // ???
MAX7219_Write_1(REG_DECODE, 0x00); //???MAX7219
MAX7219_ShutdownStop(); //?MAX7219??? (?shutdown??)
MAX7219_DisplayTestStop(); // ?MAX7219??? (?test??)
MAX7219_Clear(); // ???
MAX7219_Clear_1(); //???MAX7219
MAX7219_SetBrightness(INTENSITY_MAX); // ???
}

do not need to care about the chinese!!!thx

I don't care about the Chinese, I do care about the missing code tags.

char I?temp;

That ain't no comma.

#define DATA P2^3;

Two things wrong here - what is P2, and what is that semicolon doing there?

Arduino: 1.5.6-r2 (Windows XP), Board: "Arduino Uno"

_2014:29: error: stray '\' in program _2014:24: error: expected initializer before 'code_table' _2014.ino: In function 'void send(unsigned char)': _2014:29: error: expected unqualified-id before '=' token _2014:30: error: 'i' was not declared in this scope _2014:32: error: 'P2' was not declared in this scope _2014:32: error: expected primary-expression before '=' token _2014:33: error: 'temp' was not declared in this scope _2014:35: error: expected primary-expression before '=' token _2014:36: error: 'else' without a previous 'if' _2014:37: error: expected primary-expression before '=' token _2014:39: error: expected primary-expression before '=' token _2014.ino: In function 'void MAX7219_Write(unsigned char, unsigned char)': _2014:45: error: 'P2' was not declared in this scope _2014:45: error: expected primary-expression before '=' token _2014:48: error: expected primary-expression before '=' token _2014.ino: In function 'void MAX7219_Write_1(unsigned char, unsigned char)': _2014:53: error: 'P2' was not declared in this scope _2014:53: error: expected primary-expression before '=' token _2014:54: error: 'sent' was not declared in this scope _2014:56: error: expected primary-expression before '=' token _2014:59: error: expected primary-expression before '=' token _2014.ino: In function 'void MAX7219_Init()': _2014:113: error: 'P2' was not declared in this scope _2014:113: error: expected primary-expression before '=' token _2014:114: error: expected primary-expression before '=' token _2014:115: error: expected primary-expression before '=' token

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.

Yes, you've shown us the error messages, but where is the corrected code (inside code tags this time) ?

no,I don't know the correct answer

No, me neither. Good luck.

thank you for your teaching,good night