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

Revision:
12:a16d86fac131
Parent:
7:b16b9733d859
Child:
15:abda719ba6e6
--- a/SeeedFourDigitDisp.h	Fri Apr 21 13:47:19 2017 +0000
+++ b/SeeedFourDigitDisp.h	Thu Apr 27 16:08:02 2017 -0600
@@ -1,6 +1,7 @@
 #ifndef SEEED_FOUR_DIGIT_DISP_H
 #define SEEED_FOUR_DIGIT_DISP_H
 #include "mbed.h"
+#include "DataClockPair.h"
 
 class SeeedFourDigitDisp {
   private:
@@ -23,10 +24,10 @@
     void set_integer(int value);
     void clear_display();
     void turn_on();
-    SeeedFourDigitDisp (PinName dataOut, PinName clockOut);
+    SeeedFourDigitDisp (DataClockPair pins);
 };
 
-SeeedFourDigitDisp::SeeedFourDigitDisp(PinName dataOut, PinName clockOut) : datPin_(dataOut), clkPin_(clockOut) {
+SeeedFourDigitDisp::SeeedFourDigitDisp(DataClockPair pins) : datPin_(pins.dataPin, 1), clkPin_(pins.clockPin, 1) {
     brightness = 7;
     colonFlag = false;
     const int digits[] = {0x3f, 0x06, 0x5b, 0x4f,
@@ -35,29 +36,39 @@
                           0x39, 0x5e, 0x79, 0x71,
                           0x00
                          }; //0~9,A,b,C,d,E,F,null
-    for (int i = 0; i < 17; i++) {
+    for (int i = 0; i < 17; ++i) {
         digitTable_[i] = digits[i];
     }
     clear_display();
 }
 
+void SeeedFourDigitDisp::pin_delay(int delay_us) {
+    wait_us(delay_us);
+}
+
 void SeeedFourDigitDisp::start_cmd() {
-    datPin_ = 0;
+    datPin_ = !datPin_;
 }
 
 void SeeedFourDigitDisp::stop_cmd() {
-    clkPin_ = 0;
     datPin_ = 0;
+    clkPin_ = !clkPin_;
     pin_delay();
-    clkPin_ = 1;
-    datPin_ = 1;
+    clkPin_ = !clkPin_;
+    datPin_ = !datPin_;
 }
 
-void SeeedFourDigitDisp::clear_display() {
-    set_digit(0,nullDigit_);
-    set_digit(1,nullDigit_);
-    set_digit(2,nullDigit_);
-    set_digit(3,nullDigit_);
+void SeeedFourDigitDisp::send_byte(int byte) {
+    byte |= 0x100; // bring data high for ack after 8 bits
+    for (int i = 0; i < 9; ++i) {
+        pin_delay();
+        clkPin_ = !clkPin_;
+        pin_delay();
+        datPin_ = byte & 1;
+        byte >>= 1;
+        pin_delay();
+        clkPin_ = !clkPin_;
+    }
 }
 
 void SeeedFourDigitDisp::set_digit(int pos, int digit) {
@@ -72,9 +83,22 @@
     start_cmd();
     send_byte(onByte_ + brightness);
     stop_cmd();
+}
 
+void SeeedFourDigitDisp::turn_on() {
+    start_cmd();
+    send_byte(onByte_+brightness);
+    stop_cmd();
 }
 
+void SeeedFourDigitDisp::clear_display() {
+    set_digit(0,nullDigit_);
+    set_digit(1,nullDigit_);
+    set_digit(2,nullDigit_);
+    set_digit(3,nullDigit_);
+}
+
+
 void SeeedFourDigitDisp::set_integer(int value) {
     clear_display();
     if( value < 0 ) {
@@ -96,27 +120,5 @@
     }
 }
 
-void SeeedFourDigitDisp::turn_on() {
-    start_cmd();
-    send_byte(onByte_+brightness);
-    stop_cmd();
-}
-
-void SeeedFourDigitDisp::pin_delay(int delay_us) {
-    wait_us(delay_us);
-}
-
-void SeeedFourDigitDisp::send_byte(int byte) {
-    byte |= 0x100; // bring data high for ack after 8 bits
-    for (uint8_t i = 0; i < 9; i++) {
-        pin_delay();
-        clkPin_ = 0;
-        pin_delay();
-        datPin_ = byte & 1;
-        pin_delay();
-        byte >>= 1;
-        clkPin_ = 1;
-    }
-}
 
 #endif