Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 10 months ago.
jank
Stopuhr: min:sec:hsec am LCD Joystick Up: + ; Joystick Down - Joystick Left: count value up (+1); Joystick Right: count value down (-1) Joystick Calculate Joystick Left or Joystick Right: start at input of value 1 again
- include "mbed.h"
- include "C12832_lcd.h"
InterruptIn iiUp(p15); DigitalIn diUp(p15); InterruptIn iiDown(p12); DigitalIn diDown(p12); InterruptIn iiCenter(p14); DigitalIn diCenter(p14); InterruptIn iiLeft(p13); DigitalIn diLeft(p13); InterruptIn iiRight(p16); DigitalIn diRight(p16); int step = 0; char calcOp = '+'; bool updateLcd = true; int z1=0, z2=0, er=0; C12832_LCD lcd; prototypes
functions uint8_t debounce(DigitalIn myIn) {
- define LEVEL_CHECKS 8
- define MAX_LOOPS 30 stoppt das Überprüfen des Prellen nach max. MAX_LOOPS Durchläufen unsigned char port_buffer; unsigned char debounceCounter = 0; uint8_t loopCounter = 0;
do { port_buffer = myIn; wait_us(100); loopCounter++; if(myIn == port_buffer) debounceCounter++; mindestens 'LEVEL_CHECKS' Abtastungen in Folge: gleicher Pegel else debounceCounter = 0; } while ((debounceCounter <= LEVEL_CHECKS) && (loopCounter <= MAX_LOOPS)); return loopCounter; }
ISR void Up() { switch (step) { case 0: debounce(diRight); z1=z1+1; updateLcd=true; break; case 2: debounce(diRight); z2++; updateLcd=true; break;
} }
void Down()
{
switch (step) {
case 0:
debounce(diLeft);
z1=z1-1;
updateLcd=true;
break;
case 2:
debounce(diLeft);
z2;
updateLcd=true;
break;
}
}
void st()
{
debounce(diLeft);
debounce(diRight);
debounce(diUp);
debounce(diDown);
step=step+1;
updateLcd=true;
}
void re()
{
step=0;
updateLcd=true;
} void pl() { debounce(diRight); calcOp='+'; updateLcd=true; }
void mi() { debounce(diLeft); calcOp='-'; updateLcd=true; }
main program int main() {
lcd.cls(); lcd.locate(0,0); lcd.printf("5ABELI: Calulator1");
while(1) {
if (updateLcd) { updateLcd = false; switch (step) { case 0: iiRight.rise(&Up); iiLeft.rise(&Down); iiUp.rise(&st); iiDown.rise(&st); lcd.cls(); lcd.locate(0,0); lcd.printf("5ABELI: Calulator\n"); lcd.printf("%i",z1); break;
case 1: iiRight.rise(&st); iiLeft.rise(&st); iiUp.rise(&pl); iiDown.rise(&mi); lcd.cls(); lcd.locate(0,0); lcd.printf("5ABELI: Calulator\n"); lcd.printf("%i %c",z1,calcOp);
break; case 2: iiRight.rise(&Up); iiLeft.rise(&Down); iiCenter.rise(&st); lcd.cls(); lcd.locate(0,0); lcd.printf("5ABELI: Calulator\n"); lcd.printf("%i %c %i",z1,calcOp,z2); break; case 3: if(calcOp=='-') er=z1-z2; if(calcOp=='+') er=z1+z2; iiRight.rise(&re); iiLeft.rise(&re); iiUp.rise(&re); iiDown.rise(&re); iiCenter.rise(&re); lcd.cls(); lcd.locate(0,0); lcd.printf("5ABELI: Calulator\n"); lcd.printf("%i %c %i = %i",z1,calcOp,z2,er);
default:
break; } } } }