![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Pavle Popovic 0494
main.cpp@0:2cc3ed89daea, 2021-11-13 (annotated)
- Committer:
- pavle1
- Date:
- Sat Nov 13 09:11:59 2021 +0000
- Revision:
- 0:2cc3ed89daea
Pavle Popovic 2020/0494;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pavle1 | 0:2cc3ed89daea | 1 | /* mbed Microcontroller Library |
pavle1 | 0:2cc3ed89daea | 2 | * Copyright (c) 2019 ARM Limited |
pavle1 | 0:2cc3ed89daea | 3 | * SPDX-License-Identifier: Apache-2.0 |
pavle1 | 0:2cc3ed89daea | 4 | */ |
pavle1 | 0:2cc3ed89daea | 5 | |
pavle1 | 0:2cc3ed89daea | 6 | #include "mbed.h"//uvoz biblioteka |
pavle1 | 0:2cc3ed89daea | 7 | |
pavle1 | 0:2cc3ed89daea | 8 | #define SCALER 4900//definisanje direktiva |
pavle1 | 0:2cc3ed89daea | 9 | |
pavle1 | 0:2cc3ed89daea | 10 | AnalogIn pot1(PA_0);//glavne promenljive |
pavle1 | 0:2cc3ed89daea | 11 | AnalogIn pot2(PA_1); |
pavle1 | 0:2cc3ed89daea | 12 | PwmOut buzz(PA_11); |
pavle1 | 0:2cc3ed89daea | 13 | InterruptIn sw1(PC_9); |
pavle1 | 0:2cc3ed89daea | 14 | BusOut display(PA_10,PA_9,PA_8,PB_10,PB_5,PB_4,PB_3,PA_5); |
pavle1 | 0:2cc3ed89daea | 15 | DigitalOut SEL2(PC_7); |
pavle1 | 0:2cc3ed89daea | 16 | DigitalOut SEL1(PB_6); |
pavle1 | 0:2cc3ed89daea | 17 | |
pavle1 | 0:2cc3ed89daea | 18 | void ISR_sw1(void);//pomocne funkcije |
pavle1 | 0:2cc3ed89daea | 19 | |
pavle1 | 0:2cc3ed89daea | 20 | int main()//glavna funkcija |
pavle1 | 0:2cc3ed89daea | 21 | { |
pavle1 | 0:2cc3ed89daea | 22 | buzz.period_ms(1); |
pavle1 | 0:2cc3ed89daea | 23 | sw1.fall(&ISR_sw1); |
pavle1 | 0:2cc3ed89daea | 24 | while (true) { |
pavle1 | 0:2cc3ed89daea | 25 | buzz.period_us(pot2.read()*SCALER+100);//kada stavim 50 pocetnu vrednost ne cuje se po cetak pa zato sam stavio 100us |
pavle1 | 0:2cc3ed89daea | 26 | buzz.write(pot1.read()); |
pavle1 | 0:2cc3ed89daea | 27 | wait_ms(10); |
pavle1 | 0:2cc3ed89daea | 28 | } |
pavle1 | 0:2cc3ed89daea | 29 | } |
pavle1 | 0:2cc3ed89daea | 30 | |
pavle1 | 0:2cc3ed89daea | 31 | void ISR_sw1()//interrupt sub-routine |
pavle1 | 0:2cc3ed89daea | 32 | { |
pavle1 | 0:2cc3ed89daea | 33 | int i=pot1.read()*100; |
pavle1 | 0:2cc3ed89daea | 34 | |
pavle1 | 0:2cc3ed89daea | 35 | int d; |
pavle1 | 0:2cc3ed89daea | 36 | int j; |
pavle1 | 0:2cc3ed89daea | 37 | d=i/10; |
pavle1 | 0:2cc3ed89daea | 38 | j=i%10; |
pavle1 | 0:2cc3ed89daea | 39 | while(!sw1.read()) |
pavle1 | 0:2cc3ed89daea | 40 | { |
pavle1 | 0:2cc3ed89daea | 41 | if(i<10) |
pavle1 | 0:2cc3ed89daea | 42 | { |
pavle1 | 0:2cc3ed89daea | 43 | SEL2.write(0); |
pavle1 | 0:2cc3ed89daea | 44 | switch(i) |
pavle1 | 0:2cc3ed89daea | 45 | { |
pavle1 | 0:2cc3ed89daea | 46 | case 0:display.write(0xC0);break; |
pavle1 | 0:2cc3ed89daea | 47 | case 1:display.write(0xF9);break; |
pavle1 | 0:2cc3ed89daea | 48 | case 2:display.write(0xA4);break; |
pavle1 | 0:2cc3ed89daea | 49 | case 3:display.write(0xB0);break; |
pavle1 | 0:2cc3ed89daea | 50 | case 4:display.write(0x99);break; |
pavle1 | 0:2cc3ed89daea | 51 | case 5:display.write(0x92);break; |
pavle1 | 0:2cc3ed89daea | 52 | case 6:display.write(0x82);break; |
pavle1 | 0:2cc3ed89daea | 53 | case 7:display.write(0xF8);break; |
pavle1 | 0:2cc3ed89daea | 54 | case 8:display.write(0x80);break; |
pavle1 | 0:2cc3ed89daea | 55 | case 9:display.write(0x90);break; |
pavle1 | 0:2cc3ed89daea | 56 | |
pavle1 | 0:2cc3ed89daea | 57 | } |
pavle1 | 0:2cc3ed89daea | 58 | SEL2.write(1); |
pavle1 | 0:2cc3ed89daea | 59 | wait_us(500); |
pavle1 | 0:2cc3ed89daea | 60 | } |
pavle1 | 0:2cc3ed89daea | 61 | else |
pavle1 | 0:2cc3ed89daea | 62 | { |
pavle1 | 0:2cc3ed89daea | 63 | SEL1.write(0); |
pavle1 | 0:2cc3ed89daea | 64 | switch(d) |
pavle1 | 0:2cc3ed89daea | 65 | { |
pavle1 | 0:2cc3ed89daea | 66 | case 1:display.write(0xF9);break; |
pavle1 | 0:2cc3ed89daea | 67 | case 2:display.write(0xA4);break; |
pavle1 | 0:2cc3ed89daea | 68 | case 3:display.write(0xB0);break; |
pavle1 | 0:2cc3ed89daea | 69 | case 4:display.write(0x99);break; |
pavle1 | 0:2cc3ed89daea | 70 | case 5:display.write(0x92);break; |
pavle1 | 0:2cc3ed89daea | 71 | case 6:display.write(0x82);break; |
pavle1 | 0:2cc3ed89daea | 72 | case 7:display.write(0xF8);break; |
pavle1 | 0:2cc3ed89daea | 73 | case 8:display.write(0x80);break; |
pavle1 | 0:2cc3ed89daea | 74 | case 9:display.write(0x90);break; |
pavle1 | 0:2cc3ed89daea | 75 | |
pavle1 | 0:2cc3ed89daea | 76 | } |
pavle1 | 0:2cc3ed89daea | 77 | wait_us(500); |
pavle1 | 0:2cc3ed89daea | 78 | |
pavle1 | 0:2cc3ed89daea | 79 | SEL1.write(1); |
pavle1 | 0:2cc3ed89daea | 80 | |
pavle1 | 0:2cc3ed89daea | 81 | SEL2.write(0); |
pavle1 | 0:2cc3ed89daea | 82 | switch(j) |
pavle1 | 0:2cc3ed89daea | 83 | { |
pavle1 | 0:2cc3ed89daea | 84 | case 0:display.write(0xC0);break; |
pavle1 | 0:2cc3ed89daea | 85 | case 1:display.write(0xF9);break; |
pavle1 | 0:2cc3ed89daea | 86 | case 2:display.write(0xA4);break; |
pavle1 | 0:2cc3ed89daea | 87 | case 3:display.write(0xB0);break; |
pavle1 | 0:2cc3ed89daea | 88 | case 4:display.write(0x99);break; |
pavle1 | 0:2cc3ed89daea | 89 | case 5:display.write(0x92);break; |
pavle1 | 0:2cc3ed89daea | 90 | case 6:display.write(0x82);break; |
pavle1 | 0:2cc3ed89daea | 91 | case 7:display.write(0xF8);break; |
pavle1 | 0:2cc3ed89daea | 92 | case 8:display.write(0x80);break; |
pavle1 | 0:2cc3ed89daea | 93 | case 9:display.write(0x90);break; |
pavle1 | 0:2cc3ed89daea | 94 | |
pavle1 | 0:2cc3ed89daea | 95 | } |
pavle1 | 0:2cc3ed89daea | 96 | wait_us(500); |
pavle1 | 0:2cc3ed89daea | 97 | SEL1.write(1); |
pavle1 | 0:2cc3ed89daea | 98 | } |
pavle1 | 0:2cc3ed89daea | 99 | } |
pavle1 | 0:2cc3ed89daea | 100 | |
pavle1 | 0:2cc3ed89daea | 101 | |
pavle1 | 0:2cc3ed89daea | 102 | } |