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.
Dependencies: mbed
Fork of tarefa1 by
Diff: Tarefa1.cpp
- Revision:
- 3:14310c47674c
- Parent:
- 2:7476f7336e9a
- Child:
- 4:ee911115dcb6
--- a/Tarefa1.cpp Thu Mar 12 11:29:04 2015 +0000 +++ b/Tarefa1.cpp Thu Mar 12 13:50:57 2015 +0000 @@ -8,13 +8,18 @@ #define ESCALA_DE_TENSAO 3.3 #define TAM_VALORES_MEDIA_AMPLITUDE 10 - +Timer t; Ticker flipper; AnalogIn ain0(PTB0); AnalogIn ain1(PTB1); DigitalOut myled(LED1); int aux2 = 0; // Variavel auxiliar, para indicar quando realizar uma amostragem +typedef struct { + float valorMedido; + float tempo; +} Medida; + void flip() { aux2 = !aux2; } @@ -54,23 +59,23 @@ mediaValoresMinimos = calculaMedia(valoresMinimos, tamValores); float amplitude = (mediaValoresMaximos - mediaValoresMinimos) * ESCALA_DE_TENSAO; - float tensaoEficaz = amplitude / 1.414; + float tensaoEficaz = amplitude / (sqrt((float) 2)); // Para printar valores maximos e minimos printf("Vetor de valores MAX: ["); for(int i = 0; i < tamValores; i++) { printf(" %.2f,", valoresMaximos[i]); } - printf("]\n"); + printf("]\n\r"); printf("Vetor de valores MIN: ["); for(int i = 0; i < tamValores; i++) { printf("%.2f, ", valoresMinimos[i]); } - printf("]\n"); - printf("Media valores MAX: %.2f\n", mediaValoresMaximos); - printf("Media valores MIN: %.2f\n", mediaValoresMinimos); - printf("Amplitude calculada em volts: %.2f\n", amplitude); - printf("Tensao eficaz de %.2f volts\n", tensaoEficaz); + printf("]\n\r"); + printf("Media valores MAX: %.2f\n\r", mediaValoresMaximos); + printf("Media valores MIN: %.2f\n\r", mediaValoresMinimos); + printf("Amplitude calculada em volts: %.2f\n\r", amplitude); + printf("Tensao eficaz de %.2f volts\n\r", tensaoEficaz); return tensaoEficaz; } @@ -82,7 +87,7 @@ int main() { // valor mínimo de ts: ~0.0001 (10 kHz) - int contador = 0, tamanho=1000, opçao; // Tamanho dos vetores de amostras. + int contador = 0, tamanho=1000; // Tamanho dos vetores de amostras. float ts = 0.0001, sinal0[tamanho], sinal1[tamanho], n1= 0, sinalDC; myled = 0; // Acende led @@ -102,14 +107,17 @@ flipper.detach(); /* para o ticker */ myled = 1; - while (1){ - printf ("A tensão DC é: %f ", sinalDC); + + printf ("A tensao DC e: %f ", sinalDC); - printf ("A tensão AC é: %f.2", calculaTensaoACSenoidal(&sinal0, tamanho); + printf ("A tensao AC eh: %f.2", calculaTensaoACSenoidal(sinal0, tamanho)); - } + // Apaga led quando termina // Coloque aqui o seu programa para tratamento dos dados. } + + +