Alejandro Marin
/
Tarea1procesadores
impresion en LCD con boton de incremento y decremento encada variable en el LCD
Revision 0:6c9cb98ad497, committed 2013-10-16
- Comitter:
- amarincan
- Date:
- Wed Oct 16 16:38:18 2013 +0000
- Commit message:
- Tarea1
Changed in this revision
diff -r 000000000000 -r 6c9cb98ad497 DebouncedIn.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebouncedIn.cpp Wed Oct 16 16:38:18 2013 +0000 @@ -0,0 +1,91 @@ +#include "DebouncedIn.h" +#include "mbed.h" + +/* + * Constructor + */ +DebouncedIn::DebouncedIn(PinName in) + : _in(in) { + + // reset all the flags and counters + _samples = 0; + _output = 0; + _output_last = 0; + _rising_flag = 0; + _falling_flag = 0; + _state_counter = 0; + + // Attach ticker + _ticker.attach(this, &DebouncedIn::_sample, 0.005); +} + +void DebouncedIn::_sample() { + + // take a sample + _samples = _samples >> 1; // shift left + + if (_in) { + _samples |= 0x80; + } + + // examine the sample window, look for steady state + if (_samples == 0x00) { + _output = 0; + } + else if (_samples == 0xFF) { + _output = 1; + } + + + // Rising edge detection + if ((_output == 1) && (_output_last == 0)) { + _rising_flag++; + _state_counter = 0; + } + + // Falling edge detection + else if ((_output == 0) && (_output_last == 1)) { + _falling_flag++; + _state_counter = 0; + } + + // steady state + else { + _state_counter++; + } + + // update the output + _output_last = _output; + +} + + + +// return number of rising edges +int DebouncedIn::rising(void) { + int return_value = _rising_flag; + _rising_flag = 0; + return(return_value); +} + +// return number of falling edges +int DebouncedIn::falling(void) { + int return_value = _falling_flag; + _falling_flag = 0; + return(return_value); +} + +// return number of ticsk we've bene steady for +int DebouncedIn::steady(void) { +return(_state_counter); +} + +// return the debounced status +int DebouncedIn::read(void) { + return(_output); +} + +// shorthand for read() +DebouncedIn::operator int() { + return read(); +} \ No newline at end of file
diff -r 000000000000 -r 6c9cb98ad497 DebouncedIn.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebouncedIn.h Wed Oct 16 16:38:18 2013 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" + + class DebouncedIn { + public: + DebouncedIn(PinName in); + + int read (void); + operator int(); + + int rising(void); + int falling(void); + int steady(void); + + private : + // objects + DigitalIn _in; + Ticker _ticker; + + // function to take a sample, and update flags + void _sample(void); + + // counters and flags + int _samples; + int _output; + int _output_last; + int _rising_flag; + int _falling_flag; + int _state_counter; + + }; + +
diff -r 000000000000 -r 6c9cb98ad497 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Wed Oct 16 16:38:18 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 6c9cb98ad497 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Oct 16 16:38:18 2013 +0000 @@ -0,0 +1,121 @@ +#include "mbed.h" +#include "DebouncedIn.h" +#include "TextLCD.h" + +TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 +int i,Sp=0,Kp,Ki,Kd; +DigitalOut l1(LED1); +DigitalOut l2(LED2); +int main() +{ + DebouncedIn button1(PTC12); + DebouncedIn button2(PTC13); + DebouncedIn button3(PTC16); + lcd.writeCommand(0x0E); + lcd.printf("Sp= Kp="); + lcd.locate(0,1); + lcd.printf("Ki= Kd="); + lcd.locate(2,0); + lcd.printf("="); + + while(1) { + + if(button1.falling()) { + + switch(i) { + case 0: + lcd.locate(2,0); + lcd.printf("= "); + lcd.locate(3,0); + lcd.printf("%d",++Sp); + + break; + case 1: + lcd.locate(10,0); + lcd.printf("= "); + lcd.locate(11,0); + lcd.printf("%d",++Kp); + break; + case 2: + + lcd.locate(2,1); + lcd.printf("= "); + lcd.locate(3,1); + lcd.printf("%d",++Ki); + break; + case 3: + lcd.locate(10,1); + lcd.printf("= "); + lcd.locate(11,1); + lcd.printf("%d",++Kd); + break; + } + } + if(button2.falling()) { + switch(i) { + case 0: + if(Sp<0) { + Sp=0; + } + lcd.locate(2,0); + lcd.printf("= "); + lcd.locate(3,0); + lcd.printf("%d",Sp--); + break; + case 1: + if(Kp<0) { + Kp=0; + } + lcd.locate(10,0); + lcd.printf("= "); + lcd.locate(11,0); + lcd.printf("%d",Kp--); + break; + case 2: + + if(Ki<0) { + Ki=0; + } + lcd.locate(2,1); + lcd.printf("= "); + lcd.locate(3,1); + lcd.printf("%d",Ki--); + break; + case 3: + + if(Kd<0) { + Kd=0; + } + lcd.locate(10,1); + lcd.printf("= "); + lcd.locate(11,1); + lcd.printf("%d",Kd--); + break; + } + } + if(button3.falling()) { + i++; + if(i>3) { + i=0; + } + switch (i) { + case 0: + lcd.locate(2,0); + lcd.printf("="); + break; + case 1: + lcd.locate(10,0); + lcd.printf("="); + break; + case 2: + lcd.locate(2,1); + lcd.printf("="); + break; + case 3: + lcd.locate(10,1); + lcd.printf("="); + break; + } + } + } +} \ No newline at end of file
diff -r 000000000000 -r 6c9cb98ad497 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Oct 16 16:38:18 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file