Etape 7: Montage et programmation du contrôleur
#include < Servo.h > / / incluindo une biblioteca servos dos
Servo SRx ;
SRy servo ;
const int VRx = A0 ;
const int VRy = A1 ;
int sensorVRx = 0 ;
int sensorVRy = 0 ;
int outputVRx = 0 ;
int outputVRy = 0 ;
long tempo_anterior = 0 ;
intervalo long = 100 ; milisegundos
unsigned long tempo_atual ;
void setup()
{
Serial.Begin(9600) ;
SRx.attach(9) ;
SRy.attach(10) ;
}
void loop()
{
tempo_atual = millis(); / / o tempo atual é igual ao tempo de funcionamento do uC
sensorVRx = analogRead(VRx) ;
sensorVRy = analogRead(VRy) ;
outputVRx = carte (sensorVRx, 0, 1023, 0, 180) ;
outputVRy = carte (sensorVRy, 0, 1023, 0, 180) ;
Si (tempo_atual - tempo_anterior > intervalo) / / se o tempo atual menos o tempo antérieure pour maior que o intervalo com que eu quero fazer minha acao
{
tempo_anterior = tempo_atual ; //tempo anterior recebe o tempo atual
Serial.Print(outputVRx) ;
Serial.Print(",") ;
Serial.Print(outputVRy) ;
Serial.Print(",") ;
Serial.println("") ;
}
SRx.write(outputVRx) ;
SRy.write(outputVRy) ;
Delay(2) ;
}
En cours d’exécution :