Stefan Veljkovic
/
19E042PIM_T2_2020_0158
19E042PIM_T2_2020_0158
Revision 0:173abbcd8ef1, committed 2021-11-13
- Comitter:
- 1stefikefi
- Date:
- Sat Nov 13 08:48:52 2021 +0000
- Commit message:
- 19E042PIM_T2_2020_0158
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 13 08:48:52 2021 +0000 @@ -0,0 +1,166 @@ +/* + Stefan Veljkovic 2020_0158 + Prikazana vrednost ne pokazuje ono sto mi cujemo iz razloga sto + nasa percepcija zvuka je eksponencijalno zavisna dok sam ga ja + isprogramirao da bude linearno zavisno +*/ +#include <mbed.h> + +#define VOLTAGE_SKALE 3.3 + +AnalogIn pot1(PA_0); +AnalogIn pot2(PA_1); +InterruptIn sw1(PC_9); +PwmOut zujalica(PA_11); +BusOut DISPLAY(PA_10, PA_9, PA_8, PB_10, PB_5, PB_4, PB_3); +DigitalOut SEL1 = PB_6; +DigitalOut SEL2 = PC_7; +int i = 0,d = 0,c = 0; + +void isr_sw1() +{ + i = 100 - pot1.read()*100; + d = i / 10; + c = i - d*10; + /* + if(i < 10) + { + //printf("Jacina zvuka je %1.0f%c \r\n", 100 - pot1.read()*100,37); + //printf("%d\n\r", c); + switch(c) + { + //case -1: i = 15; break; + case 0: DISPLAY.write(0xC0); SEL1.write(1); SEL2.write(0); break; + case 1: DISPLAY.write(0xF9); SEL1.write(1); SEL2.write(0); break; + case 2: DISPLAY.write(0xA4); SEL1.write(1); SEL2.write(0); break; + case 3: DISPLAY.write(0xB0); SEL1.write(1); SEL2.write(0); break; + case 4: DISPLAY.write(0x99); SEL1.write(1); SEL2.write(0); break; + case 5: DISPLAY.write(0x92); SEL1.write(1); SEL2.write(0); break; + case 6: DISPLAY.write(0x82); SEL1.write(1); SEL2.write(0); break; + case 7: DISPLAY.write(0xF8); SEL1.write(1); SEL2.write(0); break; + case 8: DISPLAY.write(0x80); SEL1.write(1); SEL2.write(0); break; + case 9: DISPLAY.write(0x90); SEL1.write(1); SEL2.write(0); break; + } + wait(0.0005); + } + if((i <= 99) and (i >= 10)) + { + //printf("%d\n\r", c); + switch(c) + { + //case -1: i = 15; break; + case 0: DISPLAY.write(0xC0); SEL1.write(1); SEL2.write(0); break; + case 1: DISPLAY.write(0xF9); SEL1.write(1); SEL2.write(0); break; + case 2: DISPLAY.write(0xA4); SEL1.write(1); SEL2.write(0); break; + case 3: DISPLAY.write(0xB0); SEL1.write(1); SEL2.write(0); break; + case 4: DISPLAY.write(0x99); SEL1.write(1); SEL2.write(0); break; + case 5: DISPLAY.write(0x92); SEL1.write(1); SEL2.write(0); break; + case 6: DISPLAY.write(0x82); SEL1.write(1); SEL2.write(0); break; + case 7: DISPLAY.write(0xF8); SEL1.write(1); SEL2.write(0); break; + case 8: DISPLAY.write(0x80); SEL1.write(1); SEL2.write(0); break; + case 9: DISPLAY.write(0x90); SEL1.write(1); SEL2.write(0); break; + } + wait(0.0005); + switch(d) + { + //case -1: i = 15; break; + case 0: DISPLAY.write(0xC0); SEL1.write(0); SEL2.write(1); break; + case 1: DISPLAY.write(0xF9); SEL1.write(0); SEL2.write(1); break; + case 2: DISPLAY.write(0xA4); SEL1.write(0); SEL2.write(1); break; + case 3: DISPLAY.write(0xB0); SEL1.write(0); SEL2.write(1); break; + case 4: DISPLAY.write(0x99); SEL1.write(0); SEL2.write(1); break; + case 5: DISPLAY.write(0x92); SEL1.write(0); SEL2.write(1); break; + case 6: DISPLAY.write(0x82); SEL1.write(0); SEL2.write(1); break; + case 7: DISPLAY.write(0xF8); SEL1.write(0); SEL2.write(1); break; + case 8: DISPLAY.write(0x80); SEL1.write(0); SEL2.write(1); break; + case 9: DISPLAY.write(0x90); SEL1.write(0); SEL2.write(1); break; + } + wait(0.0005); + //printf("Jacina zvuka je %1.0f%c \r\n", 100 - pot1.read()*100,37); + } + if(i == 100) + { + DISPLAY.write(0x90); SEL1.write(0); SEL2.write(1); + DISPLAY.write(0x90); SEL1.write(1); SEL2.write(0); + } + */ +} + + +int main() +{ + //sw1.fall(&isr_sw1); + + while(1) + { + //jacina = pot1.read(); + //frekvenca = pot2.read(); + //printf("%1.2f %1.2f \r\n", pot1.read(), pot2.read()); + //wait(1); + sw1.fall(&isr_sw1); //namesta vrednosti i,d,c + + if(i < 10) + { + //printf("Jacina zvuka je %1.0f%c \r\n", 100 - pot1.read()*100,37); + //printf("%d\n\r", c); + switch(c) + { + //case -1: i = 15; break; + case 0: DISPLAY.write(0xC0); SEL1.write(1); SEL2.write(0); break; + case 1: DISPLAY.write(0xF9); SEL1.write(1); SEL2.write(0); break; + case 2: DISPLAY.write(0xA4); SEL1.write(1); SEL2.write(0); break; + case 3: DISPLAY.write(0xB0); SEL1.write(1); SEL2.write(0); break; + case 4: DISPLAY.write(0x99); SEL1.write(1); SEL2.write(0); break; + case 5: DISPLAY.write(0x92); SEL1.write(1); SEL2.write(0); break; + case 6: DISPLAY.write(0x82); SEL1.write(1); SEL2.write(0); break; + case 7: DISPLAY.write(0xF8); SEL1.write(1); SEL2.write(0); break; + case 8: DISPLAY.write(0x80); SEL1.write(1); SEL2.write(0); break; + case 9: DISPLAY.write(0x90); SEL1.write(1); SEL2.write(0); break; + } + } + if((i <= 99) and (i >= 10)) + { + //printf("%d\n\r", c); + switch(c) + { + //case -1: i = 15; break; + case 0: DISPLAY.write(0xC0); SEL1.write(1); SEL2.write(0); break; + case 1: DISPLAY.write(0xF9); SEL1.write(1); SEL2.write(0); break; + case 2: DISPLAY.write(0xA4); SEL1.write(1); SEL2.write(0); break; + case 3: DISPLAY.write(0xB0); SEL1.write(1); SEL2.write(0); break; + case 4: DISPLAY.write(0x99); SEL1.write(1); SEL2.write(0); break; + case 5: DISPLAY.write(0x92); SEL1.write(1); SEL2.write(0); break; + case 6: DISPLAY.write(0x82); SEL1.write(1); SEL2.write(0); break; + case 7: DISPLAY.write(0xF8); SEL1.write(1); SEL2.write(0); break; + case 8: DISPLAY.write(0x80); SEL1.write(1); SEL2.write(0); break; + case 9: DISPLAY.write(0x90); SEL1.write(1); SEL2.write(0); break; + } + wait(0.002); + switch(d) + { + //case -1: i = 15; break; + case 0: DISPLAY.write(0xC0); SEL1.write(0); SEL2.write(1); break; + case 1: DISPLAY.write(0xF9); SEL1.write(0); SEL2.write(1); break; + case 2: DISPLAY.write(0xA4); SEL1.write(0); SEL2.write(1); break; + case 3: DISPLAY.write(0xB0); SEL1.write(0); SEL2.write(1); break; + case 4: DISPLAY.write(0x99); SEL1.write(0); SEL2.write(1); break; + case 5: DISPLAY.write(0x92); SEL1.write(0); SEL2.write(1); break; + case 6: DISPLAY.write(0x82); SEL1.write(0); SEL2.write(1); break; + case 7: DISPLAY.write(0xF8); SEL1.write(0); SEL2.write(1); break; + case 8: DISPLAY.write(0x80); SEL1.write(0); SEL2.write(1); break; + case 9: DISPLAY.write(0x90); SEL1.write(0); SEL2.write(1); break; + } + wait(0.002); + //printf("Jacina zvuka je %1.0f%c \r\n", 100 - pot1.read()*100,37); + } + if(i == 100) + { + DISPLAY.write(0x90); SEL1.write(0); SEL2.write(1);wait(0.002); + DISPLAY.write(0x90); SEL1.write(1); SEL2.write(0);wait(0.002); + } + zujalica.period(1 / (pot2.read() * 2000)); //pjeva vislje + zujalica.write(pot1.read()); //pjeva glasnije + wait(0.005); //ko ce ga znati zasto + + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 13 08:48:52 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file