Zdravím všechny odborníky, začínám s arduinem, vlastním klon MEGA a potřeboval bych dálkově ovládat několik serv pokaždé jiným tlačítkem- zatím stačí 4 serva.
Zkoušel jsem najít na webu, ale stále mi to nefunguje, funguje mi jen 1 servo a ostatní nemohu přidat, tak aby mi to fungovalo.
Zde mám na jedno servo, můžete mi někdo zkušenější poradit nebo odkázat na nějakou stránku, předem všem děkuji.
#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0xFF6897   //clockwise rotation button
#define minus 0xFF9867  //counter clockwise rotation button
int RECV_PIN = 19;       //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 == plus)
    {
      cwRotation = !cwRotation;      //toggle the rotation value
      ccwRotation = false;         //no rotation in this direction
    }
    if (results.value == minus)
    {
      ccwRotation = !ccwRotation;   //toggle the rotation value
      cwRotation = false;            //no rotation in this direction
    }
  }
  if (cwRotation && (val != 35))  {
    val++;                         //for colockwise button
  }
  if (ccwRotation && (val != 0))  {
    val–;                         //for counter colockwise button
  }
  servo.write(val);
  delay(2);          //General speed
}