Oops, I thought I replied last night ha ha, oh well.
The LED matrix is a very home brew circuit that I put together really before I knew what multiplexing was, so it might be a little unique. The device has two decade counters that run through the rows and columns while a transistor turns on at the end to let the current through only when the counters get to a specified LED. I had originally designed this using Visual Basic 6 and the Parallel port from my computer. The software is a loop that processes an array(the image)and sequences 5 pins to run the 2 clocks and resets of the counters, and the trigger transistor. It works great, but a little power hungry I think.
The accelerometer is the one from Radioshack, the Memsic 2125. The code I found to work was in the example code that comes with the arduino ide. But I quickly got bored of looking at the output over the serial port and set it up with some LEDS to measure one Axis. Then I had the idea of using this LED matrix I have to plot out both Axis. But Like I said as soon as I introduce the pulseIn() code to the LED code, I get flicker since the pulse it reads can be almost 20ms long from each axis. Last night I was able to read the accelerometer using interrupts, but that killed the LED code altogether.
Here is the code for the LED Matrix with out the accelerometer. Right now it is set up to scroll "Neato3000 :)" while stopping at the smiley for a second or two. I suppose I can make a video so every one can see what it looks like. I'll look into that. Any ideas on running both devices on the same chip? Or should just throw the towel and add a second controller?
int tPin = 2; //trigger pin, the pin that turns on the last stage transistor to allow electricity through the circuit the counters have pointed to
int xPin = 4; //x counter clock pin
int yPin = 3; //y counter clock pin
int r1Pin = 7; // counter 1 reset
int r2Pin = 8; // counter 2 reset
int intDel = 175; //trigger pin on time, higher times increase brightness, but also increase flicker
int intMillTime = 0;
int Framer = 0;
// green leads are clock
//white leads are reset
//inner black lead is trigger
//outer black lead is ground
//inner red wire is counter Vcc
//outer red wire is LED Vcc
//each array is made up of a series of decimal numbers that represent 10 bit binary numbers (0 through 1023)
//which will be converted later in the code as a column, and placed in the row it belongs to.
int picUno[10] = {
0, 204, 204, 204, 476, 0, 510, 252, 120, 0};
int allOn[10] = {
1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023};
int bioPic[10] = {
72, 132, 132, 204, 120, 510, 633, 561, 48, 204};
int earthPic[10] = {
120, 132, 386, 999, 975, 783, 975, 322, 132, 120};
int bugPic[10] = {
0, 132, 120, 1007, 220, 1007, 220, 378, 258, 0};
int scroller[] = {
0,0,0,0,0,0,0,0,0,0,1023,1023,224,112,56,28,1023,1023,0,62,127,219,219,219,123,59,0,14,223,211,211,126,63,3,192,192,1022,1023,195,195,0,60,126,195,195,126,60,0,390,903,819,819,1023,462,0,252,510,903,819,903,510,252,0,252,510,903,819,903,510,252,0,252,510,903,819,903,510,252,0,0,0,0,0,0,0,204,486,199,7,7,199,486,204,0,0,0,0,0,0,0,0,0,0};
void setup() {
pinMode(tPin,OUTPUT);
pinMode(xPin,OUTPUT);
pinMode(yPin,OUTPUT);
pinMode(r1Pin,OUTPUT);
pinMode(r2Pin,OUTPUT);
digitalWrite(r1Pin, HIGH);
digitalWrite(r2Pin, HIGH);
delay(1);
digitalWrite(r1Pin, LOW);
digitalWrite(r2Pin, LOW);
delay(1);
digitalWrite(tPin,LOW);
intMillTime = millis();
}
void loop() {
//Reset both counters
digitalWrite(r2Pin, HIGH);
digitalWrite(r2Pin, LOW);
digitalWrite(r1Pin, HIGH);
digitalWrite(r1Pin, LOW);
//Animation Timing
int intMillNow = millis();
int intTimeSpan = intMillNow - intMillTime;
//This first if statement is here to stop the scroll effect at the smiley frame
if(Framer == 84){
if(intTimeSpan > 2000){
Framer = ++Framer;
intMillTime = millis();
}
}
else{
//Remove or comment out from the last comment to here
//to remove the stop on the smiley.
//(don't forget the extra curly bracket below!!!)
//Animation delay time
if(intTimeSpan > 50){
intMillTime = millis();
Framer = ++Framer;
//Once yer at the final frame, reset the frame counter
//to 0, set this condition to the length of your array.
//This is set for the 82 length array that contains the
//scrolling "Neato3000 :)" normally a 10x10 picture should
//just be 10.
if(Framer > 92){
Framer = 0;
}
}
}
// Remove or comment from animation timing to here and set
// Framer = 0;
// for the other images.
//send the data to the led matrix by reading the column
//information from the array one row at a time.
//Basically everything below prints the array.
for(int iy = 0; iy < 10; iy++){
String myPntr;
//This is the line that defines the array(image) to use,
//as well as adding the frame count to adjust the array
//pointer to "scroll" the array if 'Framer' is changed in
//the code above.
int myNum = scroller[iy + Framer];
//This converts the number in the array that was picked in the
//last line to a 10 bit binary number.
int zeros = 10 - String(myNum,BIN).length();
String myStr;
for (int i=0; i<zeros; i++) {
myStr = myStr + "0";
}
myStr = myStr + String(myNum,BIN);
//This scans through the current row relative to the
//10 bit binary number triggering the tPin if it
//comes across a '1'.
for(int ix = 0; ix < 10; ix++) {
myPntr = myStr[ix];
if(myPntr == "1") {
digitalWrite(tPin, HIGH);
delayMicroseconds(intDel);
digitalWrite(tPin, LOW);
}
digitalWrite(yPin, LOW);
digitalWrite(yPin, HIGH);
}
digitalWrite(xPin, LOW);
digitalWrite(xPin, HIGH);
}
}