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

Files at this revision

API Documentation at this revision

Comitter:
tulanthoar
Date:
Thu Apr 27 16:08:02 2017 -0600
Parent:
8:09c844708255
Child:
13:0f5c622b00bd
Commit message:
use a pin pair struct to avoid confusing data and clock pins

Changed in this revision

SeeedChainableLED.h Show annotated file Show diff for this revision Revisions of this file
SeeedFourDigitDisp.h Show annotated file Show diff for this revision Revisions of this file
SeeedLedBar.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/SeeedChainableLED.h	Fri Apr 21 13:47:19 2017 +0000
+++ b/SeeedChainableLED.h	Thu Apr 27 16:08:02 2017 -0600
@@ -8,6 +8,7 @@
 #ifndef SEEED_CHAINABLE_LED_H
 #define SEEED_CHAINABLE_LED_H
 #include "mbed.h"
+#include "DataClockPair.h"
 
 class SeeedChainableLED {
   private:
@@ -22,10 +23,10 @@
     void set_color_rgb(int r, int g, int b, int led = 0);
     void clear_led();
     void turn_on();
-    SeeedChainableLED (PinName dataOut, PinName clockOut);
+    SeeedChainableLED (DataClockPair pins);
 };
 
-SeeedChainableLED::SeeedChainableLED(PinName dataOut, PinName clockOut) : datPin_(dataOut), clkPin_(clockOut) {
+SeeedChainableLED::SeeedChainableLED(DataClockPair pins) : datPin_(pins.dataPin), clkPin_(pins.clockPin) {
     clear_led();
 }
 
--- 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
--- a/SeeedLedBar.h	Fri Apr 21 13:47:19 2017 +0000
+++ b/SeeedLedBar.h	Thu Apr 27 16:08:02 2017 -0600
@@ -1,6 +1,7 @@
 #ifndef SEEED_LED_BAR_H
 #define SEEED_LED_BAR_H
 #include "mbed.h"
+#include "DataClockPair.h"
 
 class SeeedLedBar {
   private:
@@ -11,13 +12,13 @@
     void send_sixtn_bits(int sixtnBits);
     void set_leds(int ledPower[]);
   public:
-    SeeedLedBar(PinName dataOut, PinName clockOut);
+    SeeedLedBar(DataClockPair pins);
     void ten_on();
     void ten_off();
     void ten_set(int ledPower[]);
 };
 
-SeeedLedBar::SeeedLedBar(PinName dataOut, PinName clockOut) : datPin_(dataOut), clkPin_(clockOut) { }
+SeeedLedBar::SeeedLedBar(DataClockPair pins) : datPin_(pins.dataPin), clkPin_(pins.clockPin) { }
 
 void SeeedLedBar::pin_delay(int delay_us) {
     wait_us(delay_us);
--- a/main.cpp	Fri Apr 21 13:47:19 2017 +0000
+++ b/main.cpp	Thu Apr 27 16:08:02 2017 -0600
@@ -20,10 +20,22 @@
 
 int main() {
     pc.printf("\n\nstarting algorithm\n\n");
-    SeeedLedBar ledBar = SeeedLedBar(PE_9, PF_13);
-    SeeedFourDigitDisp disp = SeeedFourDigitDisp(PE_13, PF_15);
-    SeeedQTouch qTouch = SeeedQTouch(PB_9, PB_8);
-    SeeedChainableLED led_chain = SeeedChainableLED(PE_11, PF_14);
+    DataClockPair chainablePins, rgbPins, qTouchPins, dispPins, ledBarPins;
+    ledBarPins.dataPin = PE_9;
+    ledBarPins.clockPin = PF_13;
+    dispPins.dataPin = PE_13;
+    dispPins.clockPin = PF_15;
+    qTouchPins.dataPin = PB_9;
+    qTouchPins.clockPin = PB_8;
+    rgbPins.dataPin = PG_14;
+    rgbPins.clockPin = PG_9;
+    chainablePins.clockPin = PF_14;
+    chainablePins.dataPin = PE_11;
+    SeeedLedBar ledBar(ledBarPins);
+    SeeedFourDigitDisp disp(dispPins);
+    SeeedQTouch qTouch(qTouchPins);
+    SeeedChainableLED led_chain(chainablePins);
+    SeeedChainableLED rgb_led(rgbPins);
 
     Thread blinky(led_thread);
 
@@ -32,8 +44,10 @@
     ledBar.ten_on();
     disp.clear_display();
     led_chain.turn_on();
-    led_chain.set_color_rgb(100,200,100);
+    led_chain.set_color_rgb(100,50,0);
+    rgb_led.set_color_rgb(50,200,10);
     while (1) {
+        qTouch.key_touch(&pc);
         float led_frac = knob.read();
         int led_percent = floor(led_frac * 100);
         int tens = floor(led_frac * 10);
@@ -47,6 +61,6 @@
         disp.set_integer(led_percent);
         int eightBitInput = led_frac * 255;
         led_chain.set_color_rgb(eightBitInput, eightBitInput, eightBitInput);
-        Thread::wait(10);
+        Thread::wait(2000);
     }
 }