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.
Dependencies: Data_Clock_Pair Seeed_Chainable_LED Seeed_Four_Digit_Disp Seeed_IR_Temp_Sensor Seeed_Led_Bar
Fork of Seeed_Grove_4_Digit_Display_Clock by
SeeedLedBar.h
- Committer:
- tulanthoar
- Date:
- 2017-04-27
- Revision:
- 12:a16d86fac131
- Parent:
- 7:b16b9733d859
- Child:
- 15:abda719ba6e6
File content as of revision 12:a16d86fac131:
#ifndef SEEED_LED_BAR_H #define SEEED_LED_BAR_H #include "mbed.h" #include "DataClockPair.h" class SeeedLedBar { private: DigitalOut datPin_; DigitalOut clkPin_; void pin_delay(int delay_us = 2); static const int glbCmdMode_ = 0x00; void send_sixtn_bits(int sixtnBits); void set_leds(int ledPower[]); public: SeeedLedBar(DataClockPair pins); void ten_on(); void ten_off(); void ten_set(int ledPower[]); }; SeeedLedBar::SeeedLedBar(DataClockPair pins) : datPin_(pins.dataPin), clkPin_(pins.clockPin) { } void SeeedLedBar::pin_delay(int delay_us) { wait_us(delay_us); } void SeeedLedBar::send_sixtn_bits(int sixtnBits) { for (int i = 0; i < 16; i++) { pin_delay(); datPin_ = sixtnBits & 0x8000; pin_delay(); clkPin_ = !clkPin_; sixtnBits <<= 1; } } void SeeedLedBar::set_leds(int ledPower[]) { send_sixtn_bits(glbCmdMode_); for (int i = 0; i < 10; i++) send_sixtn_bits(ledPower[i]); // Two extra empty bits for padding the command to the correct length send_sixtn_bits(0x00); send_sixtn_bits(0x00); pin_delay(); datPin_ = 0; pin_delay(); for (int i = 0; i < 4; i++) { pin_delay(); datPin_ = 1; pin_delay(); datPin_ = 0; } } void SeeedLedBar::ten_on() { int all_on[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; set_leds(all_on); } void SeeedLedBar::ten_off() { int all_off[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; set_leds(all_off); } void SeeedLedBar::ten_set(int ledPower[]) { set_leds(ledPower); } #endif