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@8:20afab089ff8, 2020-06-08 (annotated)
- Committer:
- amandarm
- Date:
- Mon Jun 08 14:59:14 2020 +0000
- Revision:
- 8:20afab089ff8
- Parent:
- 7:f69e1333449d
- Child:
- 9:c9fd0beba38c
- Child:
- 11:d3e72f8d05cd
onda triangular certa
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 | 7:f69e1333449d | 4 | InterruptIn 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 | 7:f69e1333449d | 21 | void funcao_botao(){ |
amandarm | 7:f69e1333449d | 22 | if (estado_botao < 4){ |
amandarm | 7:f69e1333449d | 23 | estado_botao++; |
amandarm | 7:f69e1333449d | 24 | } |
amandarm | 7:f69e1333449d | 25 | else{ |
amandarm | 7:f69e1333449d | 26 | estado_botao = 0; |
amandarm | 7:f69e1333449d | 27 | } |
amandarm | 7:f69e1333449d | 28 | } |
amandarm | 2:8e9dbb7523e7 | 29 | |
enricoan | 0:f2560180665b | 30 | int main(){ |
amandarm | 5:436b7d88a92d | 31 | estado_botao=0; |
enricoan | 0:f2560180665b | 32 | pc.baud(9600); |
enricoan | 0:f2560180665b | 33 | pc.printf("\r"); |
amandarm | 3:b0a44d2901a1 | 34 | pc.printf("oi"); |
enricoan | 0:f2560180665b | 35 | while(1){ |
amandarm | 7:f69e1333449d | 36 | pc.printf("%d",estado_botao); |
amandarm | 7:f69e1333449d | 37 | botao_usuario.fall(&funcao_botao); |
amandarm | 5:436b7d88a92d | 38 | if(estado_botao == 0){ |
amandarm | 5:436b7d88a92d | 39 | for (int i=0; i<8; i++) { |
amandarm | 5:436b7d88a92d | 40 | saida_digital = 0b111; |
amandarm | 5:436b7d88a92d | 41 | valor=leitura_an.read(); |
amandarm | 5:436b7d88a92d | 42 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 5:436b7d88a92d | 43 | wait(0.5); |
amandarm | 6:e8afe3e31edb | 44 | } |
amandarm | 6:e8afe3e31edb | 45 | for (int i=8; i>0; i--) { |
amandarm | 5:436b7d88a92d | 46 | saida_digital = 0b000; |
amandarm | 6:e8afe3e31edb | 47 | valor=leitura_an.read(); |
amandarm | 6:e8afe3e31edb | 48 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 6:e8afe3e31edb | 49 | wait(0.5); |
amandarm | 5:436b7d88a92d | 50 | } |
enricoan | 0:f2560180665b | 51 | } |
amandarm | 5:436b7d88a92d | 52 | else if (estado_botao == 1){ //Onda rampa |
amandarm | 5:436b7d88a92d | 53 | for (int i=0; i<8; i++) { |
amandarm | 5:436b7d88a92d | 54 | saida_digital = SEQUENCIA[i]; |
amandarm | 5:436b7d88a92d | 55 | valor=leitura_an.read(); |
amandarm | 5:436b7d88a92d | 56 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 5:436b7d88a92d | 57 | wait(0.5); |
amandarm | 5:436b7d88a92d | 58 | } |
amandarm | 5:436b7d88a92d | 59 | } |
amandarm | 5:436b7d88a92d | 60 | else if (estado_botao == 2){ //Onda triangular |
amandarm | 5:436b7d88a92d | 61 | for (int i=0; i<8; i++) { |
amandarm | 5:436b7d88a92d | 62 | saida_digital = SEQUENCIA[i]; |
amandarm | 5:436b7d88a92d | 63 | wait(0.5); |
amandarm | 5:436b7d88a92d | 64 | valor=leitura_an.read(); |
amandarm | 7:f69e1333449d | 65 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 5:436b7d88a92d | 66 | } |
amandarm | 8:20afab089ff8 | 67 | for (int i=7; i>0; i--) { |
amandarm | 5:436b7d88a92d | 68 | saida_digital = SEQUENCIA[i]; |
amandarm | 5:436b7d88a92d | 69 | wait(0.5); |
amandarm | 5:436b7d88a92d | 70 | valor=leitura_an.read(); |
amandarm | 7:f69e1333449d | 71 | pc.printf("\r\t%1.3f\n",valor); |
amandarm | 5:436b7d88a92d | 72 | } |
amandarm | 5:436b7d88a92d | 73 | } |
amandarm | 5:436b7d88a92d | 74 | |
amandarm | 2:8e9dbb7523e7 | 75 | |
amandarm | 2:8e9dbb7523e7 | 76 | } |
amandarm | 2:8e9dbb7523e7 | 77 | } |
enricoan | 0:f2560180665b | 78 |