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 Seeed

Committer:
tulanthoar
Date:
Fri Apr 21 13:47:19 2017 +0000
Revision:
8:09c844708255
Parent:
7:b16b9733d859
Child:
12:a16d86fac131
add fastio library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tulanthoar 7:b16b9733d859 1 #ifndef SEEED_LED_BAR_H
tulanthoar 7:b16b9733d859 2 #define SEEED_LED_BAR_H
tulanthoar 7:b16b9733d859 3 #include "mbed.h"
tulanthoar 7:b16b9733d859 4
tulanthoar 7:b16b9733d859 5 class SeeedLedBar {
tulanthoar 7:b16b9733d859 6 private:
tulanthoar 7:b16b9733d859 7 DigitalOut datPin_;
tulanthoar 7:b16b9733d859 8 DigitalOut clkPin_;
tulanthoar 7:b16b9733d859 9 void pin_delay(int delay_us = 2);
tulanthoar 7:b16b9733d859 10 static const int glbCmdMode_ = 0x00;
tulanthoar 7:b16b9733d859 11 void send_sixtn_bits(int sixtnBits);
tulanthoar 7:b16b9733d859 12 void set_leds(int ledPower[]);
tulanthoar 7:b16b9733d859 13 public:
tulanthoar 7:b16b9733d859 14 SeeedLedBar(PinName dataOut, PinName clockOut);
tulanthoar 7:b16b9733d859 15 void ten_on();
tulanthoar 7:b16b9733d859 16 void ten_off();
tulanthoar 7:b16b9733d859 17 void ten_set(int ledPower[]);
tulanthoar 7:b16b9733d859 18 };
tulanthoar 7:b16b9733d859 19
tulanthoar 7:b16b9733d859 20 SeeedLedBar::SeeedLedBar(PinName dataOut, PinName clockOut) : datPin_(dataOut), clkPin_(clockOut) { }
tulanthoar 7:b16b9733d859 21
tulanthoar 7:b16b9733d859 22 void SeeedLedBar::pin_delay(int delay_us) {
tulanthoar 7:b16b9733d859 23 wait_us(delay_us);
tulanthoar 7:b16b9733d859 24 }
tulanthoar 7:b16b9733d859 25
tulanthoar 7:b16b9733d859 26 void SeeedLedBar::send_sixtn_bits(int sixtnBits) {
tulanthoar 7:b16b9733d859 27 for (int i = 0; i < 16; i++) {
tulanthoar 7:b16b9733d859 28 pin_delay();
tulanthoar 7:b16b9733d859 29 datPin_ = sixtnBits & 0x8000;
tulanthoar 7:b16b9733d859 30 pin_delay();
tulanthoar 7:b16b9733d859 31 clkPin_ = !clkPin_;
tulanthoar 7:b16b9733d859 32 sixtnBits <<= 1;
tulanthoar 7:b16b9733d859 33 }
tulanthoar 7:b16b9733d859 34 }
tulanthoar 7:b16b9733d859 35
tulanthoar 7:b16b9733d859 36 void SeeedLedBar::set_leds(int ledPower[]) {
tulanthoar 7:b16b9733d859 37 send_sixtn_bits(glbCmdMode_);
tulanthoar 7:b16b9733d859 38 for (int i = 0; i < 10; i++) send_sixtn_bits(ledPower[i]);
tulanthoar 7:b16b9733d859 39 // Two extra empty bits for padding the command to the correct length
tulanthoar 7:b16b9733d859 40 send_sixtn_bits(0x00);
tulanthoar 7:b16b9733d859 41 send_sixtn_bits(0x00);
tulanthoar 7:b16b9733d859 42 pin_delay();
tulanthoar 7:b16b9733d859 43 datPin_ = 0;
tulanthoar 7:b16b9733d859 44 pin_delay();
tulanthoar 7:b16b9733d859 45 for (int i = 0; i < 4; i++) {
tulanthoar 7:b16b9733d859 46 pin_delay();
tulanthoar 7:b16b9733d859 47 datPin_ = 1;
tulanthoar 7:b16b9733d859 48 pin_delay();
tulanthoar 7:b16b9733d859 49 datPin_ = 0;
tulanthoar 7:b16b9733d859 50 }
tulanthoar 7:b16b9733d859 51 }
tulanthoar 7:b16b9733d859 52
tulanthoar 7:b16b9733d859 53 void SeeedLedBar::ten_on() {
tulanthoar 7:b16b9733d859 54 int all_on[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
tulanthoar 7:b16b9733d859 55 set_leds(all_on);
tulanthoar 7:b16b9733d859 56 }
tulanthoar 7:b16b9733d859 57
tulanthoar 7:b16b9733d859 58 void SeeedLedBar::ten_off() {
tulanthoar 7:b16b9733d859 59 int all_off[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
tulanthoar 7:b16b9733d859 60 set_leds(all_off);
tulanthoar 7:b16b9733d859 61 }
tulanthoar 7:b16b9733d859 62
tulanthoar 7:b16b9733d859 63 void SeeedLedBar::ten_set(int ledPower[]) {
tulanthoar 7:b16b9733d859 64 set_leds(ledPower);
tulanthoar 7:b16b9733d859 65 }
tulanthoar 7:b16b9733d859 66
tulanthoar 7:b16b9733d859 67 #endif