So in my project for bingo its going pretty good. I am one step closer to having it work. So when I hit a row button and a column button the arduino will turn on an led to the max7219. The only problem is that when i turn on more then one light in the same row the max shuts the previous led off and turns on the new one. How do I have it so that the max leaves the previous led on and turns on an extra led. So for example if I hit button B and column 1 it turns on light 1,1 on the max. If i then hit button B and column 2 then the light 1,1 turns off and the light 1,2 turns on. I want both lights to stay on. Thank You for Your Help!
Heres my code incase anybody is wondering:
#define dataIn 2
#define load 3
#define clock 4
int maxInUse = 1; //change this variable to set how many MAX7219's you'll use
int e = 0; // just a varialble
// define max7219 registers
byte max7219_reg_noop = 0x00;
byte max7219_reg_digit0 = 0x01;
byte max7219_reg_digit1 = 0x02;
byte max7219_reg_digit2 = 0x03;
byte max7219_reg_digit3 = 0x04;
byte max7219_reg_digit4 = 0x05;
byte max7219_reg_digit5 = 0x06;
byte max7219_reg_digit6 = 0x07;
byte max7219_reg_digit7 = 0x08;
byte max7219_reg_decodeMode = 0x09;
byte max7219_reg_intensity = 0x0a;
byte max7219_reg_scanLimit = 0x0b;
byte max7219_reg_shutdown = 0x0c;
byte max7219_reg_displayTest = 0x0f;
#define referenceVoltage A0
#define buttonRow A1
#define buttonColumn A2
#define ledB 2
#define ledC1 3
int voltage = analogRead(referenceVoltage);
int whichRow = analogRead(buttonRow);
int columnState = 0;
int rowState = 0;
void setup()
{
Serial.begin(9600);
pinMode(dataIn, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(load, OUTPUT);
//beginSerial(9600);
digitalWrite(13, HIGH);
//initiation of the max 7219
maxSingle(max7219_reg_scanLimit, 0x07);
maxSingle(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
maxSingle(max7219_reg_shutdown, 0x01); // not in shutdown mode
maxSingle(max7219_reg_displayTest, 0x00); // no display test
for (e=1; e<=8; e++) { // empty registers, turn all LEDs off
maxSingle(e,0);
}
maxSingle(max7219_reg_intensity, 0x0f & 0x0f); // the first 0x0f is the value you can set
// range: 0x00 to 0x0f
}
void loop() {
while(columnState == 0){
columnCheck();
}
while(rowState == 0) {
rowcheck();
}
Serial.println("Done with both");
while(rowState != 0 && columnState != 0){
maxSingle(columnState,rowState);
rowState = 0;
columnState = 0;
}
delay(1000);
}
void columnCheck() {
int voltage = analogRead(referenceVoltage);
int whichRow = analogRead(buttonRow);
if (whichRow > .9*voltage) {
Serial.println("B");
columnState = 1;
delay(250);
}
else {
if (whichRow > .7*voltage) {
Serial.println("I");
columnState = 2;
delay(250);
}
else {
if (whichRow > .5*voltage) {
Serial.println("N");
columnState = 3;
delay(250);
}
else {
if (whichRow > .3*voltage) {
Serial.println("G");\
columnState = 4;
delay(250);
}
else {
if (whichRow > .1*voltage) {
Serial.println("O");
columnState = 5;
delay(250);
}
else {
Serial.println("nothin hit");
delay(250);}
}
}
}
}
}
void rowcheck() {
int voltage = analogRead(referenceVoltage);
int whichColumn = analogRead(buttonColumn);
if (whichColumn > .9*voltage) {
Serial.println("1");
rowState = 1;
delay(250);
}
else {
if (whichColumn > .7*voltage) {
Serial.println("2");
rowState = 2;
delay(250);
}
else {
if (whichColumn > .5*voltage) {
Serial.println("3");
rowState = 4;
delay(250);
}
else {
if (whichColumn > .3*voltage) {
Serial.println("4");
rowState = 8;
delay(250);
}
else {
if (whichColumn > .1*voltage) {
Serial.println("5");
rowState = 16;
delay(250);
}
else {
Serial.println("nothin hit");
delay(250);}
}
}
}
}
}
void putByte(byte data) {
byte i = 8;
byte mask;
while(i > 0) {
mask = 0x01 << (i - 1); // get bitmask
digitalWrite( clock, LOW); // tick
if (data & mask){ // choose bit
digitalWrite(dataIn, HIGH);// send 1
}else{
digitalWrite(dataIn, LOW); // send 0
}
digitalWrite(clock, HIGH); // tock
--i; // move to lesser bit
}
}
void maxSingle( byte reg, byte col) {
//maxSingle is the "easy" function to use for a //single max7219
digitalWrite(load, LOW); // begin
putByte(reg); // specify register
putByte(col);//((data & 0x01) * 256) + data >> 1); // put data
digitalWrite(load, LOW); // and load da shit
digitalWrite(load,HIGH);
}