#include <LiquidCrystal.h>
#include <LedControl.h>
#define VRX_PIN A3 // Arduino pin connected to VRX pin
#define VRY_PIN A2 // Arduino pin connected to VRY pin
#define SEL_PIN 6
#define CLK_PIN 9
#define DATA_PIN 7
#define CS_PIN 8
LedControl lc = LedControl(DATA_PIN, CLK_PIN, CS_PIN, 0);
int xValue = 0; // To store value of the X axis
int yValue = 0; // To store value of the Y axis
int switchState = 1;
const int RS = 12, E = 11, D4 = 5, D5 = 4, D6 = 3, D7 = 2;
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//pinMode(swPin, INPUT);
lc.shutdown(0, false);
lc.setIntensity(0, 0);
lc.clearDisplay(0);
pinMode(CLK_PIN, OUTPUT);
pinMode(DATA_PIN, OUTPUT);
pinMode(CS_PIN, OUTPUT);
lcd.begin(16,2);
// lc.setLed(0,1,0,true);
// lc.setLed(0,1,1,true);
// lc.setLed(0,1,2,true);
// lc.setLed(0,1,3,true);
// lc.setLed(0,1,4,true);
// lc.setLed(0,1,5,true);
// delay(10000);
//digitalWrite(swPin, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
// read analog X and Y analog values
//xValue = analogRead(VRX_PIN);
//yValue = analogRead(VRY_PIN);
//switchState = digitalRead(swPin);
//
// print data to Serial Monitor on Arduino IDE
//Serial.print("Switch: ");
//Serial.println(switchState);
//if (!switchState){
//Serial.println("Switch is Pressed")
//}
//delay(200);
//if lcd.print(Joystick);
int x_map = map(analogRead(VRX_PIN), 0, 1023, -1,1); // maps analog value from -4 to 4
int y_map = map(analogRead(VRY_PIN), 0, 1023, 1,-1); // maps analog value from -4 to 4
Serial.print("x = ");
Serial.println(x_map, DEC);
Serial.print(", y = ");
Serial.println(y_map, DEC);
Serial.println("");
//lc.clearDisplay(0);
lc.setLed(0,x_map, y_map, true);
delay(150);
if (digitalRead(SEL_PIN) == LOW) {
//need to switch to the other thing
//mx.clear();
}
}