Hello All,
Project title: Controlling each LED in a 7219 LED Matrix using Joystick.
Objective: Every time I move the thumb joystick towards left, right, top, bottom, one LED should get lite and go to the left, right, top and bottom and remain there even when the joystick comes back.
For instance, if the thumb joystick is moved to the left the LED should jump/transfer to the left and stay there HIGH even if the joystick returns to its original position. Again when the joystick is moved to the left it should move the LED to the further left and stay HIGH on the recently moved position.
Here is the code:
int Xpin=A0; // X pin of joystick is connected to A0
int Ypin=A1; // Y pin of joystick is connected to A1
int readXval;
int readYval;
float Vx;
float Vy;
int hold = 100;
#include "LedControl.h" // need the library
int DIN=11 ;
int CS=10;
int CLK=13;
LedControl lc=LedControl(11,13,10,1); //10 is to CLOCK, 9 = CS, 8=DIN//
void setup() {
Serial.begin(9600);
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,8);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
}
void loop() {
readXval=analogRead(Xpin); // Joystick X movement read value//
Serial.print("readXval = ");
Serial.println(readXval, DEC);
delay(hold);
Vx=(3.3/798.)*readXval; // 3.3 is the max volt and 798. is the joystick X coordinate maximum//
Serial.print("Voltage at Vx = ");
Serial.println(Vx);
delay(hold);
readYval=analogRead(Ypin); // Joystick Y movement read value//
Serial.print("readYval = ");
Serial.println(readYval, DEC);
delay(hold);
Vy=(3.3/797.)*readYval; // 3.3 is the max volt and 797. is the joystick Y coordinate maximum //
Serial.print("Voltage at Vy = ");
Serial.println(Vy);
delay(hold);
char x_translate = map(readXval, 798, 0, 7, 0); //This maps the values//
char y_translate = map(readYval, 797, 0, 0, 7);
Serial.print("x = ");
Serial.println(x_translate, DEC);//Joystick X coordinate
delay(hold);
Serial.print("y = ");
Serial.println(y_translate, DEC);//Joystick Y coordinate
delay(hold);
lc.clearDisplay(0);
lc.setLed(0,x_translate,y_translate,true);
while(Vx>1.39){
Serial.println ("Joystick is in at X =3 & Y =2");
delay(hold);
x_translate=3; // Joystick X coordinate is translated in to x
y_translate=2;
lc.clearDisplay(0);Use code tags to format code for the forum
lc.setLed(0,x_translate,y_translate,true);
readXval=analogRead(Xpin);
Vx=(3.3/798.)*readXval;
}
}
Code Explanation:
When the Vx (voltage at X) goes more than 1.38 the X pixle or X coordinate moves to 3 while Y pixel or Y coordinates remains same at 2.
Bottom line: I need the LED to jump or transfer in the direction of the the joystick's direction movement and the LED should stay in the last location even though the joystick returns to its original position.
Help will be highly appreciated.
-UK


