Go Down

Topic: Compiling error: error: stray '\' in program (Read 11550 times) previous topic - next topic

codlink

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

Code: [Select]
// 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 () ;
}
//LiNK

majenko

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


What's the gt= ...?

PaulS

Code: [Select]
if (greenLEDState == LOW)
greenLEDState = HIGH ;
else
greenLEDState = LOW ;

would be only one line of code as
Code: [Select]
greenLEDState = !greenLEDState;

WizenedEE

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

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



Graynomad

#4
Jun 12, 2012, 01:28 am Last Edit: Jun 12, 2012, 01:33 am by Graynomad Reason: 1
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
Rob Gray aka the GRAYnomad www.robgray.com

majenko

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.

Graynomad

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
Rob Gray aka the GRAYnomad www.robgray.com

PaulS

Quote
but how on earth did they wind up in a program

Probably cut-and-pasted from a web site.

codlink

#8
Jun 12, 2012, 02:43 am Last Edit: Jun 12, 2012, 02:53 am by codlink Reason: 1
Thanks guys, i got it to compile.
//LiNK

DT1234

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 !!!!`

AWOL

Quote
I don't know how to fix it.

What is the "it" you cannot fix?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DT1234

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;
  }

AWOL

Whee is "setup()"?
Where is "loop()"?
Where are the code tags?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

DT1234

#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

AWOL

#14
Apr 17, 2014, 08:57 am Last Edit: Apr 17, 2014, 09:03 am by AWOL Reason: 1
I don't care about the Chinese, I do care about the missing code tags.

Code: [Select]
char I?temp;
That ain't no comma.

Code: [Select]
#define DATA P2^3;
Two things wrong here - what is P2, and what is that semicolon doing there?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up