Ricardo Kannebley
/
projeto_estufa
Repositório para o trabalho semestral (Projeto Estufa) de Microcontroladores.
bomba-sensor_umidade/main.cpp@0:cdb895446e57, 2018-06-06 (annotated)
- Committer:
- RickBadKan
- Date:
- Wed Jun 06 19:17:52 2018 +0000
- Revision:
- 0:cdb895446e57
- Child:
- 1:4d014defc573
Primeiro commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RickBadKan | 0:cdb895446e57 | 1 | #include "mbed.h" |
RickBadKan | 0:cdb895446e57 | 2 | |
RickBadKan | 0:cdb895446e57 | 3 | // Biblioteca para utilização do LCD Display |
RickBadKan | 0:cdb895446e57 | 4 | #include "C12832.h" |
RickBadKan | 0:cdb895446e57 | 5 | |
RickBadKan | 0:cdb895446e57 | 6 | // Initialize a pins to perform analog input and digital output fucntions |
RickBadKan | 0:cdb895446e57 | 7 | AnalogIn potenciometro(p19); |
RickBadKan | 0:cdb895446e57 | 8 | AnalogIn sensor(p15); |
RickBadKan | 0:cdb895446e57 | 9 | |
RickBadKan | 0:cdb895446e57 | 10 | //DigitalOut blue(p25); |
RickBadKan | 0:cdb895446e57 | 11 | //DigitalOut green(p24); |
RickBadKan | 0:cdb895446e57 | 12 | |
RickBadKan | 0:cdb895446e57 | 13 | // Visualização PWM LED1 |
RickBadKan | 0:cdb895446e57 | 14 | PwmOut l_out(LED1); |
RickBadKan | 0:cdb895446e57 | 15 | PwmOut pwm(p24); |
RickBadKan | 0:cdb895446e57 | 16 | |
RickBadKan | 0:cdb895446e57 | 17 | // Default initialization for LCD |
RickBadKan | 0:cdb895446e57 | 18 | C12832 lcd(p5, p7, p6, p8, p11); |
RickBadKan | 0:cdb895446e57 | 19 | |
RickBadKan | 0:cdb895446e57 | 20 | int main(void) |
RickBadKan | 0:cdb895446e57 | 21 | { |
RickBadKan | 0:cdb895446e57 | 22 | lcd.cls(); |
RickBadKan | 0:cdb895446e57 | 23 | |
RickBadKan | 0:cdb895446e57 | 24 | // Codigo PWM |
RickBadKan | 0:cdb895446e57 | 25 | int i; |
RickBadKan | 0:cdb895446e57 | 26 | float pw; // signal pulse width from 0 to 1 |
RickBadKan | 0:cdb895446e57 | 27 | int reps; // pulse repetitions |
RickBadKan | 0:cdb895446e57 | 28 | float level[]= {0, 0.2, 0.4, 0.6 }; |
RickBadKan | 0:cdb895446e57 | 29 | |
RickBadKan | 0:cdb895446e57 | 30 | pwm.period_us(100); |
RickBadKan | 0:cdb895446e57 | 31 | |
RickBadKan | 0:cdb895446e57 | 32 | while (1) { |
RickBadKan | 0:cdb895446e57 | 33 | |
RickBadKan | 0:cdb895446e57 | 34 | |
RickBadKan | 0:cdb895446e57 | 35 | for(i=0; i<=3; i+=1) { |
RickBadKan | 0:cdb895446e57 | 36 | pw = level[i]; // pulse width steps of 0, 0.2, 0.4, and 0.6 |
RickBadKan | 0:cdb895446e57 | 37 | for(reps=0; reps<=10000; reps++) { // for visual delay |
RickBadKan | 0:cdb895446e57 | 38 | |
RickBadKan | 0:cdb895446e57 | 39 | l_out.write(pw); |
RickBadKan | 0:cdb895446e57 | 40 | } |
RickBadKan | 0:cdb895446e57 | 41 | } |
RickBadKan | 0:cdb895446e57 | 42 | |
RickBadKan | 0:cdb895446e57 | 43 | pwm.write(0.5f); |
RickBadKan | 0:cdb895446e57 | 44 | |
RickBadKan | 0:cdb895446e57 | 45 | /* |
RickBadKan | 0:cdb895446e57 | 46 | Test the voltage on the initialized analog pin |
RickBadKan | 0:cdb895446e57 | 47 | and if greater than 0.3 * VCC set the blue on |
RickBadKan | 0:cdb895446e57 | 48 | otherwise green on |
RickBadKan | 0:cdb895446e57 | 49 | */ |
RickBadKan | 0:cdb895446e57 | 50 | //if(potenciometro > 0.3f) { // Valor capturado somente chamando o nome do AnalogIn |
RickBadKan | 0:cdb895446e57 | 51 | // blue = 1; |
RickBadKan | 0:cdb895446e57 | 52 | // green = 0; |
RickBadKan | 0:cdb895446e57 | 53 | //} |
RickBadKan | 0:cdb895446e57 | 54 | //else { |
RickBadKan | 0:cdb895446e57 | 55 | // blue = 0; |
RickBadKan | 0:cdb895446e57 | 56 | // green = 1; |
RickBadKan | 0:cdb895446e57 | 57 | //} |
RickBadKan | 0:cdb895446e57 | 58 | |
RickBadKan | 0:cdb895446e57 | 59 | // Print the % value and the absolute value from the sensor at p15 |
RickBadKan | 0:cdb895446e57 | 60 | lcd.locate(0,3); |
RickBadKan | 0:cdb895446e57 | 61 | lcd.printf( "Percentage: %3.3f%% \n", sensor.read() * 100.0f ); |
RickBadKan | 0:cdb895446e57 | 62 | lcd.printf( "Absolute Value: %2.3f", sensor.read() ); |
RickBadKan | 0:cdb895446e57 | 63 | wait(0.02f); |
RickBadKan | 0:cdb895446e57 | 64 | lcd.cls(); |
RickBadKan | 0:cdb895446e57 | 65 | } |
RickBadKan | 0:cdb895446e57 | 66 | } |