Senhores, estou com a seguinte dificuldade...
Não estou conseguindo implementar 3 servomotores no codigo, consegui apenas 1.
A proposta é o seguinte.
Servomotor 1 é para movimentar (direita e esquerda) com o sinal Ir do controle de codigos: E17AD827 e E17A38C7; (LIGADO NO PIN DIG 9)
Servomotor 2, movimentar direita e esquerda com os codigos: E17AD02F e E17A30CF; (LIGADO NO PIN DIG 10)
E servomotor 3, movimentar direita e esquerda com os codigos: E17AE817 e E17A6897. (LIGADO NO PIN DIG 11)
Consegui fazer somente um servomotor funcionar, não consegui "replicar" o codigo para os outros servomotores.
Segue o codigo que tive sucesso ligando apenas 1 servomotor.
#include <IRremote.h> //must copy IRremote library to arduino libraries
#include <Servo.h>
#define left 0xE17AD827 //clockwise rotation button
#define right 0xE17A38C7 //counter clockwise rotation button
int RECV_PIN = 2; //IR receiver pin
Servo servo;
int val; //rotation angle
bool cwRotation, ccwRotation; //the states of rotation
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
servo.attach(9); //servo pin
}
void loop()
{
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
if (results.value == left)
{
cwRotation = !cwRotation; //toggle the rotation value
ccwRotation = false; //no rotation in this direction
}
if (results.value == right)
{
ccwRotation = !ccwRotation; //toggle the rotation value
cwRotation = false; //no rotation in this direction
}
}
if (cwRotation && (val != 175)) {
val++; //for colockwise button
}
if (ccwRotation && (val != 0)) {
val--; //for counter colockwise button
}
servo.write(val);
delay(20); //General speed
}
Tags:
LC, bom dia.
Qual arduino você está usando e quais ports pretende usar para os outros 2 motores?
Rui
Ola Rui,
então uso arduino Uno R3,
os ports são os pinos digitais 9, 10 e 11.
Oi LS,
acrescentei dados no seu code para um segundo motor.
Teste e veja se funciona.
Se funcionar entenda como eu fiz e acrescente o 3o.
Boas sorte
Rui
Obrigado pela ajuda RUI, consegui fazer funcionar.
Boa tarde amigo LS, então como a proposta eh triplicar fiz o code, fiz o mesmo seguindo o modelo base do seu exemplo mais as conf que pediu para que possa ficar bem compreensível ao estudo, não tenho a biblioteca do IRreceiver aqui por isso nao compilei para testar em fim qualquer duvida nao deixa de atualizar o tópico, bons projetos!
Romario, obrigado pela ajuda! Deu certinho com o codigo!!
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por