Go Down

Topic: Sparkfun 2x2 led matrix button board help (Read 1 time) previous topic - next topic



I have been working with sparkfuns 2x2 led matrix button board recently and I've gotten the lights to light up on their own, but as for the buttons, no dice.  I'm sure its my code, could somebody take a peek?

Code: [Select]
2x2 RGB LED Control
This is for control of Sparkfun's 2x2 RGB Button Pad.

Original: Aaron Goselin (Nakor) Oct 27, 2010

Editor: Shannon Strutz Jan 28th, 2012

This code is in the public domain.

// Button Grounds
const int buttonMatrix1 = A1;
const int buttonMatrix2 = A2;
const int buttonMatrix3 = A3;
const int buttonMatrix4 = A4;
// LED Grounds
const int ledGnd1 = 0;
const int ledGnd2 = 1;
const int ledGnd3 = 2;
const int ledGnd4 = 3;
// RGB pins
const int redLED = 13;
const int greenLED = 12;
const int blueLED = 11;
const int SwitchPin = 10;

// Colour definitions
int red[] = {255, 0, 0};
int green[] = {0, 255, 0};
int blue[] = {0, 0, 255};
int purple[] = {255, 0, 150};
int yellow[] = {255, 255, 0};
int dark[] = {0, 0, 0};

void setup()
// Switch Grounds
pinMode(buttonMatrix1, INPUT);
pinMode(buttonMatrix2, INPUT);
pinMode(buttonMatrix3, INPUT);
pinMode(buttonMatrix4, INPUT);

// Led grounds
pinMode(ledGnd1, OUTPUT);
pinMode(ledGnd2, OUTPUT);
pinMode(ledGnd3, OUTPUT);
pinMode(ledGnd4, OUTPUT);

// RGB pins
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);

pinMode(SwitchPin, OUTPUT);

// Serial if you need it

void loop() {
digitalWrite(SwitchPin, HIGH);
// Pass in the colour of your buttons 1, 2, 3, and 4
if (buttonMatrix1 >=analogRead(900))
else if(buttonMatrix2 >= analogRead(900))

else if(buttonMatrix3 >= analogRead(900))

else if(buttonMatrix4 >= analogRead(900))

else {
  ledColour(purple, blue, green, red);

// Uniform colour. Pass in the colour array of your choice.

// Dark is just off. Use dark to turn any LED off.
//ledColour(dark, dark, dark, dark);

// Check for button presses and output states
// Enable if you want to test your buttons


// Control individual LEDs
// Pass in a colour array for each LED
void ledColour(int led1[], int led2[], int led3[], int led4[])
analogWrite(redLED, led1[0]);
analogWrite(greenLED, led1[1]);
analogWrite(blueLED, led1[2]);
// Flicker control
digitalWrite(ledGnd1, LOW);
// Flicker control
digitalWrite(ledGnd1, HIGH);

analogWrite(redLED, led2[0]);
analogWrite(greenLED, led2[1]);
analogWrite(blueLED, led2[2]);
// Flicker control
digitalWrite(ledGnd2, LOW);
// Flicker control
digitalWrite(ledGnd2, HIGH);

analogWrite(redLED, led3[0]);
analogWrite(greenLED, led3[1]);
analogWrite(blueLED, led3[2]);
// Flicker control
digitalWrite(ledGnd3, LOW);
// Flicker control
digitalWrite(ledGnd3, HIGH);

analogWrite(redLED, led4[0]);
analogWrite(greenLED, led4[1]);
analogWrite(blueLED, led4[2]);
// Flicker control
digitalWrite(ledGnd4, LOW);
// Flicker control
digitalWrite(ledGnd4, HIGH);


// Uniform colour
// This doesn't appear to work well with mixed colours.
void ledColourU(int colour[])
analogWrite(redLED, colour[0]);
analogWrite(greenLED, colour[1]);
analogWrite(blueLED, colour[2]);
digitalWrite(ledGnd1, LOW);
digitalWrite(ledGnd2, LOW);
digitalWrite(ledGnd3, LOW);
digitalWrite(ledGnd4, LOW);

I know that my problem lies in the fact that I've never really worked with buttons that have only 2 connections.  I've only ever worked with the pushbuttons that have 4 pins.  Can somebody help me out on getting this thing working?
Accelerate to 88 miles per hour.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131