Sz_Insper / Mbed 2 deprecated DAC_waveform_V2

Dependencies:   mbed

main.cpp

Committer:
henriquer
Date:
2020-05-29
Revision:
1:a0a660d54a0b
Parent:
0:cdadc6b7f2d1

File content as of revision 1:a0a660d54a0b:

#include "mbed.h"

BusOut Bus(D5,D6,D7);

AnalogIn Ain (A0);

Serial pc (USBTX,USBRX);

InterruptIn button(USER_BUTTON);

#define PI 3.141592f


float valor ;

float  sen;

int contador = 0;

int j =0;

void wave(void);


void seno()
{
while(j!=25){
    j++;
    for (int i=0; i <361; i++) {

        valor  = 3.3 * Ain.read();

        sen = 0.5*sin(i*(PI/180.0))+0.5;

        int n = (int) (sen*7);

        Bus = n;

        //pc.printf("\r\t%1.3f\n",valor);
         wait_ms(1);
}

    }


}

void serra()
{
    for(int i = 0; i<8; i++) {
        Bus = i*7;
        valor = 3.3*Ain.read();
        //pc.printf("\r\t%1.3f\n",valor);
        wait_ms(100);
    }
}

void square()
{
    for(int i =0; i <=15; i=i++) {
        Bus =  (i/10)*15;
        wait_ms(100);
        valor = 3.3*Ain.read();
        //pc.printf("\r\t%1.3f\n",valor);


    }
}






void wave()

{

    button==!button;
    contador = contador++;
    pc.printf("Contador: = %d\n\r",contador);
    switch(contador) {




        case 1:
            for (int i=1; i<10; i++) {
                seno();
                wait_ms(20);
            }
            break;

        case 2:
            for (int i=10; i<20; i++) {
                serra();
                wait_ms(20);

            }
            break;

        case 3:
            for (int i=20; i<30; i++) {
                square();
                wait_ms(20);
            }
            
            break;



        case 4:
          for (int i=30; i<35; i++) {
            contador = 0;
            j =0;
            }
            break;

    }
}

int main()
{

    button.rise(&wave);


}