Pages: [1] 2   Go Down
Author Topic: Compiling error: error: stray '\' in program  (Read 8645 times)
0 Members and 1 Guest are viewing this topic.
USA, FL
Offline Offline
God Member
*****
Karma: 14
Posts: 688
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: 99
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

What's the gt= ...?
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
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: 19
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: 126
Posts: 8475
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: 99
Posts: 4153
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

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8475
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: 601
Posts: 48556
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: 688
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

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25874
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don't know how to fix it.
What is the "it" you cannot fix?
Logged

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25874
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

#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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25874
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
char I,temp;
That ain't no comma.

Code:
#define DATA P2^3;
Two things wrong here - what is P2, and what is that semicolon doing there?
« Last Edit: April 17, 2014, 02:03:28 am by AWOL » Logged

"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.

Pages: [1] 2   Go Up
Jump to: