![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
PWM, ancho de pulso variable, periodo variable (lectura por puerto)
Dependencies: TSI TextLCD mbed
main.cpp@0:c1fa75d95078, 2013-11-29 (annotated)
- Committer:
- avallejopo
- Date:
- Fri Nov 29 18:25:47 2013 +0000
- Revision:
- 0:c1fa75d95078
PWM, ancho de pulso variable, periodo variable (lectura por puerto)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
avallejopo | 0:c1fa75d95078 | 1 | #include "mbed.h" |
avallejopo | 0:c1fa75d95078 | 2 | #include "TSISensor.h" |
avallejopo | 0:c1fa75d95078 | 3 | #include "TextLCD.h" |
avallejopo | 0:c1fa75d95078 | 4 | |
avallejopo | 0:c1fa75d95078 | 5 | TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 |
avallejopo | 0:c1fa75d95078 | 6 | Timer t1; |
avallejopo | 0:c1fa75d95078 | 7 | float anchop=0.5; |
avallejopo | 0:c1fa75d95078 | 8 | float periodo=100; |
avallejopo | 0:c1fa75d95078 | 9 | int main(void) { |
avallejopo | 0:c1fa75d95078 | 10 | |
avallejopo | 0:c1fa75d95078 | 11 | PwmOut led(PTA5); |
avallejopo | 0:c1fa75d95078 | 12 | TSISensor tsi; |
avallejopo | 0:c1fa75d95078 | 13 | led.pulsewidth(anchop); |
avallejopo | 0:c1fa75d95078 | 14 | led.period_ms(periodo); |
avallejopo | 0:c1fa75d95078 | 15 | |
avallejopo | 0:c1fa75d95078 | 16 | while (true) { |
avallejopo | 0:c1fa75d95078 | 17 | if(tsi.readPercentage()!=0){ |
avallejopo | 0:c1fa75d95078 | 18 | led = 1.0 - tsi.readPercentage(); |
avallejopo | 0:c1fa75d95078 | 19 | lcd.cls(); |
avallejopo | 0:c1fa75d95078 | 20 | lcd.printf("PWM=%g",tsi.readPercentage()); |
avallejopo | 0:c1fa75d95078 | 21 | } |
avallejopo | 0:c1fa75d95078 | 22 | wait(0.1); |
avallejopo | 0:c1fa75d95078 | 23 | } |
avallejopo | 0:c1fa75d95078 | 24 | } |