Test version

LEDS.cpp

Committer:
a2824256
Date:
2018-03-20
Revision:
1:bd9f39f9d91c
Parent:
0:4be500de690c

File content as of revision 1:bd9f39f9d91c:

#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);
    }
}