ok half the battle with this code is its copied from a website relating to multiplexing LED's and im not 100% sure on how or what its doing especially realting to the bitwise operations.
what i am trying to get this code to-do is multiplex 9 leds, that are setup as the bottom row of what will be eventually a 3 x 3 x 3 cube. however the code does not do anything except light up the first led for a split second then switch it off.
my led grid is arranged like this.
1-2-3
4-5-6
7-8-9
they all share a common ground connection and each Positive (anode ??) pin is connected to a sepeate pin on the arduino, here is a list of led (anode?) pins to arduino pin mappings, each arduino pin needs to be brough HIGH to bring the LED on.
Led = Arduino
1 = 2
2 = 3
3 = 4
4 = 5
5 = 6
6 = 7
7 = 8
8 = 9
9 = 10
here is the sketch i have so far, any help would be appreaciated on what is going wrong or a better way to multiplex the led's..
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
Serial.begin(9600);
};
void loop() {
byte PATTERN[1][3] = {
{B010,B101,B010},
};
int PATTERN_SIZE = 1;
long PATTERN_DELAY_MS = 0.5;
for (int pos = 0; pos < PATTERN_SIZE; pos++) {
long start = millis();
while (millis() - start < PATTERN_DELAY_MS) {
ShowPattern(PATTERN[pos]);
}
}
delay(3000);
}
void SetColumn(byte pattern) {
int COL_PINS[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
int COL_COUNT = 3;
for (int i = COL_COUNT-1; i >= 0; i--, pattern >>= 1) {
digitalWrite(COL_PINS[i], pattern & 1 ? LOW : HIGH);
Serial.print(COL_PINS[i]);
}
}
void ShowPattern(byte pattern[]) {
Serial.println('here');
long MULTIPLEX_DELAY_MS = 0.5;
int ROW_COUNT = 3;
int last_row = ROW_COUNT - 1;
for (int row = 1; row < ROW_COUNT ; row++) {
SetColumn(pattern[row]);
Serial.print(row);
delay(MULTIPLEX_DELAY_MS);
}
}
thanks
kris