My code is by far from perfect but this is my first ever atempt at programming so please go easy (especially with the use of "delays") XD
#include <IRremote.h>
#define button1 16724175
#define button2 16718055
#define button3 16743045
#define button4 16716015
#define button5 16726215
#define button6 16734885
#define button7 16728765
#define button8 16730805
#define RECV_PIN 13
//Pin setup up the Laugh
int Laugh7 = 10;
int Fan = 15;
int delta = 100;
int Laugh[] = {4,5,6,7,8,9};
// Laugh OPEN FROM BOTTOM
int pattern1[] = {HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern2[] = {HIGH,HIGH,LOW,LOW,LOW,LOW};
int pattern3[] = {HIGH,HIGH,HIGH,LOW,LOW,LOW};
int pattern4[] = {HIGH,HIGH,HIGH,HIGH,LOW,LOW};
int pattern5[] = {HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern6[] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
// Laugh CLOSE FROM TOP
int pattern7[] = {HIGH,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern8[] = {HIGH,HIGH,HIGH,HIGH,LOW,LOW};
int pattern9[] = {HIGH,HIGH,HIGH,LOW,LOW,LOW};
int pattern10[] = {HIGH,HIGH,LOW,LOW,LOW,LOW};
int pattern11[] = {HIGH,LOW,LOW,LOW,LOW,LOW};
int pattern12[] = {LOW,LOW,LOW,LOW,LOW,LOW};
// Laugh OPEN CLOSE FROM CENTER
int pattern13[] = {LOW,LOW,LOW,LOW,LOW,LOW};
int pattern14[] = {LOW,LOW,HIGH,HIGH,LOW,LOW};
int pattern15[] = {LOW,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern16[] = {HIGH,HIGH,HIGH,HIGH,HIGH,HIGH};
int pattern17[] = {LOW,HIGH,HIGH,HIGH,HIGH,LOW};
int pattern18[] = {LOW,LOW,HIGH,HIGH,LOW,LOW};
int pattern19[] = {LOW,LOW,LOW,LOW,LOW,LOW};
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 200; // interval at which to blink (milliseconds)
int times ;
IRrecv irrecv(RECV_PIN);
decode_results results;
long lReceived = 0 ;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
//Set each pin connected to an LED to output mode (pulling high (on) or low (off)
for(int i = 0; i < 6; i++)
{
pinMode(Laugh[i],OUTPUT);
pinMode(Laugh7,OUTPUT);
pinMode(Fan,OUTPUT);
}
}
void loop ()
{
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume(); // Receive the next value
if (results.value == button1)
{
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
}
else {
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
}
}
else if (results.value == button2)
for (int i=0; i <= 100000; i++){
digitalWrite(10, LOW);
// Laugh OPEN CLOSE FROM TOP
makePattern(Laugh, pattern1, 6);
makePattern(Laugh, pattern2, 6);
makePattern(Laugh, pattern3, 6);
makePattern(Laugh, pattern4, 6);
makePattern(Laugh, pattern5, 6);
makePattern(Laugh, pattern6, 6);
makePattern(Laugh, pattern7, 6);
makePattern(Laugh, pattern8, 6);
makePattern(Laugh, pattern9, 6);
makePattern(Laugh, pattern10, 6);
makePattern(Laugh, pattern11, 6);
makePattern(Laugh, pattern12, 6);
break;
irrecv.resume(); // Receive the next value
}
else if (results.value == button3)
for (int i=0; i <= 1; i++){
digitalWrite(10, LOW);
// Laugh OPEN CLOSE FROM CENTER
makePattern(Laugh, pattern13, 6);
makePattern(Laugh, pattern14, 6);
makePattern(Laugh, pattern15, 6);
makePattern(Laugh, pattern16, 6);
makePattern(Laugh, pattern17, 6);
makePattern(Laugh, pattern18, 6);
makePattern(Laugh, pattern19, 6);
break;
irrecv.resume(); // Receive the next value
}
else if (results.value == button4)
for (int i=0; i <= 1; i++){
digitalWrite(10, LOW);
// Laugh OPEN CLOSE FROM BOTTOM
makePattern2(Laugh, pattern12, 6);
makePattern2(Laugh, pattern11, 6);
makePattern2(Laugh, pattern10, 6);
makePattern2(Laugh, pattern9, 6);
makePattern2(Laugh, pattern8, 6);
makePattern2(Laugh, pattern7, 6);
makePattern2(Laugh, pattern6, 6);
makePattern2(Laugh, pattern5, 6);
makePattern2(Laugh, pattern4, 6);
makePattern2(Laugh, pattern3, 6);
makePattern2(Laugh, pattern2, 6);
makePattern2(Laugh, pattern1, 6);
break;
irrecv.resume(); // Receive the next value
}
if (results.value == button5)
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(10, ledState);
digitalWrite(4, ledState);
digitalWrite(5, ledState);
digitalWrite(6, ledState);
digitalWrite(7, ledState);
digitalWrite(8, ledState);
digitalWrite(9, ledState);
irrecv.resume(); // Receive the next value
}
}
}
/*
* makePattern - this function has three parameters:
* leds[]-an array of output pins connected to LEDs
* pattern[]-an array containing HIGH or LOW to indicate whether an LED is on or off
* num-the number of LEDs
*/
void makePattern(int leds[], int pattern[], int num)
{
int delayTime = 100;
for(int i = 0; i < num; i++)
{
digitalWrite(leds[i], pattern[i]);
}
delay(delayTime);
}
void makePattern2(int leds[], int pattern[], int num)
{
int delayTime = 50;
for(int i = 0; i < num; i++)
{
digitalWrite(leds[i], pattern[i]);
}
delay(delayTime);
}