Pages: [1]   Go Down
Author Topic: #define not working within switch case?  (Read 746 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if I put:

Code:
#define outOne 10
#define on 11

and then later on write:

Code:
switch(client.read()){
              case '1':
                Serial.write(outOne);
                Serial.write(on);

i get this error:

Code:
Temperature:101: error: expected primary-expression before '=' token

What am I doing wrong?

I know it is that line of code because if I change the "outOne" to the number 10 it works fine.
Logged

Arduino Uno;
Mega328

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

The problem is somewhere else, so post your code.

You'd see that error if you said
Code:
#define outOne = 10
for example
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would look around line 101.  (line numbers are shown in the lower left hand corner of the ide).
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops......I was programming last night and when I set up all of my #define's I did have an "=" in there.  Works now and I need to work on my attention to detail :-)
Logged

Arduino Uno;
Mega328

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8933
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops......I was programming last night and when I set up all of my #define's I did have an "=" in there.  Works now and I need to work on my attention to detail :-)

Better yet, change your programming style:
Code:
const int outOne = 10;
const int on = 11;

This gives the compiler more information and lets it do more syntax checking for you.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Sr. Member
****
Karma: 4
Posts: 289
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops......I was programming last night and when I set up all of my #define's I did have an "=" in there.  Works now and I need to work on my attention to detail :-)

Better yet, change your programming style:
Code:
const int outOne = 10;
const int on = 11;

This gives the compiler more information and lets it do more syntax checking for you.

Thanks!  I will remember that and use it in my sketch.  I mainly just need to be able to keep the commands straight across multiple sketches because the commands will be sent from one arduino over bluetooth to be received by another arduino.  I was having trouble keeping things straight across my different sketches.
Logged

Arduino Uno;
Mega328

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8933
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I mainly just need to be able to keep the commands straight across multiple sketches because the commands will be sent from one arduino over bluetooth to be received by another arduino.  I was having trouble keeping things straight across my different sketches.

One thing you can do it encapsulate the parts that are common to both sketches into a library.  You can call it something like "MyProtocol".  You would put MyProtocol.h into a MyProtocol directory inside a 'libraries' directory in your sketch folder.  Then you can #include "MyProtocol" in both sketches and anything you define in the .h file will be common to both.

If there are functions or objects common to both you can put them in MyProtocol.cpp in the same MyProtocol directory.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: