You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
920 B

6 years ago
  1. int pins[] = {13,8,9,10,11,12};
  2. int light_pin = 0;
  3. void setup() {
  4. for(int i = 0; i<6; i++){
  5. pinMode(pins[i],OUTPUT);
  6. }
  7. }
  8. void loop() {
  9. while(Serial.read() != '/'){
  10. continue;
  11. }
  12. char prev = '!';
  13. char cur = '!';
  14. String data = "";
  15. while(Serial.read() != '/'){
  16. if(cur == '!' || prev != cur){
  17. prev = cur;
  18. data += cur;
  19. }
  20. cur = Serial.read()
  21. }
  22. for(int i = 0; i<2;i++){
  23. switch(data[i]){
  24. case "g":
  25. digitalWrite(pins[i*3],HIGH);
  26. digitalWrite(pins[(i*2)+1],LOW);
  27. digitalWrite(pins[(i*2)+2],LOW);
  28. break;
  29. case "y":
  30. digitalWrite(pins[i*3],LOW);
  31. digitalWrite(pins[(i*2)+1],HIGH);
  32. digitalWrite(pins[(i*2)+1],LOW);
  33. break;
  34. case "r":
  35. digitalWrite(pins[i*3],LOW);
  36. digitalWrite(pins[(i*2)+1],LOW);
  37. digitalWrite(pins[(i*2)+1],HIGH);
  38. break;
  39. }
  40. }
  41. }