Tandem
/
Progetto_Tandem_Finale
TaDA
Fork of luce_rossa_piezo by
Diff: main.cpp
- Revision:
- 1:0e967fe8862e
- Parent:
- 0:5daff114eb4a
diff -r 5daff114eb4a -r 0e967fe8862e main.cpp --- a/main.cpp Mon Apr 18 19:28:48 2016 +0000 +++ b/main.cpp Mon Apr 18 21:04:36 2016 +0000 @@ -1,40 +1,95 @@ #include "mbed.h" -DigitalIn bottone(p23); +#include "note.h" +#include "Servo.h" + +DigitalIn bottone(p14); DigitalOut ledR(p25); DigitalOut ledG(p24); DigitalOut ledB(p26); PwmOut piezo(p22); -bool flag=0; +Servo myservo1(p23); +Servo myservo2(p21); int c=0; + +void suono(int frequenza, int beat); + int main() { while(1) { - if(bottone==1&& c>0 && c<=10000) { + c=0; + if(bottone==1) { + ledG=1; ledR=0; - flag=0; - c=0; - piezo.period(1.0 / 200.0); - piezo.write(0.5); - wait(2); - piezo.write(0); - wait(0.05); - } else if(bottone==1) { - ledR=1; - flag=1; - } else if (c>10000) { - piezo.period(1.0 / 600.0); - piezo.write(0.5); - wait(1.0 / 2); - piezo.write(0); - wait(0.05); - } + suono(NOTE_B4,1); + wait(1); - if(flag==1) { - c++; + do { + wait(0.001); + c++; + if(c++>=10000) { + ledG=0; + ledR=1; + suono(NOTE_C5,1); + } + } while(!bottone); + //*************************MOVIMENTO SERVI************************ + int a=0; + int b=0; + if(a<2) a++; + else if(a>=2) { + for(float i=0; i<30; i++) { + myservo1=i; + wait(0.1); + a=0; + b++; + } + } + if(b==5){ + for(float i=180; i<0; i++) + myservo1=i; + wait(0.1); + b=0; + } + int f=0; + + if(f==0){ + for(float i=0; i<30; i++) + myservo2=i; + wait(0.1); + f++; + } + else if(f==1) + for(float i=0; i<60; i++) + myservo2=i; + wait(0.1); + f++; + if(f==3){ + for(float i=60; i<0; i--) + myservo2=i; + wait(0.1); + f=0; + } + + //**************************************************************** + + ledR=0; + ledB=1; + wait(1); + ledB=0; + suono(NOTE_F1,1); } wait_ms(1); } } + +void suono(int frequenza, int beat) +{ + piezo.period(1.0 / frequenza); + piezo.write(0.5); + wait(1.0 / beat); + piezo.write(0); + wait(0.05); +} \ No newline at end of file