Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: C++  |  size: 0.55 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. uint8_t index=0;
  2. char command=0;
  3. char value[4];
  4. uint8_t avalue=0;
  5.  
  6. while(index < 3){
  7.   if(Serial.available())
  8.   {
  9.     if(index==0){ // index is 0 so we are hopefully recieving a,b,c....
  10.       command = Serial.read();
  11.     }
  12.     else{ // index is more then 0, we should be recieving the value
  13.       value[index] = Serial.read();
  14.     }
  15.     index++
  16.   }
  17. }
  18. avalue = atoi(value); // convert from ascii to int
  19.  
  20. switch (command){
  21.   case a:
  22.   analogWrite(A, avalue);
  23.   break;
  24.   case b:
  25.   analogWrite(B, avalue);
  26.   //and so on
  27.  
  28. }
  29.  
  30.  
  31. index=0;