#include <IRremote.h>
#include <LedControl.h>
#include <LiquidCrystal.h>
//Val = map(analog_val, 0, 1023, -10, 10);
int joy_x;
int x;
int y;
int joy_y;
int DIN = 8;
int CS = 9;
int CLK = 10;
int SEL = 2; //button of joystick
//IR receiver
const int RECV_PIN=17; //signal pin on pin 17
unsigned long up = 4244832000;
unsigned long down = 1738080000;
unsigned long rvs = 534839040;
unsigned long fwd = 1871773440;
unsigned long power = 1570963200;
LedControl lc = LedControl(DIN, CLK, CS, 0);
//LCD setup -- pins
const int rs=12, en=11, d4=5, d5=4, d6=6, d7=7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//mode (joystick or RS)
int mode=0;
//mode 1 = joystick
//mode 2 = IR remote
void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,0);
lc.clearDisplay(0);
Serial.begin(9600);
pinMode(SEL, INPUT);
IrReceiver.begin(RECV_PIN);
lcd.begin(16,2);
}
void loop() {
joy_x = analogRead(A0);
joy_y = analogRead(A1);
lcd.clear();
lcd.setCursor(0,0);
Serial.println(mode);
lcd.print("Mode: ");
if (mode==1){
lcd.print("JOYSTICK");
}
else if (mode==2){
lcd.print("REMOTE");
}
else{
lcd.print(" ");
}
//check mode
if (digitalRead(2)==HIGH){
mode = 1; //joystick
}
else if (IrReceiver.decodedIRData.decodedRawData == power){
mode = 2; //IR remote
}
lc.setLed(0,y,x,true);
lc.setLed(0, y-1, x-1, true);
lc.setLed(0, y, x-1, true);
lc.setLed(0, y-1, x, true);
if (mode==1){
x = map(joy_x, 0, 1023, 6, 0);
y = map(joy_y, 0, 1023, 0, 6);
for (int j=0; j<8; j++){
for (int i=0; i<8; i++){
if (i==x and j==y){}
else if (i==x+1 and j==y){}
else if (i==x+1 and j==y+1){}
else if (i==x and j==y+1){}
else{
lc.setLed(0, 7-j, 7-i, false);
}
}
}
//lc.setLed(0,7,0,true);
lc.setLed(0,7-y,7-x,true);
lc.setLed(0,7-y-1,7-x,true);
lc.setLed(0,7-y,7-x-1,true);
lc.setLed(0,7-y-1,7-x-1,true);
}
//IR reciever -- reading inputs (Original code)
if (IrReceiver.decode()){ //0 if no data ready, 1 if data ready
//Serial.print("Code: ");
//Serial.println(IrReceiver.decodedIRData.decodedRawData);
//returns raw decoded value, 32 bits
IrReceiver.resume(); //ready to recieve next value
}
//remote
//up
//down
//right
//left
delay(200);
}