|
|

楼主 |
发表于 2013-6-14 21:56:50
|
显示全部楼层
糯米基 发表于 2013-6-14 14:26 
他这是,三色点阵,每个595控制一种颜色,另一个595控制行,那是不是说列全部都接地了
还有,这个如何改成 ...
我只找到8x8和48x8单色点阵
8x8单色点阵

- /*
- * _8x8 LED matrix
- *
- * (c) 2009 BlushingBoy.net
- */
- #include "TimerOne.h"
- byte rows[8] = {9, 14, 8, 12, 1, 7, 2, 5};
- byte cols[8] = {13, 3, 4, 10, 6, 11, 15, 16};
- byte pins[16] = {5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
- byte screen[8] = {0, 0, 0, 0, 0, 0, 0, 0};
- volatile byte screenRow = 0;
- volatile byte screenCol = 0;
- void setup() {
- Timer1.initialize(100);
- for (int i = 2; i <= 17; i++)
- pinMode(i, OUTPUT);
- Timer1.attachInterrupt(doubleBuffer);
- }
- // interrupt routine
- void doubleBuffer() {
- // reset the previous iteration
- digitalWrite(translatePin(rows[screenRow]), HIGH); // set previous off
- digitalWrite(translatePin(cols[screenCol]), LOW); // set previous off
- // go to the next iteration...
- // go to the next screenCol, wrap if necessary
- screenCol++;
- if (screenCol >= 8) {
- screenCol = 0;
- // when screenCol wraps, go to the next screenRow, wrap if necessary
- screenRow++;
- if (screenRow >= 8) {
- screenRow = 0;
- }
- }
- // set this iteration
- if((screen[screenRow]>>screenCol)&B1 == B1) {
- digitalWrite(translatePin(rows[screenRow]), LOW); // set this on
- digitalWrite(translatePin(cols[screenCol]), HIGH); // set this on
- } else {
- digitalWrite(translatePin(rows[screenRow]), HIGH); // set this off
- digitalWrite(translatePin(cols[screenCol]), LOW); // set this off
- }
- }
- byte translatePin(byte original) {
- return pins[original - 1];
- }
- void allOFF() {
- for (int i = 0; i < 8; i++)
- screen[i]=0;
- }
- void on(byte row, byte column) {
- screen[column-1] |= (B1<<(row-1));
- }
- void off(byte row, byte column) {
- screen[column-1] &= ~(B1<<(row-1));
- }
- // looping some LEDs routine
- void loop() {
- allOFF();
- delay(1000);
- on(3,3); on(3,4); on(3,5); on(3,6);
- delay(400);
- allOFF();
- delay(1000);
- on(4,4);
- delay(400);
- }
-
复制代码
8x48单色点阵



- int x;
- int y;
- int latchPin1 = 5; //Arduino pin connected to blue 12 RCLK of 74HC595
- int clockPin1 = 6; //Arduino pin connected to green 11 SRCLK of 74HC595
- int dataPin1 = 7; //Arduino pin connected to violet 14 SER of 74HC595
- //-- Rows (Positive Anodes) --
- int latchPin2 = 9; //Arduino pin connected to yellow Latch 12 RCLK of 74HC595
- int clockPin2 = 10; //Arduino pin connected to white Clock 11 SRCLK of 74HC595
- int dataPin2 = 8; //Arduino pin connected to grey Data 14 SER of 74HC595
- //=== B I T M A P ===
- //Bits in this array represents one LED of the matrix
- // 8 is # of rows, 7 is # of LED matrix we have
- byte bitmap[8][7]; // Change the 7 to however many matrices you want to use.
- int numZones = sizeof(bitmap) / 8;
- int maxZoneIndex = numZones-1;
- int numCols = numZones * 8;
- byte alphabets[][5] = {
- {0,0,0,0,0},
- {31, 36, 68, 36, 31},
- {127, 73, 73, 73, 54},
- {62, 65, 65, 65, 34},
- {127, 65, 65, 34, 28},
- {127, 73, 73, 65, 65},
- {127, 72, 72, 72, 64},
- {62, 65, 65, 69, 38},
- {127, 8, 8, 8, 127},
- {0, 65, 127, 65, 0},
- {2, 1, 1, 1, 126},
- {127, 8, 20, 34, 65},
- {127, 1, 1, 1, 1},
- {127, 32, 16, 32, 127},
- {127, 32, 16, 8, 127},
- {62, 65, 65, 65, 62},
- {127, 72, 72, 72, 48},
- {62, 65, 69, 66, 61},
- {127, 72, 76, 74, 49},
- {50, 73, 73, 73, 38},
- {64, 64, 127, 64, 64},
- {126, 1, 1, 1, 126},
- {124, 2, 1, 2, 124},
- {126, 1, 6, 1, 126},
- {99, 20, 8, 20, 99},
- {96, 16, 15, 16, 96},
- {67, 69, 73, 81, 97},
- };
- //=== S E T U P ===
- void setup() {
- pinMode(latchPin1, OUTPUT);
- pinMode(clockPin1, OUTPUT);
- pinMode(dataPin1, OUTPUT);
- pinMode(latchPin2, OUTPUT);
- pinMode(clockPin2, OUTPUT);
- pinMode(dataPin2, OUTPUT);
-
- //-- Clear bitmap --
- for (int row = 0; row > 8; row++) {
- for (int zone = 0; zone <= maxZoneIndex; zone++) {
- bitmap[row][zone] = 0;
- }
- }
- }
- //=== F U N C T I O N S ===
- // This routine takes whatever we've setup in the bitmap array and display it on the matrix
- void RefreshDisplay()
- {
- for (int row = 0; row < 8; row++) {
- int rowbit = 1 << row;
- digitalWrite(latchPin2, LOW); //Hold latchPin LOW for as long as we're transmitting data
- shiftOut(dataPin2, clockPin2, MSBFIRST, rowbit); //Transmit data
- //-- Start sending column bytes --
- digitalWrite(latchPin1, LOW); //Hold latchPin LOW for as long as we're transmitting data
- //-- Shift out to each matrix (zone is 8 columns represented by one matrix)
- for (int zone = maxZoneIndex; zone >= 0; zone--) {
- shiftOut(dataPin1, clockPin1, MSBFIRST, bitmap[row][zone]);
- }
- //-- Done sending Column bytes, flip both latches at once to eliminate flicker
- digitalWrite(latchPin1, HIGH
- digitalWrite(latchPin2, HIGH
- //-- Wait a little bit to let humans see what we've pushed out onto the matrix --
- delayMicroseconds(500);
- }
- }
- // Converts row and colum to actual bitmap bit and turn it off/on
- void Plot(int col, int row, bool isOn)
- {
- int zone = col / 8;
- int colBitIndex = x % 8;
- byte colBit = 1 << colBitIndex;
- if (isOn)
- bitmap[row][zone] = bitmap[y][zone] | colBit;
- else
- bitmap[row][zone] = bitmap[y][zone] & (~colBit);
- }
- // Plot each character of the message one column at a time, updated the display, shift bitmap left.
- void AlphabetSoup()
- {
- char msg[] = "YOUR TEXT ";
- for (int charIndex=0; charIndex < (sizeof(msg)-1); charIndex++)
- {
- int alphabetIndex = msg[charIndex] - '@';
- if (alphabetIndex < 0) alphabetIndex=0;
-
- //-- Draw one character of the message --
- for (int col = 0; col < 6; col++)
- {
- for (int row = 0; row < 8; row++)
- {
- bool isOn = 0;
- if (col<5) isOn = bitRead( alphabets[alphabetIndex][col], 7-row ) == 1;
- Plot( numCols-1, row, isOn
- }
-
- //-- The more times you repeat this loop, the slower we would scroll --
- for (int refreshCount=0; refreshCount < 7; refreshCount++) //change this value to vary speed
- RefreshDisplay();
- //-- Shift the bitmap one column to left --
- for (int row=0; row<8; row++)
- {
- for (int zone=0; zone < numZones; zone++)
- {
- bitmap[row][zone] = bitmap[row][zone] >> 1;
- // Roll over lowest bit from the next zone as highest bit of this zone.
- if (zone < maxZoneIndex) bitWrite(bitmap[row][zone], 7,
- bitRead(bitmap[row][zone+1],0));
- }
- }
- }
- }
- }
- //=== L O O P ===
- void loop() {
- AlphabetSoup();
- }
复制代码
|
|