Nathan Yonkee / Mbed OS Seeed_Grove_4_Digit_Display_Clock

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:
Thu Apr 27 16:08:02 2017 -0600
Revision:
12:a16d86fac131
Parent:
7:b16b9733d859
Child:
15:abda719ba6e6
use a pin pair struct to avoid confusing data and clock pins

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