wiki:wade/embedded/arduino/example/example_3-3

回到 Arduino

Demo video

Source code

/*                           
 *              08 07 06 05 04 03 02 01
 *                                   *
 * 74HC595  PIN 09 10 11 12 13 14 15 16
 *                    SH ST    DS
 *                    棕 白    紫
 * Arduino  PIN       3  2     4 
 *     
 */
// display array size
#define display_array_size 128
// ascii 5x7 dot font
#define data_null 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // null char
#define data_ascii_A 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, 0x00, 0x00  // A 65
#define data_ascii_R 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00, 0x00  // R 82
#define data_ascii_D 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00, 0x00  // D 68
#define data_ascii_U 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00, 0x00  // U 85
#define data_ascii_I 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00, 0x00  // I 73
#define data_ascii_N 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00, 0x00  // N 78
#define data_ascii_O 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00, 0x00  // O 79
#define data_ascii_colon 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00  // : 58
// byte data_0[5]={0x03E, B00111110, 0x049, 0x045, 0x03E};
// display array 
byte data_ascii[][display_array_size] = {
                       data_null,
                       data_null,
                       data_null,
                       data_null,
                       data_ascii_A,
                       data_ascii_R,
                       data_ascii_D,
                       data_ascii_U,
                       data_ascii_I,
                       data_ascii_N,
                       data_ascii_O,
                       data_ascii_colon,
                       data_null,
                       data_null,
                       data_null,
                       data_null,
                       }; 

// Pin connected to ST_CP of 74HC595 for scanning
int scan_latch_pin = 5; // 白
// Pin connected to SH_CP of 74HC595 for scanning
int scan_clock_pin = 6; // 藍
// Pin connected to DS of 74HC595 for scanning
int scan_data_pin = 7; // 棕


void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(scan_latch_pin, OUTPUT);
  pinMode(scan_clock_pin, OUTPUT);
  pinMode(scan_data_pin, OUTPUT);
  Serial.begin(9600);
  
  //for (int i = 0; i < display_array_size; i++)
  //  data_ascii[0][i] ^= 0xFF;  
}

void loop() {
  for (int i = 1; i < (display_array_size - 32); i++ )
    display_led_from(i, 25);
}

void display_led_from(int index, int continue_time)
{
  //count up routine
  for (int k = 0; k < continue_time; k++)
  {
    for (int j = index; j < (index + 8); j++) {
      //ground scan_latch_pin and hold low for as long as you are transmitting
      digitalWrite(scan_latch_pin, LOW);
      
      
      //the data of second LED Matrix
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, byte((1 << (j-index)) ^ 0xFF));      
      //shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(1 << (j-index)));
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(data_ascii[0][j] ));
      
      //the data of second LED Matrix
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, byte((1 << (j-index)) ^ 0xFF));      
      //shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(1 << (j-index)));
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(data_ascii[0][j+8] ));
      
      //the data of second LED Matrix
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, byte((1 << (j-index)) ^ 0xFF));      
      //shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(1 << (j-index)));
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(data_ascii[0][j+16] ));
      
      
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, byte((1 << (j-index)) ^ 0xFF));
      //shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int( (1 << (j-index)) ) );
      shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, int(data_ascii[0][j+24] ));
      

      //return the latch pin high to signal chip that it 
      //no longer needs to listen for information
      digitalWrite(scan_latch_pin, HIGH);
      //Serial.print(1 << j-index, HEX);
      //Serial.print(" = ");
      //Serial.println(data_ascii[0][j], HEX);
      //delay(1000);
    }
  }
}

void scan_line()
{
  //count up routine
  for (int j = 1; j <= 256; j <<= 1) 
  {
    //ground scan_latch_pin and hold low for as long as you are transmitting
    digitalWrite(scan_latch_pin, LOW);
    shiftOut(scan_data_pin, scan_clock_pin, MSBFIRST, j);   
    //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(scan_latch_pin, HIGH);
    delay(500);
  }
}

Last modified 14 years ago Last modified on Mar 5, 2010, 2:33:57 PM