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@6:e8afe3e31edb, 2020-06-08 (annotated)
- Committer:
- amandarm
- Date:
- Mon Jun 08 14:49:08 2020 +0000
- Revision:
- 6:e8afe3e31edb
- Parent:
- 5:436b7d88a92d
- Child:
- 7:f69e1333449d
onda quadrada ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
enricoan | 0:f2560180665b | 1 | #include "mbed.h" |
enricoan | 1:d05e46c73155 | 2 | #include <math.h> |
amandarm | 2:8e9dbb7523e7 | 3 | BusOut saida_digital (D2,D3,D4); |
amandarm | 2:8e9dbb7523e7 | 4 | DigitalIn botao_usuario(PC_13); |
amandarm | 2:8e9dbb7523e7 | 5 | AnalogIn leitura_an(A0); |
enricoan | 0:f2560180665b | 6 | |
enricoan | 0:f2560180665b | 7 | Serial pc(USBTX, USBRX); |
enricoan | 0:f2560180665b | 8 | float valor; |
amandarm | 5:436b7d88a92d | 9 | int estado_botao; |
enricoan | 0:f2560180665b | 10 | |
amandarm | 2:8e9dbb7523e7 | 11 | int SEQUENCIA[8]={ |
amandarm | 2:8e9dbb7523e7 | 12 | 0b000, |
amandarm | 2:8e9dbb7523e7 | 13 | 0b001, |
amandarm | 2:8e9dbb7523e7 | 14 | 0b010, |
amandarm | 2:8e9dbb7523e7 | 15 | 0b011, |
amandarm | 2:8e9dbb7523e7 | 16 | 0b100, |
amandarm | 2:8e9dbb7523e7 | 17 | 0b101, |
amandarm | 2:8e9dbb7523e7 | 18 | 0b110, |
amandarm | 2:8e9dbb7523e7 | 19 | 0b111 |
amandarm | 2:8e9dbb7523e7 | 20 | }; |
amandarm | 2:8e9dbb7523e7 | 21 | |
enricoan | 0:f2560180665b | 22 | int main(){ |
amandarm | 5:436b7d88a92d | 23 | estado_botao=0; |
enricoan | 0:f2560180665b | 24 | pc.baud(9600); |
enricoan | 0:f2560180665b | 25 | pc.printf("\r"); |
amandarm | 3:b0a44d2901a1 | 26 | pc.printf("oi"); |
enricoan | 0:f2560180665b | 27 | while(1){ |
amandarm | 5:436b7d88a92d | 28 | if (botao_usuario == 0){ //Onda quadrada |
amandarm | 5:436b7d88a92d | 29 | if (botao_usuario < 4){ |
amandarm | 5:436b7d88a92d | 30 | estado_botao++; |
amandarm | 5:436b7d88a92d | 31 | } |
amandarm | 5:436b7d88a92d | 32 | else{ |
amandarm | 5:436b7d88a92d | 33 | estado_botao = 0; |
amandarm | 5:436b7d88a92d | 34 | } |
amandarm | 5:436b7d88a92d | 35 | } |
amandarm | 5:436b7d88a92d | 36 | if(estado_botao == 0){ |
amandarm | 5:436b7d88a92d | 37 | for (int i=0; i<8; i++) { |
amandarm | 5:436b7d88a92d | 38 | saida_digital = 0b111; |
amandarm | 5:436b7d88a92d | 39 | valor=leitura_an.read(); |
amandarm | 5:436b7d88a92d | 40 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 5:436b7d88a92d | 41 | wait(0.5); |
amandarm | 6:e8afe3e31edb | 42 | } |
amandarm | 6:e8afe3e31edb | 43 | for (int i=8; i>0; i--) { |
amandarm | 5:436b7d88a92d | 44 | saida_digital = 0b000; |
amandarm | 6:e8afe3e31edb | 45 | valor=leitura_an.read(); |
amandarm | 6:e8afe3e31edb | 46 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 6:e8afe3e31edb | 47 | wait(0.5); |
amandarm | 5:436b7d88a92d | 48 | } |
enricoan | 0:f2560180665b | 49 | } |
amandarm | 5:436b7d88a92d | 50 | else if (estado_botao == 1){ //Onda rampa |
amandarm | 5:436b7d88a92d | 51 | for (int i=0; i<8; i++) { |
amandarm | 5:436b7d88a92d | 52 | saida_digital = SEQUENCIA[i]; |
amandarm | 5:436b7d88a92d | 53 | valor=leitura_an.read(); |
amandarm | 5:436b7d88a92d | 54 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 5:436b7d88a92d | 55 | wait(0.5); |
amandarm | 5:436b7d88a92d | 56 | } |
amandarm | 5:436b7d88a92d | 57 | } |
amandarm | 5:436b7d88a92d | 58 | else if (estado_botao == 2){ //Onda triangular |
amandarm | 5:436b7d88a92d | 59 | for (int i=0; i<8; i++) { |
amandarm | 5:436b7d88a92d | 60 | saida_digital = SEQUENCIA[i]; |
amandarm | 5:436b7d88a92d | 61 | wait(0.5); |
amandarm | 5:436b7d88a92d | 62 | valor=leitura_an.read(); |
amandarm | 5:436b7d88a92d | 63 | pc.printf("\r\t%1.3f\n",i); |
amandarm | 5:436b7d88a92d | 64 | } |
amandarm | 5:436b7d88a92d | 65 | for (int i=8; i>0; i--) { |
amandarm | 5:436b7d88a92d | 66 | saida_digital = SEQUENCIA[i]; |
amandarm | 5:436b7d88a92d | 67 | wait(0.5); |
amandarm | 5:436b7d88a92d | 68 | valor=leitura_an.read(); |
amandarm | 5:436b7d88a92d | 69 | pc.printf("\r\t%1.3f\n",i); |
amandarm | 5:436b7d88a92d | 70 | } |
amandarm | 5:436b7d88a92d | 71 | } |
amandarm | 5:436b7d88a92d | 72 | |
amandarm | 2:8e9dbb7523e7 | 73 | |
amandarm | 2:8e9dbb7523e7 | 74 | } |
amandarm | 2:8e9dbb7523e7 | 75 | } |
enricoan | 0:f2560180665b | 76 |