Display 16x2 is used to counting numbers show, ascending or descending in 4 positions
Dependencies: Debounced TextLCDmo mbed
main.cpp
- Committer:
- mandres7
- Date:
- 2013-10-18
- Revision:
- 0:7f914d2c35cb
File content as of revision 0:7f914d2c35cb:
#include "mbed.h" #include "TextLCD.h" #include "DebouncedIn.h" TextLCD lcd(PTC10, PTC11, PTC12, PTC13, PTC16, PTC17); // rs, e, d4-d7.. Nota: No se quiere función de lectura, luego ese puerto a tierra. //lectura=1, escritura=0 PwmOut rled(LED_BLUE); DebouncedIn next(PTE2); DebouncedIn up(PTE3); DebouncedIn down(PTE4); int C1=0x0F; int main() { int c; int v,b,n,m; v=0; b=0; n=0; m=0; c=0; lcd.cls(); lcd.locate(0,0); lcd.printf("sp:%d",v); lcd.locate(8,0); lcd.printf("kp:%d",b); lcd.locate(0,1); lcd.printf("ki:%d",n); lcd.locate(8,1); lcd.printf("kd:%d",m); //SP while (1){ if (next.falling()){ c++; while (c>3){ c=0; } //Salto a SP if (c==0){ lcd.locate(3,0); lcd.putc(0xFE); lcd.writeCommand(C1); lcd.locate(3,0); lcd.printf("%d",v); while(c==0){ if(up.falling()){ v++; lcd.locate(3,0); lcd.printf("%d",v); } if(down.falling()){ v--; if(v<0){ v=0; lcd.locate(4,0); lcd.putc(0xFE); } if(v<10){ lcd.locate(4,0); lcd.putc(0xFE); } lcd.locate(3,0); lcd.printf("%d",v); } if(next.falling()){ c++; } } } //Salto a Kp if (c==1){ lcd.locate(11,0); lcd.putc(0xFE); lcd.writeCommand(C1); lcd.locate(11,0); lcd.printf("%d",b); while(c==1){ if(up.falling()){ b++; lcd.locate(11,0); lcd.printf("%d",b); } if(down.falling()){ b--; if(b<0){ b=0; lcd.locate(12,0); lcd.putc(0xFE); } if(b<10){ lcd.locate(12,0); lcd.putc(0xFE); } lcd.locate(11,0); lcd.printf("%d",b); } if(next.falling()){ c++; } } } //Salto a Kp if (c==2){ lcd.locate(3,1); lcd.putc(0xFE); lcd.writeCommand(C1); lcd.locate(3,1); lcd.printf("%d",n); while(c==2){ if(up.falling()){ n++; lcd.locate(3,1); lcd.printf("%d",n); } if(down.falling()){ n--; if(n<0){ n=0; lcd.locate(4,1); lcd.putc(0xFE); } if(n<10){ lcd.locate(4,1); lcd.putc(0xFE); } lcd.locate(3,1); lcd.printf("%d",n); } if(next.falling()){ c++; } } } //Salto a Kp if (c==3){ lcd.locate(11,1); lcd.putc(0xFE); lcd.writeCommand(C1); lcd.locate(11,1); lcd.printf("%d",m); while(c==3){ if(up.falling()){ m++; lcd.locate(11,1); lcd.printf("%d",m); } if(down.falling()){ m--; if(m<0){ m=0; lcd.locate(12,1); lcd.putc(0xFE); } if(m<10){ lcd.locate(12,1); lcd.putc(0xFE); } lcd.locate(11,1); lcd.printf("%d",m); } if(next.falling()){ c++; } } } // } } }