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.
|
|
#include<SoftwareSerial.h>
#include<Servo.h>
SoftwareSerial xbee(2,3);#define LEN 13
#define servoPin 9
int count = 0, flag = 1, angle = 0, a = 1;Servo myservo;
void setup() { Serial.begin(9600); xbee.begin(9600); myservo.attach(servoPin); myservo.write(0);}
void loop() { char arr[LEN] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', 'o', 'x'}; char ch = xbee.read(); for(int i = 0; i < LEN; i++){ if(ch == '*') count++; else if(count >= 3 && ch == '!'){ count = 0; Serial.println(); } else if(count >= 3 && ch == arr[i]){ if(ch == 'x'){ flag = 0; } else if(ch == 'o'){ flag = 1; } Serial.write(ch); } } if(flag == 1){ if(angle == 180){ a = -10; }else if(angle == 0){ a = 10; } angle += a; myservo.write(angle); delay(10); } }
|