Fahrudin Brbutovic Adnan Mehanovic

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 using namespace std;
00004 
00005 BusOut segments(dp2, dp1, dp28, dp6, dp5, dp27, dp26);
00006 BusOut digit(dp23, dp24, dp25);
00007 DigitalOut decimal_point(dp4);
00008 AnalogIn voltage(dp9);
00009 
00010 
00011 int predefined_segments[10] = {0x01, 0x4f, 0x12, 0x06, 0x4c, 0x24, 0x20, 0x0f, 0x00, 0x04};
00012 
00013 void display(float vtg)
00014 {
00015     
00016     int digits[3] = {(int)(vtg / 100) % 10, (int)(vtg / 10) % 10, (int)(vtg) % 10};
00017     for(int i = 1; i <= 4; i = i * 2) {
00018         segments = predefined_segments[digits[i / 2]];
00019         digit = ~i;
00020         decimal_point = (i == 1) ? 0 : 1;
00021         wait_ms(1);
00022     }
00023 }
00024 
00025 int main()
00026 {
00027     while(1) {
00028         display(voltage * 3.3 * 100);
00029     }
00030 }