Aplicações de Microcontroladores
/
Aula_2
Multímetro
main.cpp@2:fb35f75110ee, 2019-07-04 (annotated)
- Committer:
- meksc
- Date:
- Thu Jul 04 12:24:39 2019 +0000
- Revision:
- 2:fb35f75110ee
- Parent:
- 1:808bed0f2433
projeto arlindo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
felipealboy | 0:be36515913f8 | 1 | #include "mbed.h" |
felipealboy | 0:be36515913f8 | 2 | #include "TextLCD.h" |
felipealboy | 0:be36515913f8 | 3 | |
felipealboy | 0:be36515913f8 | 4 | |
meksc | 2:fb35f75110ee | 5 | |
felipealboy | 0:be36515913f8 | 6 | DigitalOut led1(PC_13); |
felipealboy | 0:be36515913f8 | 7 | TextLCD lcd(PA_4,PA_5,PA_6,PB_12,PB_13,PB_14,PB_15); |
felipealboy | 0:be36515913f8 | 8 | AnalogIn adc(PA_0); |
MaikonJT | 1:808bed0f2433 | 9 | AnalogIn tensaofixa(PA_1); |
meksc | 2:fb35f75110ee | 10 | Serial pc(PA_9, PA_10);// ver qual porta e rx e tx |
felipealboy | 0:be36515913f8 | 11 | |
meksc | 2:fb35f75110ee | 12 | /*InterruptIn botao(PA_7); |
felipealboy | 0:be36515913f8 | 13 | volatile bool botao_pressed = false; // Used in the main loop |
felipealboy | 0:be36515913f8 | 14 | volatile bool botao_enabled = true; // Used for debouncing |
felipealboy | 0:be36515913f8 | 15 | Timeout botao_timeout; // Used for debouncing |
felipealboy | 0:be36515913f8 | 16 | |
felipealboy | 0:be36515913f8 | 17 | // Enables button when bouncing is over |
felipealboy | 0:be36515913f8 | 18 | void botao_enabled_cb(void) |
felipealboy | 0:be36515913f8 | 19 | { |
felipealboy | 0:be36515913f8 | 20 | botao_enabled = true; |
felipealboy | 0:be36515913f8 | 21 | } |
felipealboy | 0:be36515913f8 | 22 | |
felipealboy | 0:be36515913f8 | 23 | // ISR handling button pressed event |
felipealboy | 0:be36515913f8 | 24 | void botao_onpressed_cb(void) |
felipealboy | 0:be36515913f8 | 25 | { |
felipealboy | 0:be36515913f8 | 26 | if (botao_enabled) { // Disabled while the button is bouncing |
felipealboy | 0:be36515913f8 | 27 | botao_enabled = false; |
felipealboy | 0:be36515913f8 | 28 | botao_pressed = true; // To be read by the main loop |
felipealboy | 0:be36515913f8 | 29 | botao_timeout.attach(callback(botao_enabled_cb), 0.3); // Debounce time 300 ms |
felipealboy | 0:be36515913f8 | 30 | } |
felipealboy | 0:be36515913f8 | 31 | } |
meksc | 2:fb35f75110ee | 32 | */ |
felipealboy | 0:be36515913f8 | 33 | |
felipealboy | 0:be36515913f8 | 34 | int main() |
felipealboy | 0:be36515913f8 | 35 | { |
MaikonJT | 1:808bed0f2433 | 36 | float alim, tensao, corrente, resistencia; |
meksc | 2:fb35f75110ee | 37 | char cont; |
meksc | 2:fb35f75110ee | 38 | cont = '1'; |
felipealboy | 0:be36515913f8 | 39 | //button1.mode(PullUp); // Activate pull-up |
meksc | 2:fb35f75110ee | 40 | //botao.fall(callback(botao_onpressed_cb)); // Attach ISR to handle button press event |
felipealboy | 0:be36515913f8 | 41 | |
felipealboy | 0:be36515913f8 | 42 | while(1) { |
felipealboy | 0:be36515913f8 | 43 | |
MaikonJT | 1:808bed0f2433 | 44 | alim = 3.3*tensaofixa.read(); |
felipealboy | 0:be36515913f8 | 45 | tensao = 3.3*adc.read(); |
MaikonJT | 1:808bed0f2433 | 46 | resistencia = (tensao*1000)/(alim-tensao); |
MaikonJT | 1:808bed0f2433 | 47 | corrente = (tensao/resistencia) * 1000; |
meksc | 2:fb35f75110ee | 48 | cont= pc.getc (); |
felipealboy | 0:be36515913f8 | 49 | |
meksc | 2:fb35f75110ee | 50 | |
meksc | 2:fb35f75110ee | 51 | /* if (botao_pressed == true) { // Set when button is pressed |
felipealboy | 0:be36515913f8 | 52 | botao_pressed = false; |
felipealboy | 0:be36515913f8 | 53 | cont = cont++; |
felipealboy | 0:be36515913f8 | 54 | led1 = !led1; |
felipealboy | 0:be36515913f8 | 55 | } |
MaikonJT | 1:808bed0f2433 | 56 | if(cont == 4){ |
felipealboy | 0:be36515913f8 | 57 | cont = 1; |
felipealboy | 0:be36515913f8 | 58 | } |
meksc | 2:fb35f75110ee | 59 | */ |
meksc | 2:fb35f75110ee | 60 | |
meksc | 2:fb35f75110ee | 61 | if(cont == '1'){ |
meksc | 2:fb35f75110ee | 62 | //lcd.gotoxy(1,1); |
meksc | 2:fb35f75110ee | 63 | //lcd.printf("Tensao: %.2fV ",tensao); |
meksc | 2:fb35f75110ee | 64 | pc.printf("Tensao: %.2fV ",tensao); |
MaikonJT | 1:808bed0f2433 | 65 | wait(0.2); |
MaikonJT | 1:808bed0f2433 | 66 | |
felipealboy | 0:be36515913f8 | 67 | } |
meksc | 2:fb35f75110ee | 68 | if(cont == '2'){ |
meksc | 2:fb35f75110ee | 69 | //lcd.gotoxy(1,1); |
meksc | 2:fb35f75110ee | 70 | pc.printf("Corrente: %.2fmA ",corrente); |
MaikonJT | 1:808bed0f2433 | 71 | wait(0.2); |
felipealboy | 0:be36515913f8 | 72 | } |
meksc | 2:fb35f75110ee | 73 | if(cont == '3'){ |
meksc | 2:fb35f75110ee | 74 | //lcd.gotoxy(1,1); |
meksc | 2:fb35f75110ee | 75 | pc.printf("Res.:% .0fohm ",resistencia); |
MaikonJT | 1:808bed0f2433 | 76 | wait(0.2); |
felipealboy | 0:be36515913f8 | 77 | } |
MaikonJT | 1:808bed0f2433 | 78 | |
felipealboy | 0:be36515913f8 | 79 | } |
felipealboy | 0:be36515913f8 | 80 | } |