I can't for the life of me figure out how to add another servo that is controlled independently by its own button to this code. Help would be apprenticed I am trying to be able to control 4 servos with separate buttons on the remote.
#include <IRremote.hpp>
#include <Servo.h>
#define IR_RECEIVE_PIN 4
#define SERVO_PIN 9
Servo servo;
const int range = 780;
const int mid = 1600;
int pos = 90;
int speed = 1000;
void rotate(int angle) {
angle = map(angle, 0, 180, mid - range, mid + range);
servo.writeMicroseconds(angle);
}
void setup() {
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
servo.attach(SERVO_PIN);
servo2.attach(servopin2);
rotate(pos);
}
void loop() {
if (IrReceiver.decode()) {
uint16_t command = IrReceiver.decodedIRData.command;
if (command == 2) { // NEXT
pos = min(pos + speed, 180);
} else if (command == 3) { // PREV
pos = max(pos - speed, 10);
}
rotate(pos);
IrReceiver.resume();
}
}