TaDA

Dependencies:   Servo mbed

Fork of luce_rossa_piezo by Matteo Andriolo

main.cpp

Committer:
EzDzO
Date:
2016-04-18
Revision:
1:0e967fe8862e
Parent:
0:5daff114eb4a

File content as of revision 1:0e967fe8862e:

#include "mbed.h"
#include "note.h"
#include "Servo.h"

DigitalIn bottone(p14);
DigitalOut ledR(p25);
DigitalOut ledG(p24);
DigitalOut ledB(p26);
PwmOut piezo(p22);
Servo myservo1(p23);
Servo myservo2(p21);
int c=0;

void suono(int frequenza, int beat);

int main()
{
    while(1) {

        c=0;
        if(bottone==1) {
            ledG=1;
            ledR=0;
            suono(NOTE_B4,1);
            wait(1);

            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);
}