Created
April 3, 2015 23:48
-
-
Save rockos/991ecb49e319610eb886 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> | |
Servo srv; | |
int deg = 0; | |
int save_deg = 0; | |
void setup() | |
{ | |
srv.attach(8); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) { | |
delay(15); | |
deg = readData(); | |
srv.write(deg); | |
} | |
if (save_deg != deg){ | |
Serial.print("degree is "); | |
Serial.println(deg); | |
} | |
save_deg = deg; | |
} | |
#define MAX_DIGIT 3 | |
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