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:
6:14929f54ed6f
Parent:
5:d28207a2d2a6
Child:
7:b16b9733d859
--- a/main.cpp	Tue Apr 11 09:14:06 2017 -0600
+++ b/main.cpp	Thu Apr 20 11:19:18 2017 -0600
@@ -1,103 +1,45 @@
 #include <algorithm>
 #include <cmath>
 #include "mbed.h"
+#include "SeeedLedBar.h"
+#include "SeeedFourDigitDisp.h"
+#include "SeeedQTouch.h"
+#include "SeeedChainableLED.h"
 
 Serial pc(SERIAL_TX, SERIAL_RX);
-DigitalOut clk(PE_9);
-DigitalOut dat(PE_11);
-DigitalOut   led(LED1);
+DigitalOut led(LED1);
 AnalogIn knob(PA_3);
 
-// Avoid name conflict
-#define LED_GLB_CMDMODE 0x00  // Work on 8-bit mode
-#define LED_GLB_ON      0xff  // 8-bit 1 data
-#define LED_GLB_OFF     0x00  // 8-bit 0 data
-
-// Send 16 bits of data
-void sendData(unsigned int data)
-{
-    for (int i = 0; i < 16; i++)
-    {
-        wait_us(10);
-        unsigned int state = (data & 0x8000) ? 1 : 0;
-        dat = state;
-
-        wait_us(10);
-        clk = !clk;
-
-        data <<= 1;
-    }
-}
-
-// Send the latch command
-void latchData()
-{
-    dat = 0;
-    wait_us(100);
-
-    for (int i = 0; i < 4; i++)
-    {
-        wait_us(10);
-        dat = 1;
-        wait_us(10);
-        dat = 0;
-    }
-}
-
-// each element in the state will hold the brightness level
-// 00000000 darkest
-// 00000011 brighter
-// ........
-// 11111111 brightest
-void setData(int __state[])
-{
-
-    sendData(LED_GLB_CMDMODE);
-    for (int i = 0; i < 10; i++)
-    {
-        // Go forward on __state
-        sendData(__state[i]);
-    }
-
-    // Two extra empty bits for padding the command to the correct length
-    sendData(0x00);
-    sendData(0x00);
-
-    latchData();
-}
+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);
 
 
-
-int main()
-{
-    pc.printf("\n\nstarting algorithm\n\n");
-    int led_bar[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-    int not_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+    disp.set_digit(0,0);
     int knob_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-    setData(led_bar);
-    while (1)
-    {
+    ledBar.ten_on();
+    disp.clear_display();
+    led_chain.turn_on();
+    led_chain.set_color_rgb(100,200,100);
+    while (1) {
+        led = !led;
         float led_frac = knob.read();
-        pc.printf("knob is %f\n", led_frac);
         int led_percent = floor(led_frac * 100);
         int tens = floor(led_frac * 10);
-        pc.printf("percent is %i\n", led_percent);
         int ones = led_percent % 10;
         ones = floor(ones * 10 / 8);
         if (ones > 8) ones = 8;
         int ones_led = ones * 16;
-        pc.printf("tens is %i\n", tens);
         for (int i = 0; i < 10; ++i) knob_led_bar[i] = 0x00;
-        for (int i = 0; i < tens; ++i)
-            knob_led_bar[i] = 0xff;
+        for (int i = 0; i < tens; ++i) knob_led_bar[i] = 0xff;
         knob_led_bar[tens] = ones_led;
-        setData(led_bar);
-        wait_ms(100);
-        setData(knob_led_bar);
-        wait_ms(100);
-        setData(not_led_bar);
-        pc.printf("iteration\n");
-        led = !led;
-        wait_ms(100);
+        ledBar.ten_set(knob_led_bar);
+        disp.set_digit(2,tens);
+        disp.set_digit(3,ones);
+        int eightBitInput = led_frac * 255;
+        led_chain.set_color_rgb(eightBitInput, eightBitInput, eightBitInput);
     }
 }