Alex Leung
/
HealthTracker
Test version
Diff: LEDS.cpp
- Revision:
- 0:4be500de690c
diff -r 000000000000 -r 4be500de690c LEDS.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LEDS.cpp Tue Mar 20 02:09:21 2018 +0000 @@ -0,0 +1,36 @@ +#include "LEDS.h" +#include "mbed.h" + +BusOut ctrl(PA_9,PA_8,PB_10,PB_4); +BusOut leds(PA_13,PA_14,PA_15,PA_5,PA_6,PA_7,PB_6,PC_7); +int num_arr[10] = {252,96,218,242,102,182,190,224,254,250}; + +int pow(int num, int pow){ + int res = 1; + if(pow<1){ + return 1; + } + for(int i = 1;i<=pow;i++){ + res *= num; + } + return res; +} + +void LightLEDs(float num){ + int a[4]; + a[3] = num / 100; + a[2] = num / 10 - a[3] * 10; + a[1] = num - a[3] * 100 - a[2] * 10; + a[0] = num * 10 - a[3] * 1000 - a[2] * 100 - a[1] * 10; + for (int i = 3; i > 0; i--) + { + ctrl = pow(2,i); + if(i == 1){ + leds = num_arr[a[i]] + 1; + }else{ + leds = num_arr[a[i]]; + } + wait(0.01); + } +} +