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
Diff: main.cpp
- Revision:
- 7:b16b9733d859
- Parent:
- 6:14929f54ed6f
- Child:
- 12:a16d86fac131
diff -r 14929f54ed6f -r b16b9733d859 main.cpp --- a/main.cpp Thu Apr 20 11:19:18 2017 -0600 +++ b/main.cpp Fri Apr 21 07:34:25 2017 -0600 @@ -1,15 +1,23 @@ #include <algorithm> #include <cmath> #include "mbed.h" +#include "rtos.h" #include "SeeedLedBar.h" #include "SeeedFourDigitDisp.h" #include "SeeedQTouch.h" #include "SeeedChainableLED.h" Serial pc(SERIAL_TX, SERIAL_RX); -DigitalOut led(LED1); +DigitalOut led(PF_12); AnalogIn knob(PA_3); +void led_thread(void const* args) { + while(1) { + led = !led; + Thread::wait(1000); + } +} + int main() { pc.printf("\n\nstarting algorithm\n\n"); SeeedLedBar ledBar = SeeedLedBar(PE_9, PF_13); @@ -17,6 +25,7 @@ SeeedQTouch qTouch = SeeedQTouch(PB_9, PB_8); SeeedChainableLED led_chain = SeeedChainableLED(PE_11, PF_14); + Thread blinky(led_thread); disp.set_digit(0,0); int knob_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -25,21 +34,19 @@ led_chain.turn_on(); led_chain.set_color_rgb(100,200,100); while (1) { - led = !led; float led_frac = knob.read(); int led_percent = floor(led_frac * 100); int tens = floor(led_frac * 10); int ones = led_percent % 10; ones = floor(ones * 10 / 8); if (ones > 8) ones = 8; - int ones_led = ones * 16; - for (int i = 0; i < 10; ++i) knob_led_bar[i] = 0x00; for (int i = 0; i < tens; ++i) knob_led_bar[i] = 0xff; - knob_led_bar[tens] = ones_led; + knob_led_bar[tens] = ones * 0xf; + for (int i = ++tens; i < 10; ++i) knob_led_bar[i] = 0x00; ledBar.ten_set(knob_led_bar); - disp.set_digit(2,tens); - disp.set_digit(3,ones); + disp.set_integer(led_percent); int eightBitInput = led_frac * 255; led_chain.set_color_rgb(eightBitInput, eightBitInput, eightBitInput); + Thread::wait(10); } }