#include <IRremote.h>
#include <Servo.h>
#include <LedControl.h>
const int DIN = 11;
const int CS = 10;
const int CLK = 13;
LedControl lc = LedControl(DIN, CLK, CS, 1);
Servo motor;
IRrecv sensor(7);
decode_results boton;
int angulo=90;
void setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
motor.attach(9);
Serial.begin(9600);
sensor.enableIRIn();
pinMode(5, OUTPUT);
pinMode(3,OUTPUT);
}
void loop() {
if (sensor.decode()) {
translateIR();
sensor.resume();
Serial.println(sensor.decodedIRData.command);
}
}
void translateIR(){
switch (sensor.decodedIRData.command) {
case 144:
digitalWrite(3, HIGH);
delay(25);
break;
case 224:
digitalWrite(3, LOW);
delay(25);
break;
case 2:
angulo +=3;
motor.write(angulo);
delay(20);
break;
case 152:
angulo -=3;
motor.write(angulo);
delay(20);
break;
case 48:
flecha();
delay(15);
break;
case 24:
Caritafeliz();
delay(15);
break;
case 122:
flecha2();
delay(20);
break;
}
}
void flecha() {
lc.clearDisplay(0); //Flecha
lc.setRow(0,0,B00011000);
lc.setRow(0,1,B00110000);
lc.setRow(0,2,B01100000);
lc.setRow(0,3,B11111111);
lc.setRow(0,4,B11111111);
lc.setRow(0,5,B01100000);
lc.setRow(0,6,B00110000);
lc.setRow(0,7,B00011000);
}
void Caritafeliz() {
lc.clearDisplay(0); //Carita feliz
lc.setRow(0,0,B00001000);
lc.setRow(0,1,B00000100);
lc.setRow(0,2,B01100010);
lc.setRow(0,3,B00000010);
lc.setRow(0,4,B01100010);
lc.setRow(0,5,B00000010);
lc.setRow(0,6,B00000100);
lc.setRow(0,7,B00001000);
}
void flecha2(){
lc.clearDisplay(0); //Flecha
lc.setRow(0,0,B00011000);
lc.setRow(0,1,B00001100);
lc.setRow(0,2,B00000110);
lc.setRow(0,3,B11111111);
lc.setRow(0,4,B11111111);
lc.setRow(0,5,B00000110);
lc.setRow(0,6,B00001100);
lc.setRow(0,7,B00011000);
}