2021 기업연계프로젝트_컴퓨터소프트웨어공학 2조 팀 Sper
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.

49 lines
880 B

  1. #include<SoftwareSerial.h>
  2. #include<Servo.h>
  3. SoftwareSerial xbee(2,3);
  4. #define LEN 13
  5. #define servoPin 9
  6. int count = 0, flag = 1, angle = 0, a = 1;
  7. Servo myservo;
  8. void setup() {
  9. Serial.begin(9600);
  10. xbee.begin(9600);
  11. myservo.attach(servoPin);
  12. myservo.write(0);
  13. }
  14. void loop() {
  15. char arr[LEN] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'o', 'x'};
  16. char ch = xbee.read();
  17. for(int i = 0; i < LEN; i++){
  18. if(ch == '*') count++;
  19. else if(count >= 3 && ch == '!'){
  20. count = 0;
  21. Serial.println();
  22. }
  23. else if(count >= 3 && ch == arr[i]){
  24. if(ch == 'x'){
  25. flag = 0;
  26. }
  27. else if(ch == 'o'){
  28. flag = 1;
  29. }
  30. Serial.write(ch);
  31. }
  32. }
  33. if(flag == 1){
  34. if(angle == 180){
  35. a = -10;
  36. }else if(angle == 0){
  37. a = 10;
  38. }
  39. angle += a;
  40. myservo.write(angle);
  41. delay(10);
  42. }
  43. }