#include <IRremote.h>
String myCom;
const byte IR_RECEIVE_PIN = 2;
int LHlights = 11;
int RHlights = 12;
int lightsOn = 0;
int lightsDelay = 10;
int d = 150;
int bubbleLight = 0;
int leftTurn = 0;
int LeftTurnWOB = 0;
int turn1 = 255;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("IR Receive test");
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
pinMode(3, OUTPUT);
pinMode(5,OUTPUT);
pinMode(7, OUTPUT);
pinMode(9, OUTPUT);
pinMode(4, OUTPUT);// right break light
pinMode(6, OUTPUT);// left break light
pinMode(11, OUTPUT);// headlight left
pinMode(12, OUTPUT);// headlight right
}
void LeftTurnWB() { //left turn with bubble light
analogWrite(3, 0);
analogWrite(5, 255);
analogWrite(7, 0);
analogWrite(9, 0);
digitalWrite(6, HIGH);
delay(d);
analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(7, 255);
analogWrite(9, 0);
delay(d);
analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(7, 0);
analogWrite(9, 255);
digitalWrite(6, LOW);
delay(d);
analogWrite(3, 255);
analogWrite(5, 0);
analogWrite(7, 0);
analogWrite(9, 0);
delay(d);
}
void LeftTWOBubble(){
digitalWrite(6,HIGH);
delay(d);
delay(d);
delay(d);
digitalWrite(6,LOW);
delay(d);
delay(d);
delay(d);
}
void blight() { //bubble light
analogWrite(3, 0);
analogWrite(5, 255);
analogWrite(7, 0);
analogWrite(9, 0);
delay(d);
analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(7, 255);
analogWrite(9, 0);
delay(d);
analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(7, 0);
analogWrite(9, 255);
delay(d);
analogWrite(3, 255);
analogWrite(5, 0);
analogWrite(7, 0);
analogWrite(9, 0);
delay(d);
}
void blightOff() { //bubble light off
analogWrite(3, 0);
analogWrite(5, 0);
analogWrite(7, 0);
analogWrite(9, 0);
}
void headlightsOn() { //turns on headlights
analogWrite(LHlights, 255);
analogWrite(RHlights, 255);
}
void headlightsOff() { //turns off headlights
analogWrite(LHlights, 0);
analogWrite(RHlights, 0);
}
void loop() {
// put your main code here, to run repeatedly:
if (IrReceiver.decode()) //Remote Reading Command
{
Serial.println(IrReceiver.decodedIRData.command);
IrReceiver.resume();
}
if(IrReceiver.decodedIRData.command == 162){ // power
myCom ="power";
Serial.println("power");
IrReceiver.decodedIRData.command = 0;
}
if(IrReceiver.decodedIRData.command == 226){ // Menu
myCom ="menu";
Serial.println("menu");
IrReceiver.decodedIRData.command = 0;
}
if(IrReceiver.decodedIRData.command == 224){ // Menu
myCom ="lTurn";
Serial.println("turn left");
IrReceiver.decodedIRData.command = 0;
}
if(myCom == "lTurn" && leftTurn == 0 && bubbleLight == 1){ // turns on left turn sig with bubble
Serial.println("Left Turn Sig with bubble light");
leftTurn = 9;
myCom="";
}
if(myCom == "lTurn" && leftTurn == 0 && bubbleLight == 0){ // turns on left turn sig without bubble
Serial.println("Left Turn Sig without bubble light");
LeftTurnWOB = 9;
myCom="";
}
if(myCom == "menu" && bubbleLight == 0){ // turns on bubble light
Serial.println("Bubble Lights On");
bubbleLight = 1;
myCom="";
}
if (myCom == "menu" && bubbleLight == 1){ // turns off bubble light
Serial.println("Bubble Light Off");
bubbleLight = 0;
myCom="";
}
// everything below this will need to be changed to turn the power button into an ignition key
if(myCom == "power" && lightsOn == 0){ // Power routine
Serial.println("lights On");
lightsOn = 1;
myCom="";
}
if(myCom == "power" && lightsOn == 1){ // Power routine
Serial.println("lights off");
lightsOn = 0;
myCom="";
}
//LeftTurnWB();
if (leftTurn > 0){
LeftTurnWB();
leftTurn = leftTurn -1;
}
if (LeftTurnWOB > 0){
LeftTWOBubble();
LeftTurnWOB = LeftTurnWOB -1;
}
if (lightsOn == 1){
headlightsOn();
}
if (lightsOn == 0){
headlightsOff();
}
if (bubbleLight == 1){
blight();
}
if (bubbleLight == 0){
blightOff();
}
}