Granulo Eldar Hasanic Nadin

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 #define EYE_WAIT_TIME 10
00004 
00005 Ticker tick1, tick2, tick3;
00006 Timer timer;
00007 
00008 BusOut segments(dp18, dp4, dp28, dp6, dp5, dp27, dp26);
00009 BusOut digit(dp23, dp24, dp25);
00010 DigitalOut decimal_point(dp17);
00011 
00012 InterruptIn taster1(dp1);
00013 InterruptIn taster2(dp2);
00014 
00015 int digit_buffer[3] = {0, 0, 0};
00016 unsigned int predefined_segments[19] = {0x01, 0x4f, 0x12, 0x06, 0x4c, 
00017                                 0x24, 0x20, 0x0f, 0x00, 0x04,
00018                                 0x08,0x60,0x31,0x42,0x30,0x38,
00019                                 ~(0x01), 0x36, ~0};
00020 
00021 void display_number() {
00022     float num = timer.read();
00023     unsigned const int digit_buffer[3] = {(int)(num / 10) % 10,(int)(num) % 10,(int)(num * 10) % 10};
00024 
00025     for(int i = 1; i <= 4; i = i * 2) {
00026         digit = ~i;
00027         segments = predefined_segments[ digit_buffer[i / 2] ];
00028         decimal_point = !(i == 2);
00029        
00030     }
00031 }
00032 
00033 void display_first() {
00034     __disable_irq();
00035     float num = timer.read();
00036     unsigned const int digit_buffer[3] = {
00037                     (int)(num / 10) % 10,
00038                     (int)(num) % 10,
00039                     (int)(num * 10) % 10
00040                     };
00041     int i = 1;
00042     digit = ~i;
00043     segments = predefined_segments[ digit_buffer[i / 2] ];
00044     decimal_point = !(i == 2);
00045     __enable_irq();
00046 }
00047 
00048 void display_second() {
00049     __disable_irq();
00050     float num = timer.read();
00051     unsigned const int digit_buffer[3] = {
00052                     (int)(num / 10) % 10,
00053                     (int)(num) % 10,
00054                     (int)(num * 10) % 10
00055                     };
00056     int i = 2;
00057     digit = ~i;
00058     segments = predefined_segments[ digit_buffer[i / 2] ];
00059     decimal_point = !(i == 2);
00060     __enable_irq();
00061 }
00062 
00063 void display_third() {
00064     __disable_irq();
00065     float num = timer.read();
00066     unsigned const int digit_buffer[3] = {
00067                     (int)(num / 10) % 10,
00068                     (int)(num) % 10,
00069                     (int)(num * 10) % 10
00070                     };
00071     int i = 4;
00072     digit = ~i;
00073     segments = predefined_segments[ digit_buffer[i / 2] ];
00074     decimal_point = !(i == 2);
00075     __enable_irq();
00076 }
00077 
00078 int i = 0;
00079 void pause() {
00080     __disable_irq();
00081     (i++ % 2 == 0) ? timer.stop() : timer.start();   
00082     __enable_irq();   
00083 }
00084 
00085 
00086 void restart()
00087 {
00088     timer.reset();
00089 
00090 }
00091 int main() {
00092    
00093    
00094     taster2.rise(&pause);
00095     taster1.rise(&restart);
00096     
00097     timer.start();
00098     display_first();
00099     display_second();
00100     display_third();
00101     tick1.attach(&display_first, .001);
00102     tick2.attach(&display_second, .002);
00103     tick3.attach(&display_third, .003);
00104     while(true);
00105     
00106     
00107 }