#include <IRremote.h>
int ReceptorIR = 13;
const byte Led1 = 5;
const byte Led2 = 6;
const byte Led3 = 7;
const byte Led4 = 8;
const byte boton1 = 9;
const byte boton2 = 10;
const byte boton3 = 11;
const byte boton4 = 12;
IRrecv irrecv(ReceptorIR);
decode_results Codigos;
int estado = 0; // guarda el estado del boton
int estadoAnterior = 0;
int estado2 = 0; // guarda el estado del boton
int estadoAnterior2 = 0;
bool salida = false; // false = LED esta apagado, true = LED encendido
bool salida2 = false; // false = LED esta apagado, true = LED encendido
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(boton1, INPUT); // declaramos el boton1 como entrada
pinMode(boton2, INPUT); // declaramos el boton2 como entrada
pinMode(Led1, OUTPUT); // declaramos el LED1 como salida
pinMode(Led2, OUTPUT); // declaramos el LED2 como salida
}
const int tiempoAntirebote = 10; // código antirebote del boton
int cuenta = 0; // lleva la cuenta de las veces que presionamos el botón
int estadoBoton;
int estadoBotonAnterior;
boolean antirebote(int pin) {
int contador = 0;
boolean estado; // guarda el estado del botón
boolean estadoAnterior; // guarda el último estado del botón
do {
estado = digitalRead(pin);
if(estado != estadoAnterior) { // comparamos el estado actual con el anterior
contador = 0; // reiniciamos el contador
estadoAnterior = estado;
}
else {
contador = contador + 1; // sumentamos el contador en 1
}
delay(1);
} while(contador < tiempoAntirebote);
return estado;
}
void loop() {
if (irrecv.decode(&Codigos)) {
switch (Codigos.value) {
case 0xFF22DD: //codigo boton1
salida = true; //Encender Led1
break;
case 0xFFC23D: //codigo boton2
salida = false; //Apagar Led1
break;
case 0xFFE01F: //codigo boton3
salida2 = true; //Encender Led2
break;
case 0xFF906F: //codigo boton4
salida2 = false; //Apagar Led2
break;
}
irrecv.resume();
}
estado = digitalRead(boton1); // leer estado del boton
if ((estado == HIGH) && (estadoAnterior == LOW)) {
salida = !salida;
delay(40);
}
estadoAnterior = estado; //guarda el valor actual
if (salida) // si esta en alto
digitalWrite(Led1, HIGH); // encendemos el LED1
else
digitalWrite(Led1, LOW); // si no apagamos el LED1
estado2 = digitalRead(boton2); // leer estado del boton2
if ((estado2 == HIGH) && (estadoAnterior2 == LOW)) {
salida2 = !salida2;
delay(40);
}
estadoAnterior2 = estado2; //guarda el valor actual
if (salida2) // si esta en alto
digitalWrite(Led2, HIGH); // encendemos el LED2
else
digitalWrite(Led2, LOW); // si no apagamos el LED
}
y este:
int randNum = 1;
void setup() {
pinMode(2, OUTPUT); //DS (Serial data input)
pinMode(3, OUTPUT); //STCP (Storage register clock input)
pinMode(4, OUTPUT); //SHCP (Shift register clock input)
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
}
void loop() {
for (int i = 1; i <= 15; i++){//---------->
shift(1,30);
shift(2,30);
shift(4,30);
shift(8,30);
shift(16,30);
shift(32,30);
shift(64,30);
shift(128,30);
}
delay(1000);
for (int i = 1; i <= 25; i++) { //<<<<>>>>
shift(24,90);
shift(36,90);
shift(66,90);
shift(129,90);
shift(0,90);
}
delay(1000);
for (int i = 1; i <=15; i++) { //nightrider
shift(3,60);
shift(6,60);
shift(12,60);
shift(24,60);
shift(48,60);
shift(96,60);
shift(192,60);
shift(96,60);
shift(48,60);
shift(24,60);
shift(12,60);
shift(6,60);
shift(3,60);
}
delay(1000);
for (int i = 1; i <= 50; i++) { //ambulance
shift(65,250);
shift(130,250);
}
for (int i = 1; i <= 30; i++) { //blink everthing
shift(255,100);
shift(0,200);
}
delay(1000);
for (int i=1; i<= 400; i++) {
randNum = random(1, 8);
rnd(randNum);
}
}
void shift(int pin, int pindelay) {
shiftOut(2,4,MSBFIRST,pin); //shift out counter value to 74HC595
digitalWrite(3,HIGH); //shift out data from 8-bit Storage
delay(pindelay);
digitalWrite(3,LOW); //Register to 3-State Output
}
void rnd(int pin) {
switch (pin) {
case 1:
shift(1,45);
break;
case 2:
shift(2,45);
break;
case 3:
shift(4,45);
break;
case 4:
shift(8,45);
break;
case 5:
shift(16,45);
break;
case 6:
shift(32,45);
break;
case 7:
shift(64,45);
break;
case 8:
shift(128,45);
break;
}
}
Gracias