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

Committer:
tulanthoar
Date:
Sun May 21 13:33:34 2017 -0600
Revision:
17:71c14845db51
Parent:
15:abda719ba6e6
Child:
20:2e72ddd68cda
use infinite for loop and embed the delay in the loop declaration

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tulanthoar 4:d540dccad60a 1 #include <algorithm>
tulanthoar 4:d540dccad60a 2 #include <cmath>
tulanthoar 4:d540dccad60a 3 #include "mbed.h"
tulanthoar 7:b16b9733d859 4 #include "rtos.h"
tulanthoar 6:14929f54ed6f 5 #include "SeeedLedBar.h"
tulanthoar 6:14929f54ed6f 6 #include "SeeedFourDigitDisp.h"
tulanthoar 6:14929f54ed6f 7 #include "SeeedQTouch.h"
tulanthoar 6:14929f54ed6f 8 #include "SeeedChainableLED.h"
tulanthoar 15:abda719ba6e6 9 #include "SeeedIRTempSensor.h"
tulanthoar 15:abda719ba6e6 10
tulanthoar 15:abda719ba6e6 11 namespace {
tulanthoar 4:d540dccad60a 12
tulanthoar 3:c4427ce4d171 13 Serial pc(SERIAL_TX, SERIAL_RX);
tulanthoar 4:d540dccad60a 14 AnalogIn knob(PA_3);
tulanthoar 3:c4427ce4d171 15
tulanthoar 17:71c14845db51 16 void blink_led() {
tulanthoar 17:71c14845db51 17 for(DigitalOut led(PF_12);; Thread::wait(1000) ) {
tulanthoar 17:71c14845db51 18 led = !led
tulanthoar 7:b16b9733d859 19 }
tulanthoar 7:b16b9733d859 20 }
tulanthoar 15:abda719ba6e6 21 } // namespace
tulanthoar 7:b16b9733d859 22
tulanthoar 6:14929f54ed6f 23 int main() {
tulanthoar 6:14929f54ed6f 24 pc.printf("\n\nstarting algorithm\n\n");
tulanthoar 17:71c14845db51 25 Thread heartbeat;
tulanthoar 17:71c14845db51 26 heartbeat.start(callback(blink_led));
tulanthoar 15:abda719ba6e6 27 DataClockPair chainablePins, rgbPins, qTouchPins, dispPins, ledBarPins, surrDispPins;
tulanthoar 15:abda719ba6e6 28 surrDispPins.dataPin = PG_0;
tulanthoar 15:abda719ba6e6 29 surrDispPins.clockPin = PG_1;
tulanthoar 12:a16d86fac131 30 ledBarPins.dataPin = PE_9;
tulanthoar 12:a16d86fac131 31 ledBarPins.clockPin = PF_13;
tulanthoar 12:a16d86fac131 32 dispPins.dataPin = PE_13;
tulanthoar 12:a16d86fac131 33 dispPins.clockPin = PF_15;
tulanthoar 12:a16d86fac131 34 qTouchPins.dataPin = PB_9;
tulanthoar 12:a16d86fac131 35 qTouchPins.clockPin = PB_8;
tulanthoar 12:a16d86fac131 36 rgbPins.dataPin = PG_14;
tulanthoar 12:a16d86fac131 37 rgbPins.clockPin = PG_9;
tulanthoar 12:a16d86fac131 38 chainablePins.clockPin = PF_14;
tulanthoar 12:a16d86fac131 39 chainablePins.dataPin = PE_11;
tulanthoar 12:a16d86fac131 40 SeeedLedBar ledBar(ledBarPins);
tulanthoar 12:a16d86fac131 41 SeeedFourDigitDisp disp(dispPins);
tulanthoar 15:abda719ba6e6 42 SeeedFourDigitDisp surrDisp(surrDispPins);
tulanthoar 12:a16d86fac131 43 SeeedQTouch qTouch(qTouchPins);
tulanthoar 12:a16d86fac131 44 SeeedChainableLED led_chain(chainablePins);
tulanthoar 12:a16d86fac131 45 SeeedChainableLED rgb_led(rgbPins);
tulanthoar 3:c4427ce4d171 46
tulanthoar 6:14929f54ed6f 47 disp.set_digit(0,0);
tulanthoar 4:d540dccad60a 48 int knob_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
tulanthoar 6:14929f54ed6f 49 ledBar.ten_on();
tulanthoar 6:14929f54ed6f 50 disp.clear_display();
tulanthoar 6:14929f54ed6f 51 led_chain.turn_on();
tulanthoar 12:a16d86fac131 52 led_chain.set_color_rgb(100,50,0);
tulanthoar 12:a16d86fac131 53 rgb_led.set_color_rgb(50,200,10);
tulanthoar 17:71c14845db51 54 for (;; Thread::wait(1000) ) {
tulanthoar 12:a16d86fac131 55 qTouch.key_touch(&pc);
tulanthoar 15:abda719ba6e6 56 surrDisp.set_integer(floor(IRTempSensor::measureObjectTemp(PA_3, PC_0)));
tulanthoar 15:abda719ba6e6 57 auto led_frac = knob.read();
tulanthoar 4:d540dccad60a 58 int led_percent = floor(led_frac * 100);
tulanthoar 4:d540dccad60a 59 int tens = floor(led_frac * 10);
tulanthoar 4:d540dccad60a 60 int ones = led_percent % 10;
tulanthoar 4:d540dccad60a 61 ones = floor(ones * 10 / 8);
tulanthoar 4:d540dccad60a 62 if (ones > 8) ones = 8;
tulanthoar 6:14929f54ed6f 63 for (int i = 0; i < tens; ++i) knob_led_bar[i] = 0xff;
tulanthoar 7:b16b9733d859 64 knob_led_bar[tens] = ones * 0xf;
tulanthoar 7:b16b9733d859 65 for (int i = ++tens; i < 10; ++i) knob_led_bar[i] = 0x00;
tulanthoar 6:14929f54ed6f 66 ledBar.ten_set(knob_led_bar);
tulanthoar 15:abda719ba6e6 67 disp.set_integer(floor(IRTempSensor::measuresureTemp(PA_3)));
tulanthoar 15:abda719ba6e6 68 /* disp.set_integer(led_percent); */
tulanthoar 6:14929f54ed6f 69 int eightBitInput = led_frac * 255;
tulanthoar 6:14929f54ed6f 70 led_chain.set_color_rgb(eightBitInput, eightBitInput, eightBitInput);
tulanthoar 15:abda719ba6e6 71 rgb_led.set_color_rgb(50,eightBitInput,10);
tulanthoar 4:d540dccad60a 72 }
tulanthoar 15:abda719ba6e6 73 return 1;
tulanthoar 4:d540dccad60a 74 }