fork of seeed studio 4-digit display for st nucleo board
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-21
- Revision:
- 8:09c844708255
- Parent:
- 7:b16b9733d859
- Child:
- 12:a16d86fac131
File content as of revision 8:09c844708255:
#ifndef SEEED_LED_BAR_H #define SEEED_LED_BAR_H #include "mbed.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(PinName dataOut, PinName clockOut); void ten_on(); void ten_off(); void ten_set(int ledPower[]); }; SeeedLedBar::SeeedLedBar(PinName dataOut, PinName clockOut) : datPin_(dataOut), clkPin_(clockOut) { } 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