Difference between revisions of "Adafruit: 8x8 Red LED Matrix Panel"
(→Demo of Animation) |
(→Overview) |
||
Line 5: | Line 5: | ||
My mini project 2 is using an Adafriut 8*8 red LED matrix to show 2 animations. First animation is to composite a diamond and then fade out. The second animation is to drop down a horizontal bar to the bottom of the LED matrix until all the lines are being filled. When the two animations were done, the LED matrix will flash 5 times and shut down. | My mini project 2 is using an Adafriut 8*8 red LED matrix to show 2 animations. First animation is to composite a diamond and then fade out. The second animation is to drop down a horizontal bar to the bottom of the LED matrix until all the lines are being filled. When the two animations were done, the LED matrix will flash 5 times and shut down. | ||
− | The code that being used in this project is modified from the sample code provided by Dr. Mark A. Yoder. The new version of the code that contained my animation has been commited to my github which you can find at here: [https://github.com/1984xiali/ | + | The code that being used in this project is modified from the sample code provided by Dr. Mark A. Yoder. The new version of the code that contained my animation has been commited to my github which you can find at here: [https://github.com/1984xiali/ECE497_mini_project2 Mini-project 2 by Xia Li]. |
== Wire Connection == | == Wire Connection == |
Revision as of 22:31, 5 November 2012
Contents
Overview
My mini project 2 is using an Adafriut 8*8 red LED matrix to show 2 animations. First animation is to composite a diamond and then fade out. The second animation is to drop down a horizontal bar to the bottom of the LED matrix until all the lines are being filled. When the two animations were done, the LED matrix will flash 5 times and shut down.
The code that being used in this project is modified from the sample code provided by Dr. Mark A. Yoder. The new version of the code that contained my animation has been commited to my github which you can find at here: Mini-project 2 by Xia Li.
Wire Connection
The wire connection part is not very complex. As you can see in the picture pin3 VDD3.3v ----> breadboard's positive(red line)
pin45 GND ----> breadboard's negative(blue line)
pin19 i2c2_SCL ----> LED matrix's c pin
pin20 i2c2_SDA ----> LED matrix's d pin.
Don't forget the two 4.3KΩ pull-up resistors.
LED matrix's + - pin ----> breadboard's positive and negative
The wire connection picture:
Here is a hand by hand tutorial about I2C wrote by Dr. Yoder. If you need that Click here.
Software Design
Important facts
After I went through the sample code. I found several points which are very important. You may need to understand before you move on:
1. i2cbus is 3
2. i2c address is 0x70
3. oscillator daddress is 0x21
4. display on daddress is 0x81
5. Full brightness is 0xE7
6. array smile_bmp[], frown_bmp[], and neutral_bmp[] are save the hex-decimal value for each line on LED matrix
Theory
The theory is when you convert the hex-decimal value of each line to binary value, you will get a 8 bit binary number for each line. Each bit will stand for each led point on the corresponding line. 0 for off, 1 for on.
For example: 0x18 = 1 * 16 + 8 = 24(decimal) = 0 0 0 1 1 0 0 0(binary)
This value means the 4th and 5th led position of that line will be on, all the other leds will be off. As long as you understand this, you can program your own patterns or animations.
My Animations Analysis
I create 4 patterns for diamond animation:
pic1_bmp[]={0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x7E, 0x3C, 0x18}
pic2_bmp[]={0x18, 0x3C, 0x7E, 0xE7, 0xE7, 0x7E, 0x3C, 0x18}
pic3_bmp[]={0x18, 0x3C, 0x66, 0xC3, 0xC3, 0x66, 0x3C, 0x18}
pic4_bmp[]={0x18, 0x24, 0x42, 0x81, 0x81, 0x42, 0x24, 0x18}
The horizontal bar animation only need 1 pattern:
line_bmp[]={0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
Source Code
Below is the major part of the source code:
static __u16 smile_bmp[]={0x3C, 0x42, 0x95, 0xA1, 0xA1, 0x95, 0x42, 0x3C}; static __u16 test_bmp[]={0x3C, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; static __u16 frown_bmp[]={0x3C, 0x42, 0xA5, 0x91, 0x91, 0xA5, 0x42, 0x3C}; static __u16 neutral_bmp[]={0x3C, 0x42, 0x95, 0x91, 0x91, 0x95, 0x42, 0x3C}; static __u16 pic1_bmp[]={0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0x7E, 0x3C, 0x18}; static __u16 pic2_bmp[]={0x18, 0x3C, 0x7E, 0xE7, 0xE7, 0x7E, 0x3C, 0x18}; static __u16 pic3_bmp[]={0x18, 0x3C, 0x66, 0xC3, 0xC3, 0x66, 0x3C, 0x18}; static __u16 pic4_bmp[]={0x18, 0x24, 0x42, 0x81, 0x81, 0x42, 0x24, 0x18}; static __u16 line_bmp[]={0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Demo 1 is showing... printf("Demo 1 is showing...\n"); while(counter <= 1) { for(i=0; i<8; i++){ block[i] = (pic1_bmp[i]&0xfe) >> 1 | (pic1_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); for(i=0; i<8; i++){ block[i] = (pic2_bmp[i]&0xfe) >> 1 | (pic2_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); for(i=0; i<8; i++){ block[i] = (pic3_bmp[i]&0xfe) >> 1 | (pic3_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); for(i=0; i<8; i++){ block[i] = (pic4_bmp[i]&0xfe) >> 1 | (pic4_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); for(i=0; i<8; i++){ block[i] = (pic3_bmp[i]&0xfe) >> 1 | (pic3_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); for(i=0; i<8; i++){ block[i] = (pic2_bmp[i]&0xfe) >> 1 | (pic2_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); for(i=0; i<8; i++){ block[i] = (pic1_bmp[i]&0xfe) >> 1 | (pic1_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); counter += 1; } // Demo 2 is showing... printf("Demo 2 is showing...\n"); while(q>=0){ j=0; while(j<=q){ //nested loop to make it work for(i=0; i<8; i++){ block[i] = (line_bmp[i]&0xfe) >> 1 | (line_bmp[i]&0x01) << 7; } res = i2c_smbus_write_i2c_block_data(file, daddress, 16, (__u8 *)block); usleep(500000); if(j<q){ tmp = line_bmp[j]; line_bmp[j] = line_bmp[j+1]; line_bmp[j+1] = tmp; } if(j==q){ line_bmp[0] = 0xFF; } j++; } q--; } daddress = 0x83;// Display off, blinking on printf("writing: 0x%02x\n", daddress); res = i2c_smbus_write_byte(file, daddress); usleep(3000000); daddress = 0x80;// Display off printf("writing: 0x%02x\n", daddress); res = i2c_smbus_write_byte(file, daddress);
The source code can be download from my github at: Mini-project 2 by Xia Li.
Demo of Animation
I uploaded a video demo of my animation to www.youtube.com. The link is: http://www.youtube.com/watch?v=sZkMx70ZvbI. Enjoy it and have fun!
Xia Li