Hey all so Im building an 8x10 matrix where I have all my columns running to a shift register and the rows to a decade counter. I am trying to use a joystick where if i push it down it will light up the leds and they will stay on. I can only get one led to turn on at a time and didn't know if there was a workaround for this.
The problem will probably be either your program or your wiring but as you have shared neither of them it is difficult to provide help.
Hi.
How fast are you multiplexing the array.
Can you please post a copy of your sketch, using code tags.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
Thanks Tom.....
#include <TimedAction.h>
//shit register pins
int latchpin = 4;
int clockpin = 3;
int datapin = 2;
//decade counter pins
int clock = 13;
int Reset = 12;
int Enable = 6;
//josstick x and y
int joyPinx = 0;
int joyPiny = 1;
int pushButton = 7;
//my x and y coordinates
int coordX = 0;
int coordY = 0;
//when the joystick isnt pressed this is the center
int centerX = 500;
int centerY = 500;
int clockPosition = 0;
int i = 0;
int j;
int lastbitused = 0;
int newbits;
/*TimedAction upAction = TimedAction(200, xUp);
TimedAction leftAction = TimedAction(200, yLeft);
TimedAction rightAction = TimedAction(200, yRight);
TimedAction downAction = TimedAction(200, xDown);
TimedAction moveAction = TimedAction(200, moveball);
*/
void setup()
{
pinMode(latchpin, OUTPUT);
pinMode(clockpin, OUTPUT);
pinMode(datapin, OUTPUT);
pinMode(clock,OUTPUT);
pinMode(Reset,OUTPUT);
pinMode(pushButton, INPUT);
digitalWrite(Reset,HIGH);
delayMicroseconds(5);
digitalWrite(Reset,LOW);
Serial.begin(9600);
}
void loop()
{
coordX = analogRead(joyPinx);
coordY = analogRead(joyPiny);
int bits = (pow(2,i)+1);
/*
upAction.check();
leftAction.check();
rightAction.check();
downAction.check();
moveAction.check();
*/
//move up
if(coordX < 200){
delay(100);
Serial.println(clockPosition);
digitalWrite(Reset,HIGH);
delayMicroseconds(5);
digitalWrite(Reset,LOW);
//first I reset the clock then I run this for loop until the clock position in move up is met -1 which will put
//the led right before the one selected to simulate how to move up
for(j = 0; j <clockPosition-1; j++){
digitalWrite(clock, HIGH);
digitalWrite(clock,LOW);
}
clockPosition--;
j == 0;
}
if(coordX > 900){
delay(100);
digitalWrite(clock, HIGH);
digitalWrite(clock,LOW);
clockPosition++;
}
//move left
if(coordY > 900){
delay(100);
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST,bits);
digitalWrite(latchpin, HIGH);
i++;
lastbitused++;
Serial.println(lastbitused);
}
//move right
if(coordY < 200){
delay(100);
newbits = bits/2;
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, newbits);
digitalWrite(latchpin, HIGH);
i--;
}
}
void xUp(){
}
void xDown(){
}
void yLeft(){
}
void yRight(){
}
void moveball(){
int Button = digitalRead(pushButton);
if(Button == LOW){
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST,1);
digitalWrite(latchpin, HIGH);
delay(500);
digitalWrite(clock,HIGH);
delayMicroseconds(5);
digitalWrite(clock,LOW);
}
As of right now my code lets me move a single led in all directions but i want to be able to keep certain leds on. My end goal is to be able to draw a box. I also wasn't sure how to make the decade counter count backwards so i had to hard code the move up by giving the illusion to the led is moving up even though it is just reseting every time. I also want to be able to eventually be able to draw a box then push a button and have a ball bounce around the screen and bounce off the box. Any help will do Iv'e been working at this for way to long.
I used 82 ohm resistors going to the shift register and 1k going to the decade counter and the lights turn on bright also
P.S. I also changed the pins around so the shift register is 2,3,4, and the decade counter is 12,13 with the enable running to the ground