![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Tehnicko Veleuciliste Zagreb konstrukcijski rad Bozicne lampice
Pri pokretanju programa svijetle led lampice redoslijedom crvena, zelena, žuta u razmaku od 0.2 sekunde i svira melodija we wish You a Merry Christmas. Dovođenjem prekidača sw1 u položaj 0 led lampice se skupa pale i gase također u razmaku od 0.2 sekunde. Ticker služi za provjeru rada programa i treperi plavom led lampicom u razmaku od 0.8 sekundi. Hardverski interrupt radi pritiskom na user button pri čemu program staje na 5 sekundi i pali se led2 na Nucleo pločici. Nakon isteka 5 sek program nastavlja dalje s radom ali led2 ostaje upaljena do ponovog pokretanja interrupat-a.
Revision 0:aeccbc47e077, committed 2021-12-01
- Comitter:
- zdenko12
- Date:
- Wed Dec 01 19:15:02 2021 +0000
- Commit message:
- uredivanje koda
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flasher.lib Wed Dec 01 19:15:02 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/zdenko12/code/flasher/#ca759f0c6bac
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Dec 01 19:15:02 2021 +0000 @@ -0,0 +1,90 @@ +#include "mbed.h" +#include"flasher.h" + +PwmOut buzzer(D7); +DigitalIn sw1(D8); +DigitalOut led1(D2); //ticker plava ledica +Ticker flipper1; +InterruptIn button(USER_BUTTON); +DigitalOut workingLED(LED2); //interupt ledica +Timer debounce; +void interrupt(void); +void flip1() { + led1=!led1; + } +//frekvencija melodije +float a4=440.00; +float b3=246.94; +float b4=493.88; +float c4=261.63; +float c5=523.25; +float c5s=554.40; +float d4=293.66; +float d5=587.33; +float e4=329.63; +float e5=659.25; +float f4=349.23; +float f4s=370.00; +float f5=698.46; +float g4=392.00; +float g4s=415.30; +float g5=783.99; +//trajanje tona +float t1=16; +float t2=8; +float t3=4; +float t4=2; +float t5=1; + +float wish_freq[30] = {e4,a4,a4,b4,a4,g4s,f4s,f4s,f4s,b4,b4,c5s,b4,a4,g4s,e4,e4,c5s,c5s,d5,c5s,b4,a4,f4s,e4,e4,f4s,b4,g4s,a4}; +float wish_tempo[30] = {t3,t3,t2,t2,t2,t2,t3,t3,t3,t3,t2,t2,t2,t2,t3,t3,t3,t3,t2,t2,t2,t2,t3,t3,t2,t2,t3,t3,t3,t4}; + + +int main() +{ + debounce.start(); + button.rise(&interrupt); + + led1 = 1; + led1 = 0; + flipper1.attach(&flip1, 0.8); + + + sw1.mode(PullUp); + while(1) { + + for (int i=0; i<=30; i++) { + buzzer.period(0.2/(wish_freq[i])); + buzzer=0.8; + wait(0.02 *wish_tempo[i]); + if(sw1 == 1) { + bozicnelampice(); //poziv funkcije + } + else if(sw1==0) { //ako promjenimo polozaj prekidaca + redled = 1; + greenled = 1; + yellowled = 1; + wait(0.2); + redled = 0; + greenled = 0; + yellowled = 0; + wait(0.2); +} +} +} +} + +//Zaustavlja rad na 5 sec +void interrupt() +{ + + if (debounce.read_ms()>200) { + workingLED = !workingLED; + wait_us(5000000);//Zaustavlja rad na 5 sec + } + debounce.reset(); +} + + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Dec 01 19:15:02 2021 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file