servobasic.c
/*----------------------------------------------------- Author: --<Leonardo Yamasaki> Date: 2016-03-15 Description: Test servo manual -----------------------------------------------------*/ #define SERVMIN 800 #define SERVMID 2000 #define SERVMAX 3150 #define SERVOPORT 7 int i; int s; void servo(int s,int i); void setup() { pinMode(SERVOPORT,OUTPUT); } void loop() { for(i=SERVMIN;i<SERVMAX;i=i+10) servo(SERVOPORT,i); for(i=SERVMAX;i>SERVMIN;i=i-10) servo(SERVOPORT,i); /* for(i=0;i<200;i++) servmin(); delay(100); for(i=0;i<200;i++) servmid(); delay(100); for(i=0;i<200;i++) servmax(); delay(100); for(i=0;i<200;i++) servmid(); delay(100); */ } void servo(int s,int i){ digitalWrite(s,LOW); delay(10); digitalWrite(s,HIGH); delayMicroseconds(i); digitalWrite(s,LOW); } void servmin(){ digitalWrite(SERVOPORT,LOW); delay(10); digitalWrite(SERVOPORT,HIGH); delayMicroseconds(SERVMIN); digitalWrite(SERVOPORT,LOW); } void servmax(){ digitalWrite(SERVOPORT,LOW); delay(10); digitalWrite(SERVOPORT,HIGH); delayMicroseconds(SERVMAX); digitalWrite(SERVOPORT,LOW); } void servmid(){ digitalWrite(SERVOPORT,LOW); delay(10); digitalWrite(SERVOPORT,HIGH); delayMicroseconds(SERVMID); digitalWrite(SERVOPORT,LOW); }