Mekanisk tjur för dockor (7 / 7 steg)
Steg 7: Montering och programmering registeransvarige
#include < Servo.h > / / incluindo en biblioteca dos servon
Servo SRx;
Servo SRy;
CONST int VRx = A0;
CONST int VRy = A1;
int sensorVRx = 0;
int sensorVRy = 0;
int outputVRx = 0;
int outputVRy = 0;
lång tempo_anterior = 0;
lång intervalo = 100; milisegundos
osignerade långa 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 gör uC
sensorVRx = analogRead(VRx);
sensorVRy = analogRead(VRy);
outputVRx = karta (sensorVRx, 0, 1023, 0, 180);
outputVRy = karta (sensorVRy, 0, 1023, 0, 180);
om (tempo_atual - tempo_anterior > intervalo) / / se o tempo atual menos o tempo främre för maior que o intervalo com que eu quero fazer minha acao
{
tempo_anterior = tempo_atual; //tempo främre recebe o tempo atual
Serial.Print(outputVRx);
Serial.Print(",");
Serial.Print(outputVRy);
Serial.Print(",");
Serial.println("");
}
SRx.write(outputVRx);
SRy.write(outputVRy);
Delay(2);
}
Kör: