Stap 7: Montage en programmering van de controller
#include < Servo.h > / / incluindo een bibliotheek dos servo's
Servo SRx;
Servo SRy;
Const int VRx = A0;
Const int VRy = a1 worden verkregen;
int sensorVRx = 0;
int sensorVRy = 0;
int outputVRx = 0;
int outputVRy = 0;
lange tempo_anterior = 0;
lange intervalo = 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 = kaart (sensorVRx, 0, 1023, 0, 180);
outputVRy = kaart (sensorVRy, 0, 1023, 0, 180);
Als (tempo_atual - tempo_anterior > intervalo) / / se o tempo atual menos o tempo anterior voor 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);
}
Waarop wordt uitgevoerd: