Kazuhiro Ouchi
/
3wire_led_module_sample1
DFROBOT 3-Wire LED Module sample program.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 //Pin connected to Data in (DS) of 74HC595 00004 DigitalOut dataPin(dp9); 00005 //Pin connected to latch pin (ST_CP) of 74HC595 00006 DigitalOut latchPin(dp10); 00007 //Pin connected to clock pin (SH_CP) of 74HC595 00008 DigitalOut clockPin(dp11); 00009 00010 uint8_t Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; 00011 00012 void shiftOut(DigitalOut data, DigitalOut clk, int sdata) { 00013 for (int i = 7; i >= 0; i--) { 00014 clk = 0; 00015 if(sdata & (1 << i)){ 00016 data = 1; 00017 } else { 00018 data = 0; 00019 } 00020 clk = 1; 00021 data = 0; 00022 } 00023 } 00024 00025 void leddisp(long n){ 00026 char disp[9]; 00027 00028 sprintf(disp, "%08d¥n", n); 00029 00030 for (int c = 8; c >= 0 ;c--){ 00031 // write to the shift register with the correct bit set high: 00032 latchPin = 0; 00033 // shift the bits out: 00034 shiftOut(dataPin, clockPin, Tab[disp[c] - 48]); 00035 // turn on the output so the LEDs can light up: 00036 latchPin = 1; 00037 } 00038 } 00039 00040 int main() { 00041 long number = 0; 00042 while(1) { 00043 leddisp(number++); 00044 if (number > 99999999) { 00045 number = 0; 00046 } 00047 wait(0.1); 00048 } 00049 }
Generated on Wed Jul 13 2022 11:41:15 by 1.7.2