Loading...
Pages: [1]   Go Down
Author Topic: #define not working within switch case?  (Read 337 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 2
Posts: 237
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

Online Online
Edison Member
*
Karma: 16
Posts: 1035
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

Austin, TX
Offline Offline
Faraday Member
**
Karma: 42
Posts: 5242
CMiYC
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

www.cmiyc.com - A guide to being an Enginerd

0
Offline Offline
Full Member
***
Karma: 2
Posts: 237
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: 108
Posts: 6592
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

0
Offline Offline
Full Member
***
Karma: 2
Posts: 237
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: 108
Posts: 6592
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

Pages: [1]   Go Up
Print
 
Jump to: