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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <algorithm>
00002 #include <cmath>
00003 #include "mbed.h"
00004 #include "rtos.h"
00005 #include "SeeedLedBar.h"
00006 #include "SeeedFourDigitDisp.h"
00007 #include "SeeedQTouch.h"
00008 #include "SeeedChainableLED.h"
00009 #include "SeeedIRTempSensor.h"
00010 
00011 namespace  {
00012 
00013 Serial pc(SERIAL_TX, SERIAL_RX);
00014 AnalogIn knob(PA_3);
00015 
00016 void blink_led() {
00017     for(DigitalOut led(PF_12);; Thread::wait(1000) ) {
00018         led = !led;
00019     }
00020 }
00021 } // namespace
00022 
00023 int main() {
00024     pc.printf("\n\nstarting algorithm\n\n");
00025     Thread heartbeat;
00026     heartbeat.start(callback(blink_led));
00027     DataClockPair chainablePins, rgbPins, qTouchPins, dispPins, ledBarPins, surrDispPins;
00028     surrDispPins.dataPin = PG_0;
00029     surrDispPins.clockPin = PG_1;
00030     ledBarPins.dataPin = PE_9;
00031     ledBarPins.clockPin = PF_13;
00032     dispPins.dataPin = PE_13;
00033     dispPins.clockPin = PF_15;
00034     qTouchPins.dataPin = PB_9;
00035     qTouchPins.clockPin = PB_8;
00036     rgbPins.dataPin = PG_14;
00037     rgbPins.clockPin = PG_9;
00038     chainablePins.clockPin = PF_14;
00039     chainablePins.dataPin = PE_11;
00040     SeeedLedBar ledBar(ledBarPins);
00041     SeeedFourDigitDisp disp(dispPins);
00042     SeeedFourDigitDisp surrDisp(surrDispPins);
00043     SeeedQTouch qTouch(qTouchPins);
00044     SeeedChainableLED led_chain(chainablePins);
00045     SeeedChainableLED rgb_led(rgbPins);
00046 
00047     disp.set_digit(0,0);
00048     int knob_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
00049     ledBar.ten_on();
00050     disp.clear_display();
00051     led_chain.turn_on();
00052     led_chain.set_color_rgb(100,50,0);
00053     rgb_led.set_color_rgb(50,200,10);
00054     for (;; Thread::wait(1000) ) {
00055         qTouch.key_touch(&pc);
00056         surrDisp.set_integer(floor(IRTempSensor::measureObjectTemp(PA_3, PC_0)));
00057         auto led_frac = knob.read();
00058         int led_percent = floor(led_frac * 100);
00059         int tens = floor(led_frac * 10);
00060         int ones = led_percent % 10;
00061         ones = floor(ones * 10 / 8);
00062         if (ones > 8) ones = 8;
00063         for (int i = 0; i < tens; ++i) knob_led_bar[i] = 0xff;
00064         knob_led_bar[tens] = ones * 0xf;
00065         for (int i = ++tens; i < 10; ++i) knob_led_bar[i] = 0x00;
00066         ledBar.ten_set(knob_led_bar);
00067         disp.set_integer(floor(IRTempSensor::measuresureTemp(PA_3)));
00068         /* disp.set_integer(led_percent); */
00069         int eightBitInput = led_frac * 255;
00070         led_chain.set_color_rgb(eightBitInput, eightBitInput, eightBitInput);
00071         rgb_led.set_color_rgb(50,eightBitInput,10);
00072     }
00073     return 1;
00074 }