-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
23 lines (20 loc) · 797 Bytes
/
code.c
File metadata and controls
23 lines (20 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <Servo.h> //INCLUSÃO DA BIBLIOTECA NECESSÁRIA
#define pinoServo 10 //PINO DIGITAL UTILIZADO PELO SERVO
Servo s; //OBJETO DO TIPO SERVO
int pos; //POSIÇÃO DO SERVO
void setup (){
s.attach(pinoServo); //ASSOCIAÇÃO DO PINO DIGITAL AO OBJETO DO TIPO SERVO
s.write(0); //INICIA O MOTOR NA POSIÇÃO 0º
}
void loop(){
for(pos = 0; pos < 180; pos++){ //PARA "pos" IGUAL A 0, ENQUANTO "pos" MENOR QUE 180, INCREMENTA "pos"
s.write(pos); //ESCREVE O VALOR DA POSIÇÃO QUE O SERVO DEVE GIRAR
delay(5);
}
delay(2000); //INTERVALO DE 2 SEGUNDO
for(pos = 180; pos >= 0; pos--){ //PARA "pos" IGUAL A 180, ENQUANTO "pos" MAIOR OU IGUAL QUE 0, DECREMENTA "pos"
s.write(pos); //ESCREVE O VALOR DA POSIÇÃO QUE O SERVO DEVE GIRAR
delay(5);
}
delay(2000);
}