Pages: [1]   Go Down
Author Topic: simplest way to "route" messages  (Read 300 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am sending values over serial from max.  I have single chars being handled with if/else statements in arduino.  What I want is a simple messaging/labeling system.  I am aware of the many libraries that do this and much much more for me.  But I just want to know the code of how to do it without an external library, as I am still trying to learn the basics here.  Thanks for the help.

from max these are some example messages
a222
z235
s124

I would like to:
 "if the first char is a then set the value[a] to 222"
if the first char is z then set the value of [z] to 235

etc.

How would I go about achieving this.  To let you know where I am coming from attached is the static version I have running:


   if (Serial.available() > 0){         // Check serial buffer for characters
    char ch = Serial.read();
//Serial.println ('ch');

      if (ch == 'a') {       // If an 'r' is received then run the motor
 dc1.setSpeed (250);    // This is where I would like the value 250 instead to come from a longer input message ie. a250
 dc1.run(FORWARD);      // turn it on going forward
// Serial.println ("Moter one triggered!");
  }
      else if (ch == 'z') {       // If an 's' is received then stop the motor
 dc1.setSpeed (0); 
 dc1.run(RELEASE);      // turn it off
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
"if the first char is a then set the value[a] to 222"     
If you subtract 'a' from the label, you'll get a simple index zero to twenty five.
Logged

Per Arduino ad Astra

Pages: [1]   Go Up
Jump to: