Created
April 4, 2015 00:06
-
-
Save rockos/716fbc6b0acd027ac9b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
#define MAX_DIGIT 3 | |
Servo u_srv; | |
Servo l_srv; | |
int deg = 0; | |
int save_deg = 0; | |
void setup() | |
{ | |
u_srv.attach(10); | |
l_srv.attach(12); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
delay(15); | |
deg = readData(); | |
l_srv.write(deg); | |
u_srv.write(deg); | |
} | |
if (save_deg != deg) { | |
Serial.print("degree is "); | |
Serial.println(deg); | |
} | |
save_deg = deg; | |
} | |
int readData() { | |
char c[MAX_DIGIT] = "0"; | |
for ( int i = 0; i < MAX_DIGIT; i++ ) { | |
c[ i ] = Serial.read(); | |
if ( c[ i ] == '\0' ) | |
break; | |
} | |
return atoi( c ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment