Ricardo Kannebley
/
projeto_estufa
Repositório para o trabalho semestral (Projeto Estufa) de Microcontroladores.
Diff: bomba-sensor_umidade/main.cpp
- Revision:
- 0:cdb895446e57
- Child:
- 1:4d014defc573
diff -r 000000000000 -r cdb895446e57 bomba-sensor_umidade/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bomba-sensor_umidade/main.cpp Wed Jun 06 19:17:52 2018 +0000 @@ -0,0 +1,66 @@ +#include "mbed.h" + +// Biblioteca para utilização do LCD Display +#include "C12832.h" + +// Initialize a pins to perform analog input and digital output fucntions +AnalogIn potenciometro(p19); +AnalogIn sensor(p15); + +//DigitalOut blue(p25); +//DigitalOut green(p24); + +// Visualização PWM LED1 +PwmOut l_out(LED1); +PwmOut pwm(p24); + +// Default initialization for LCD +C12832 lcd(p5, p7, p6, p8, p11); + +int main(void) +{ + lcd.cls(); + + // Codigo PWM + int i; + float pw; // signal pulse width from 0 to 1 + int reps; // pulse repetitions + float level[]= {0, 0.2, 0.4, 0.6 }; + + pwm.period_us(100); + + while (1) { + + + for(i=0; i<=3; i+=1) { + pw = level[i]; // pulse width steps of 0, 0.2, 0.4, and 0.6 + for(reps=0; reps<=10000; reps++) { // for visual delay + + l_out.write(pw); + } + } + + pwm.write(0.5f); + + /* + Test the voltage on the initialized analog pin + and if greater than 0.3 * VCC set the blue on + otherwise green on + */ + //if(potenciometro > 0.3f) { // Valor capturado somente chamando o nome do AnalogIn + // blue = 1; + // green = 0; + //} + //else { + // blue = 0; + // green = 1; + //} + + // Print the % value and the absolute value from the sensor at p15 + lcd.locate(0,3); + lcd.printf( "Percentage: %3.3f%% \n", sensor.read() * 100.0f ); + lcd.printf( "Absolute Value: %2.3f", sensor.read() ); + wait(0.02f); + lcd.cls(); + } +} \ No newline at end of file