Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
conversor.cpp
- Committer:
- Hiroball
- Date:
- 2020-06-08
- Revision:
- 10:fef73855847f
- Parent:
- 9:c9fd0beba38c
- Child:
- 12:415818832707
File content as of revision 10:fef73855847f:
#include "mbed.h" #include <math.h> BusOut saida_digital (D2,D3,D4); InterruptIn botao_usuario(PC_13); AnalogIn leitura_an(A0); Serial pc(USBTX, USBRX); float valor; int estado_botao; int senoide[8] = {0,1,4,6,7,6,4,1}; float vref = 3.3; int SEQUENCIA[8]={ 0b000, 0b001, 0b010, 0b011, 0b100, 0b101, 0b110, 0b111 }; void funcao_botao(){ //contador que vê qual o estado do botão if (estado_botao < 4){ estado_botao++; } else{ estado_botao = 0; } } int main(){ estado_botao=0; pc.baud(9600); pc.printf("\r"); pc.printf("oi"); while(1){ pc.printf("%d",estado_botao); botao_usuario.fall(&funcao_botao); if(estado_botao == 0){ for (int i=0; i<8; i++) { saida_digital = 0b111; valor=leitura_an.read(); pc.printf("\r\t%1.3f\n",valor); wait(0.5); } for (int i=8; i>0; i--) { saida_digital = 0b000; valor=leitura_an.read(); pc.printf("\r\t%1.3f\n",valor); wait(0.5); } } else if (estado_botao == 1){ //Onda rampa for (int i=0; i<8; i++) { saida_digital = SEQUENCIA[i]; valor=leitura_an.read(); pc.printf("\r\t%1.3f\n",valor); wait(0.5); } } else if (estado_botao == 2){ //Onda triangular for (int i=0; i<8; i++) { saida_digital = SEQUENCIA[i]; wait(0.5); valor=leitura_an.read(); pc.printf("\r\t%1.3f\n",valor); } for (int i=7; i>0; i--) { saida_digital = SEQUENCIA[i]; wait(0.5); valor=leitura_an.read(); pc.printf("\r\t%1.3f\n",valor); } } else if(estado_botao == 3){ for(int i; i<8;i++){ saida_digital = senoide[i]; valor = leitura_an.read()*vref; pc.printf("\r\t%1.3f\n",valor); wait(0.5); } } } }