#include <IRremote.hpp>
#include <Servo.h>
//1st Sem_Midterm Exam
//Jhomar Garnace
//BSIS - 4 - 4
//September 29, 2024
Servo myServo;
int relayPin1 = 12;
int relayPin2 = 11;
int relayPin3 = 10;
const int irReceiverPin = 13;
int x=0;
void setup() {
myServo.attach(9);
Serial.begin(9600);
IrReceiver.begin(irReceiverPin);
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
myServo.write(0);
digitalWrite(relayPin1, HIGH);
digitalWrite(relayPin2, HIGH);
digitalWrite(relayPin3, HIGH);
}
void loop() {
if (IrReceiver.decode()) {
int a = IrReceiver.decodedIRData.command;
if(a == 2){
if (x<180){
++x;
myServo.write(x);
Serial.println(x);
}
}
if(a == 152){
if (x>0){
--x;
myServo.write(x);
Serial.println(x);
}
}
if (a == 66){
digitalWrite(relayPin1, LOW);
}
if (a == 16){
digitalWrite(relayPin1, HIGH);
}
if (a == 74){
digitalWrite(relayPin2, LOW);
}
if (a == 56){
digitalWrite(relayPin2, HIGH);
}
if (a == 82){
digitalWrite(relayPin3, LOW);
}
if (a == 90){
digitalWrite(relayPin3, HIGH);
}
}
IrReceiver.resume();
}