Beganovic Benjamin Mehanovic Adnan

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(dp18, dp4, dp28, dp6, dp5, dp27, dp26);
00006 InterruptIn taster1(dp1);
00007 InterruptIn taster2(dp2);
00008 BusOut digit(dp23, dp24, dp25);
00009 DigitalOut decimal_point(dp17);
00010 
00011 Timer timer;
00012 Timer debounce1;
00013 Timer debounce2;
00014 Ticker osvjezi_tiker;
00015 
00016 int red_br_cifre;
00017 int cifra_za_ispis;
00018 int prva_cifra, druga_cifra, treca_cifra;
00019 int predefined_segments[10] = {0x01, 0x4f, 0x12, 0x06, 0x4c, 0x24, 0x20, 0x0f, 0x00, 0x04};
00020 int chars[6] = {0x08,0x60,0x31,0x42,0x30,0x38};
00021 
00022 void osvjezi()
00023 {
00024     red_br_cifre=3;//prva cifra
00025     cifra_za_ispis=predefined_segments[prva_cifra];
00026 
00027     red_br_cifre=5;//druga cifra
00028     cifra_za_ispis=predefined_segments[druga_cifra];
00029 
00030     red_br_cifre=6;//treca cifra
00031     cifra_za_ispis=predefined_segments[treca_cifra];
00032 }
00033 
00034 void display(float current_timer)
00035 {
00036     int timer_digits[3] = { (int)(current_timer / 10.) % 10,
00037                             (int)(current_timer) % 10,
00038                             (int)(current_timer * 10.) % 10
00039                           };
00040 
00041     for(int i = 1; i <= 4; i = i * 2) {
00042         digit = ~i;
00043         segments = predefined_segments[ timer_digits[i / 2] ];
00044         decimal_point = (i == 2) ? 0 : 1;
00045         osvjezi_tiker.attach_us(&osvjezi, 1000);
00046     }
00047 }
00048 
00049 bool stopiran = true;
00050 
00051 void start()
00052 {
00053     if(debounce1.read_ms() > 200) {
00054         if(stopiran) {
00055             timer.start();
00056             stopiran = false;
00057         } else {
00058             timer.stop();
00059             stopiran = true;
00060         }
00061         debounce1.reset();
00062     }
00063 
00064 }
00065 
00066 void reset()
00067 {
00068     if(debounce2.read_ms() > 200) {
00069         timer.reset();
00070         timer.stop();
00071         stopiran = true;
00072         display(0.00);
00073         debounce2.reset();
00074     }
00075 }
00076 
00077 
00078 int main()
00079 {
00080     debounce1.start();
00081     debounce2.start();
00082     taster1.rise(&start);
00083     taster2.rise(&reset);
00084     while(1) {
00085         display(timer.read());
00086     }
00087 }