#define not working within switch case?

if I put:

#define outOne 10
#define on 11

and then later on write:

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

i get this error:

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.

The problem is somewhere else, so post your code.

You'd see that error if you said

#define outOne = 10

for example

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

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 :slight_smile:

jerseyguy1996:
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 :slight_smile:

Better yet, change your programming style:

const int outOne = 10;
const int on = 11;

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

johnwasser:

jerseyguy1996:
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 :slight_smile:

Better yet, change your programming style:

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.

jerseyguy1996:
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.