Go Down

Topic: simplest way to "route" messages (Read 443 times) previous topic - next topic

Christopher Overstreet

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

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


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


Code: [Select]
"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.
Per Arduino ad Astra

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131