/*Written by Pat McMahon 19/1/2019
*Infrared Animated disc- 10 sets of 6 LED's
*from Pat's IR Robot
*1/9/2018
 */

#include <IRremote.h>

const int kPinLed1 = 2;
const int kPinLed2 = 3;
const int kPinLed3 = 4;
const int kPinLed4 = 5;
const int kPinLed5 = 6;
const int kPinLed6 = 7;
const int kPinLed7 = 8;
const int kPinLed8 = 9;
const int kPinLed9 = 10;
const int kPinLed10 = 11;

int delayTime=300;
int forwards():
int backwards();
int left();
int right();
int halt();
const int RECV_PIN = A4;

IRrecv irrecv(RECV_PIN);

void setup()
{
  pinMode(kPinLed1, OUTPUT);
  pinMode(kPinLed2, OUTPUT);
  pinMode(kPinLed3, OUTPUT);
  pinMode(kPinLed4, OUTPUT);
  pinMode(kPinLed5, OUTPUT);
  pinMode(kPinLed6, OUTPUT);
  pinMode(kPinLed7, OUTPUT);
  pinMode(kPinLed8, OUTPUT);
  pinMode(kPinLed9, OUTPUT);
  pinMode(kPinLed10, OUTPUT);

  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  decode_results results;

  if (irrecv.decode(&results)) // if there is an IR reading
  {
    Serial.println(results.value, HEX);

    switch (results.value)
    {
      case 0x2F0:
       //Serial.println("Forwards!");
       forwards();
        break;
      case 0xAF0:
       //Serial.println("Backwards!");
        backwards();
        break;
      case 0x2D0:
        //Serial.println("Left!");
        left();
        break;
      case 0xCD0:
        //Serial.println("Right!");
       right();
        break;
      case 0xA70:
        //Serial.println("Stop!");
        halt();
        break;
    }
    
    irrecv.resume(); // Receive the next value
  }
} 
 
void forwards()
{
   // turns on/off opposites in clockwise order
  digitalWrite(kPinLed1, HIGH);
  digitalWrite(kPinLed6, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed1, LOW);
  digitalWrite(kPinLed6, LOW);
  delay(delayTime);
  digitalWrite(kPinLed2, HIGH);
  digitalWrite(kPinLed7, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed2, LOW);
  digitalWrite(kPinLed7, LOW);
  delay(delayTime);
  digitalWrite(kPinLed3, HIGH);
  digitalWrite(kPinLed8, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed3, LOW);
  digitalWrite(kPinLed8, LOW);
  delay(delayTime);
  digitalWrite(kPinLed4, HIGH);
  digitalWrite(kPinLed9, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed4, LOW);
  digitalWrite(kPinLed9, LOW);
  delay(delayTime);
  digitalWrite(kPinLed5, HIGH);
  digitalWrite(kPinLed10, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed5, LOW);
  digitalWrite(kPinLed10, LOW);
  delay(delayTime);
  digitalWrite(kPinLed1, HIGH);
  digitalWrite(kPinLed6, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed1, LOW);
  digitalWrite(kPinLed6, LOW);
  delay; 2000;
}

void backwards()
{
// turns on/off opposites in anticlockwise order
  digitalWrite(kPinLed5, HIGH);
  digitalWrite(kPinLed10, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed5, LOW);
  digitalWrite(kPinLed10, LOW);
  delay(delayTime);
  digitalWrite(kPinLed9, HIGH);
  digitalWrite(kPinLed4, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed9, LOW);
  digitalWrite(kPinLed4, LOW);
  delay(delayTime);
  digitalWrite(kPinLed8, HIGH);
  digitalWrite(kPinLed3, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed8, LOW);
  digitalWrite(kPinLed3, LOW);
  delay(delayTime);
  digitalWrite(kPinLed7, HIGH);
  digitalWrite(kPinLed2, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed7, LOW);
  digitalWrite(kPinLed2, LOW);
  delay(delayTime);
  digitalWrite(kPinLed6, HIGH);
  digitalWrite(kPinLed1, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed6, LOW);
  digitalWrite(kPinLed1, LOW);
  delay(delayTime);
  digitalWrite(kPinLed5, HIGH);
  digitalWrite(kPinLed10, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed5, LOW);
  digitalWrite(kPinLed10, LOW);
  delay; 2000;

void right()
{

 // turn on each of the LEDs in clockwise order
  //let b3=0;
 //do;
  digitalWrite(kPinLed1, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed2, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed3, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed4, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed5, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed6, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed7, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed8, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed9, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed10, HIGH);
  delay(delayTime);

  

  // turn off each of the LEDs in clockwise order
  digitalWrite(kPinLed1, LOW);
  delay(delayTime);
  digitalWrite(kPinLed2, LOW);
  delay(delayTime);
  digitalWrite(kPinLed3, LOW);
  delay(delayTime);
  digitalWrite(kPinLed4, LOW);
  delay(delayTime);
  digitalWrite(kPinLed5, LOW);
  delay(delayTime);
  digitalWrite(kPinLed6, LOW);
  delay(delayTime);
  digitalWrite(kPinLed7, LOW);
  delay(delayTime);
  digitalWrite(kPinLed8, LOW);
  delay(delayTime);
  digitalWrite(kPinLed9, LOW);
  delay(delayTime);
  digitalWrite(kPinLed10, LOW);
  delay;2000;
}

void left()
{
// turn on each of the LEDs in anticlockwise order
  digitalWrite(kPinLed10, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed9, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed8, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed7, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed6, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed5, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed4, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed3, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed2, HIGH);
  delay(delayTime);
  digitalWrite(kPinLed1, HIGH);
 delay(delayTime);

  // turn off each of the LEDs in anticlockwise order
  digitalWrite(kPinLed10, LOW);
  delay(delayTime);
  digitalWrite(kPinLed9, LOW);
  delay(delayTime);
  digitalWrite(kPinLed8, LOW);
  delay(delayTime);
  digitalWrite(kPinLed7, LOW);
  delay(delayTime);
  digitalWrite(kPinLed6, LOW);
  delay(delayTime);
  digitalWrite(kPinLed5, LOW);
  delay(delayTime);
  digitalWrite(kPinLed4, LOW);
  delay(delayTime);
  digitalWrite(kPinLed3, LOW);
  delay(delayTime);
  digitalWrite(kPinLed2, LOW);
  delay(delayTime);
  digitalWrite(kPinLed1, LOW);
  delay; 2000;
}
 
void halt()
{
  digitalWrite(kPinLed1, LOW);
  digitalWrite(kPinLed2, LOW);
  digitalWrite(kPinLed3, LOW);
  digitalWrite(kPinLed4, LOW);
  digitalWrite(kPinLed5, LOW);
  digitalWrite(kPinLed6, LOW);
  digitalWrite(kPinLed7, LOW);
  digitalWrite(kPinLed8, LOW);
  digitalWrite(kPinLed9, LOW);
  digitalWrite(kPinLed10, LOW); 
}