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.
Fork of TutoElectro_PWM by
Diff: main.cpp
- Revision:
- 2:be4ea24f1cdd
- Parent:
- 1:778a662bafcf
- Child:
- 3:7de9f8f4a15e
--- a/main.cpp Tue Feb 03 17:10:33 2015 +0000 +++ b/main.cpp Fri Dec 04 16:30:11 2015 +0000 @@ -1,78 +1,44 @@ #include "mbed.h" - -AnalogOut dac(PTE30); - +#include "TextLCD.h" +#include "AnalogIn.h" +PwmOut pwmsal(PTD2); +AnalogIn pwment(PTB1); Serial pc(USBTX,USBRX); - -uint16_t dacIntValue = 0; - -float dacValue = 0; -float dacVoltage = 0; - -void rxInterrupt() -{ - - switch(pc.getc()) { - - case 'a': - - if(dacValue>0.001){ - dacValue = dacValue - 0.001; - } - - dacIntValue = (uint16_t)(4095*dacValue); - - break; - - case 's': - - if(dacValue<1){ - dacValue = dacValue + 0.001; - } - - dacIntValue = (uint16_t)(4095*dacValue); +float valorpwm; +TextLCD lcd(PTD3, PTA12, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); +AnalogIn presionin(PTB3); +float caspresion; - break; - - case 'f': - - if(dacIntValue> 1){ - dacIntValue = dacIntValue - 1; - } - - dacValue = dacIntValue/4095.0; - - - break; - - - case 'g': - - if(dacIntValue< 4095){ - dacIntValue = dacIntValue + 1; - } - - dacValue = dacIntValue/4095.0; - - break; - - default: break; - } - - dacVoltage = 3.3 * dacValue; - - dac.write(dacValue); - - - pc.printf("DAC Value: %i, DAC Voltage: %.4f \r\n", dacIntValue, dacVoltage); - -} int main() { - + + while(1){ + + caspresion = presionin.read() * 3.3; + lcd.cls(); + lcd.locate(0,1); + lcd.printf("%.2f",caspresion); + + if(caspresion >= 2.34){ + lcd.locate(0,0); + lcd.printf("maximo"); + } + + if(caspresion >= 1.68 && caspresion <= 1.85){ + lcd.locate(0,0); + lcd.printf("medio"); + } + + if(caspresion <= 1.03){ + lcd.locate(0,0); + lcd.printf("minimo"); + } + pc.baud(115200); - pc.attach(&rxInterrupt); - - while(1); + pwmsal.period_ms(5); + valorpwm = pwment.read(); + pwmsal.write(valorpwm); + wait(1); + } }