1. #include "serial.h"
  2.  
  3. void execute_function()
  4. {
  5. int data = Serial.read();
  6. int param1, param2;
  7. Serial.println(data);
  8.  
  9. if(data >= SET_SERVO_POS) //This means we have parameters
  10. {
  11. param1 = Serial.read();
  12. param2 = Serial.read();
  13. Serial.println(param1);
  14. Serial.println(param2);
  15. }
  16.  
  17. //command is stored in first position of the array
  18. switch(data)
  19. {
  20. //parameterless functions
  21. case LED_ON:
  22. led_on(); break;
  23. case LED_OFF:
  24. led_off(); break;
  25.  
  26. case LIFT_CANS:
  27. liftCans(); break;
  28. case GRAB_FIRST:
  29. grabFirst(); break;
  30. case SCORE:
  31. scoreCans(); break;
  32. case CLOSEWINGS:
  33. closeWings(); break;
  34. case OPENWINGS:
  35. openWings(); break;
  36. case REVERSE:
  37. reverse(); break;
  38.  
  39. //two-parameter functions
  40. case SET_SERVO_POS:
  41. set_servo_position(param1, param2);
  42. break;
  43.  
  44. //functions with return values
  45. case ISCAN:
  46. Serial.write(isCan()); break;
  47. case ISBUTTON:
  48. Serial.println("Trying to return button");
  49. Serial.write(isButton());
  50.  
  51. break;
  52. default:
  53. Serial.println("CMD UNRECOGNIZED: ");
  54. Serial.println(data);
  55. // Command was not recognized
  56. break;
  57. }
  58. }