|
@ -11,6 +11,7 @@ Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); |
|
|
const char HEADER = 'H'; |
|
|
const char HEADER = 'H'; |
|
|
const char A_TAG = 'M'; |
|
|
const char A_TAG = 'M'; |
|
|
const char B_TAG = 'X'; |
|
|
const char B_TAG = 'X'; |
|
|
|
|
|
const char C_TAG = 'U'; |
|
|
const int TOTAL_BYTES = 10 ; // the total bytes in a message
|
|
|
const int TOTAL_BYTES = 10 ; // the total bytes in a message
|
|
|
|
|
|
|
|
|
int atomPins[] = {2,3,4,5,6,7,8,9}; |
|
|
int atomPins[] = {2,3,4,5,6,7,8,9}; |
|
@ -60,18 +61,26 @@ void loop() { |
|
|
if(Serial.available() >= TOTAL_BYTES) { |
|
|
if(Serial.available() >= TOTAL_BYTES) { |
|
|
if( Serial.read() == HEADER) { |
|
|
if( Serial.read() == HEADER) { |
|
|
char tag = Serial.read(); |
|
|
char tag = Serial.read(); |
|
|
if(tag == A_TAG) { |
|
|
|
|
|
|
|
|
if(tag == A_TAG || tag == B_TAG) { |
|
|
for(int i=0; i<8; i++) { |
|
|
for(int i=0; i<8; i++) { |
|
|
values[i] = Serial.read(); |
|
|
values[i] = Serial.read(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(tag == C_TAG) { |
|
|
|
|
|
for(int i=0; i<8; i++) { |
|
|
|
|
|
pwm.setPWM(i, 0, SERVOMAX+50); |
|
|
|
|
|
delay(100*SERVODIVIDER); |
|
|
|
|
|
pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
for(int i=0; i<8; i++) { |
|
|
for(int i=0; i<8; i++) { |
|
|
pwm.setPWM(i, 0, SERVOMIN); |
|
|
pwm.setPWM(i, 0, SERVOMIN); |
|
|
delay(values[i]*SERVODIVIDER); |
|
|
delay(values[i]*SERVODIVIDER); |
|
|
pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); |
|
|
pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(tag == A_TAG) { |
|
|
while(cycle < 8) { |
|
|
while(cycle < 8) { |
|
|
for(int i=0; i<8; i++) { |
|
|
for(int i=0; i<8; i++) { |
|
|
Serial.print(values[i]); |
|
|
Serial.print(values[i]); |
|
@ -85,11 +94,10 @@ void loop() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Serial.println(""); |
|
|
Serial.println(""); |
|
|
delay(TIMER); |
|
|
delay(TIMER); |
|
|
|
|
|
|
|
|
//digitalWrite(13, LOW);
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|