Marko Spremic 2020/0066

Dependencies:   mbed

main.cpp

Committer:
markospremic
Date:
2021-11-06
Revision:
0:a95a1295484c

File content as of revision 0:a95a1295484c:

/*
 *Marko Spremic 
 *Indeks: 2020/0066
 */
 //Ukljucivanje biblioteka:
 
 #include "mbed.h"
 
 //Definisanje direktiva:
 #define null 0
 #define one 1
 #define ADD(x) x+=1;
 #define DEC(x) x-=1;
 #define time 8
 #define CHECK(x) if(x > 15) x = 0;
 #define CHECK_0(x) if(x < 0) x = 15;
 
 //Definisanje glavnih promenljivih:
 
 BusOut led_dis(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3, PA_2);
 DigitalOut SEL2(PC_7);
 DigitalOut SEL1(PB_6);
 DigitalIn btn1(PC_9);
 DigitalIn btn2(PC_8);

 
 //Definisanje pomocne funkcije:
 void write_num(int broj)
 {
     switch(broj)
     {
         case 0: led_dis = 0xC0; break;
         case 1: led_dis = 0xF9; break;
         case 2: led_dis = 0xA4; break;
         case 3: led_dis = 0xB0; break;
         case 4: led_dis = 0x99; break;
         case 5: led_dis = 0x92; break;
         case 6: led_dis = 0x82; break;
         case 7: led_dis = 0xF8; break;
         case 8: led_dis = 0x80; break;
         case 9: led_dis = 0x90; break;
     }
 }
 
 //Definisanje glavne funkcije:
 
int main()
{
    int x = null, ButtonReleased1  = 0, ButtonReleased2 = 0;
    while(1)
    {
        SEL2.write(0);
        SEL1.write(1);
        write_num(x%10);
        wait_ms(time);
        if(x > 9)
        {
            SEL2.write(1);
            SEL1.write(0);
            write_num(one);
            wait_ms(time);
        }
        if(!btn1)
        {
            if(ButtonReleased1)
            {
                ADD(x)
                CHECK(x)
                ButtonReleased1 = 0;
            }
            wait_ms(2 * time);
        }
        else
            ButtonReleased1 = 1;
        
        if(!btn2)
        {
            if(ButtonReleased2)
            {
                DEC(x)
                CHECK_0(x)
                ButtonReleased2 = 0;
            }

        }
        else
            ButtonReleased2 = 1;
    }
}