Marko Spremic 2020/0066 verzija poslednja

Dependencies:   mbed

main.cpp

Committer:
markospremic
Date:
2021-11-06
Revision:
1:5422c10009a3
Parent:
0:a95a1295484c

File content as of revision 1:5422c10009a3:

/*
 *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 time2 50
 #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;
         default: led_dis = 0xFF;
     }
 }
 
 //Definisanje glavne funkcije:
 
int main()
{
    int x = null, x1 = null, x2 = null;static char ButtonReleased1  = 1, ButtonReleased2 = 1;
    while(1)
    {
        x1 = x % 10;
        x2 = (x / 10 == 1)? 1:-1;
        SEL2.write(0);
        SEL1.write(1);
        write_num(x1);
        wait_ms(time);
        
        SEL2.write(1);
        SEL1.write(0);
        write_num(x2);
        wait_ms(time);
        
        if(!btn1 && btn2)
        {
            if(ButtonReleased1)
            {
                ADD(x)
                CHECK(x)
                ButtonReleased1 = 0;
            }
            wait_ms(time2);
        }
        else
        {
            ButtonReleased1 = 1;
        }
        if(!btn2 && btn1)
        {
            if(ButtonReleased2)
            {
                DEC(x)
                CHECK_0(x)
                ButtonReleased2 = 0;
            }
            wait_ms(time2);
        }
        else
        {
            ButtonReleased2 = 1;
        }
    }
}