I've looked over the code and wiring multiple times and can't find a flaw in either yet the whole thing doesn't want to function. When I plug into the USB for power, the LEDs do light up, so everything seems to be wired correctly. I was guessing then it was the code, but every time I try to debug it, it doesn't look like there are any problems... here's my code:
#include <TimerOne.h>
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
byte led[8];
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
led[0] = B11111111;
led[1] = B10000001;
led[2] = B10111101;
led[3] = B10100101;
led[4] = B10100101;
led[5] = B10111101;
led[6] = B10000001;
led[7] = B11111111;
Timer1.initialize(10000);
Timer1.attachInterrupt(screenUpdate);
}
void loop() {
for (int i=0; i<8; i++) {
led[i]= ~led[i];
}
delay(500);
}
void screenUpdate() {
byte row = B10000000;
for (byte k=0; k<9; k++) {
digitalWrite(latchPin, LOW);
shiftIt(~led[k] );
shiftIt(row );
digitalWrite(latchPin, HIGH);
row = row << 1;
}
}
void shiftIt(byte dataOut) {
boolean pinState;
digitalWrite(dataPin, LOW);
for (int i=0; i<8; i++) {
digitalWrite(clockPin, LOW);
if ( dataOut & (1<<i) ) {
pinState = HIGH;
}
else {
pinState = LOW;
}
digitalWrite(dataPin, pinState);
digitalWrite(clockPin, HIGH);
digitalWrite(dataPin, LOW);
}
digitalWrite(clockPin, LOW);
}
Wednesday, November 2, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment