Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Seeed_Grove_4_Digit_Display_Clock
SeeedLedBar.h
00001 #ifndef SEEED_LED_BAR_H 00002 #define SEEED_LED_BAR_H 00003 #include "mbed.h" 00004 #include "DataClockPair.h" 00005 00006 class SeeedLedBar { 00007 private: 00008 DigitalOut datPin_; 00009 DigitalOut clkPin_; 00010 void pin_delay(int delay_us = 2); 00011 static const int glbCmdMode_ = 0x00; 00012 void send_sixtn_bits(int sixtnBits); 00013 void set_leds(int (&ledPower )[10]); 00014 public: 00015 SeeedLedBar(DataClockPair pins); 00016 void ten_on(); 00017 void ten_off(); 00018 void ten_set(int (&ledPower )[10]); 00019 }; 00020 00021 SeeedLedBar::SeeedLedBar(DataClockPair pins) : datPin_(pins.dataPin), clkPin_(pins.clockPin) { } 00022 00023 void SeeedLedBar::pin_delay(int delay_us) { 00024 wait_us(delay_us); 00025 } 00026 00027 void SeeedLedBar::send_sixtn_bits(int sixtnBits) { 00028 for (int i = 0; i < 16; i++) { 00029 pin_delay(); 00030 datPin_ = sixtnBits & 0x8000; 00031 sixtnBits <<= 1; 00032 pin_delay(); 00033 clkPin_ = !clkPin_; 00034 } 00035 } 00036 00037 void SeeedLedBar::set_leds(int (&ledPower )[10]) { 00038 send_sixtn_bits(glbCmdMode_); 00039 for (auto& i : ledPower) send_sixtn_bits(i); 00040 // Two extra empty bits for padding the command to the correct length 00041 send_sixtn_bits(0x00); 00042 send_sixtn_bits(0x00); 00043 pin_delay(); 00044 datPin_ = 0; 00045 pin_delay(); 00046 for (int i = 0; i < 4; i++) { 00047 pin_delay(); 00048 datPin_ = 1; 00049 pin_delay(); 00050 datPin_ = 0; 00051 } 00052 } 00053 00054 void SeeedLedBar::ten_on() { 00055 int all_on[10] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 00056 set_leds(all_on); 00057 } 00058 00059 void SeeedLedBar::ten_off() { 00060 int all_off[10] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 00061 set_leds(all_off); 00062 } 00063 00064 void SeeedLedBar::ten_set(int (&ledPower )[10]) { 00065 set_leds(ledPower); 00066 } 00067 00068 #endif
Generated on Wed Jul 13 2022 02:58:11 by
1.7.2