system
January 30, 2013, 7:23pm
14
Ok, so there is a problem with the switches.
I think:
switchPin should be OUTPUT and digitalWrite( switchPin, LOW);
buttonmatrixN are INPUT_PULLUP; (or INPUT and then digitalWrite( buttonmatrixN, HIGH);
Try that and check the Serial Monitor output again?
Okay I changed that and the serial monitor now is like this. Even when I press the buttons, nothing changes
1018 1020 1020 1021
1018 1019 1020 1021
1019 1020 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1019 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1019 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1019 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1021
1018 1019 1020 1020
1018 1019 1020 1021
1018 1019 1020 1020
1019 1019 1020 1021
1018 1019 1020 1021
system
January 30, 2013, 10:57pm
16
Time to post again the entire code with your changes
system
January 30, 2013, 11:15pm
17
We are working on just the buttons right now, we will leave the LEDS for later.
If your version has the so-called "isolation diodes" then we must reverse the polarity of the sense:
void setup()
{
pinMode(buttonMatrix1, INPUT); // Button sense
pinMode(buttonMatrix2, INPUT); // external pull-down may be required
pinMode(buttonMatrix3, INPUT);
pinMode(buttonMatrix4, INPUT);
pinMode(SwitchPin, OUTPUT); // Button Common
digitalWrite(SwitchPin, HIGH);
}
void loop()
{
Serial.print(analogRead(buttonMatrix1));
Serial.print("\t");
Serial.print(analogRead(buttonMatrix2));
Serial.print("\t");
Serial.print(analogRead(buttonMatrix3));
Serial.print("\t");
Serial.println(analogRead(buttonMatrix4));
delay(200);
}
Cheers,
John
system
January 30, 2013, 11:46pm
18
I'm always amazed at people that take an action based on one reading, then take another reading and print it, and don't understand that the two readings can be different.
Those appear to be regular digital switches on that board. Why are you using analogRead() to read digital switches?
How about posting a picture showing how you have connected that to the Arduino?
I don't get these switches!
They are different, I've never used 2 pin ones.
Picture attached
system
January 30, 2013, 11:53pm
20
They are different, I've never used 2 pin ones.
Every switch I've ever seen had just two pins. Have you used a multimeter to see how those switches actually work?
I haven't, unfortunately I left my multimeter back home from winter break.
I mean, I've only ever used push buttons.
I still don't get why when I press one button, all of them respond
EDIT: Respond as the same button I mean.
system
January 30, 2013, 11:55pm
22
funkyguy4000:
I don't get these switches!
They are different, I've never used 2 pin ones.
Did you ever run successfully the sketch that you had copy/pasted off the 'net before you started changing it?
No, there aren't many sketches for just the 2x2 matrix.
I have had it working to the point where it lights up, and then I press a button and all the lights change to the specified, but its always the same color and doesn't correspond to which button is pressed
system
January 30, 2013, 11:59pm
24
I still don't get why when I press one button, all of them respond
EDIT: Respond as the same button I mean.
Well, clearly you don't have them connected right. I would expect the switches to be wired one side to ground and one side to a digital pin, with the pullup resistor on that pin enabled. Press the switch to have the pin go LOW.
system
January 31, 2013, 12:00am
25
funkyguy4000:
No, there aren't many sketches for just the 2x2 matrix.
I have had it working to the point where it lights up, and then I press a button and all the lights change to the specified, but its always the same color and doesn't correspond to which button is pressed
Well, it appears you got that code from here http://www.aarongoselin.com/active-posts/28-using-sparkfuns-2x2-rgb-led-button-pad-with-an-arduino
(Not that it's that great as PaulS has noted)
But again, did it work before you started changing it?
Cheers,
John
So I set it up like this?
system
January 31, 2013, 12:05am
27
As I wrote up-thread his version may have the "isolation diodes" in which case he would need to go the other way around, with pulldown resistors...
A good reason to have a multi-meter. OP, hit the nearest Radio Shack (or equivalent) before you fry something.
Haha, okay. I'll get in the lab tomorrow. I need to get to my MATLAB homework anyway.
To make sure we are clear, what exactly am I looking for?
system
January 31, 2013, 12:24am
29
funkyguy4000:
So I set it up like this?
Yeah. Unless you can figure out that your version does not have the isolation diodes, in which case it could be simpler..
And maybe just start with 1 button
get it Working
...
and then 1 led
get it Working
...
and then more leds
working
... etc
Well I could remove the diodes
system
January 31, 2013, 12:32am
31
If you remove the diode and replace with jumper (or better would be 1-to-5k resistor ) , you can do without the external pull-down resistor and wire the switches between the arduino pin and Gnd.
system
January 31, 2013, 12:40am
32
In that case your hardware test code would be simply like this:
// Button sense
const int button1 = A1; // or whichever you wire to
const int button2 = A2;
const int button3 = A3;
const int button4 = A4;
void setup()
{
// Button sense
pinMode(button1, INPUT_PULLUP);
//pinMode(button2, INPUT_PULLUP);
//pinMode(button3, INPUT_PULLUP);
//pinMode(button4, INPUT_PULLUP);
}
void loop()
{
Serial.print( digitalRead(button1)); Serial.print("\t");
//Serial.print( digitalRead(button2)); Serial.print("\t");
//Serial.print( digitalRead(button3)); Serial.print("\t");
//Serial.print( digitalRead(button4));
Serial.println();
delay(250);
}
system
January 31, 2013, 12:46am
33
Shouldn't the input pins be digital and not analog?
And the switches should go from the digital pin to GND when pressed, yes?