bla

You are viewing an older revision! See the latest version

Homepage

Calculator: Addirion and Subtraction 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

  1. include "mbed.h"
  2. 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); uint8_t step = 0; char calcOp = '+'; bool updateLcd = true; int value1, value2, result;

prototypes void count_up(){ switch (step) { case 0 : value1++; updateLcd = true; break; case 1 : step = 2; break; case 2 : value2++; updateLcd = true; break; } }

void count_down(){ switch (step) { case 0 : value1; updateLcd = true; break; case 1 : step = 2; break; case 2 : value2; updateLcd = true; break; }

}

void calculate(){ step = 3; result = 0; if (calcOp == '+') result = value1 + value2; if (calcOp == '-') result = value1 - value2; updateLcd = true; }

void opChange(){ step = 1; if (calcOp == '+') calcOp = '-'; else calcOp = '+'; updateLcd = true; }

functions uint8_t debounce(DigitalIn myIn) {

  1. define LEVEL_CHECKS 8
  2. 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

main program int main() { C12832_LCD lcd; lcd.cls(); lcd.locate(0,0); lcd.printf("5ABELI: Calulator");

iiLeft.rise(&count_up); iiRight.rise(&count_down); iiUp.rise(&opChange); iiDown.rise(&opChange); iiCenter.rise(&calculate);

while(1) { if (updateLcd) { updateLcd = false; switch (step) { case 0: lcd.locate(0,10); lcd.printf("%d", value1); break;

case 1: lcd.locate(7,10); lcd.printf("%c",calcOp); break;

case 2: lcd.locate(13,10); lcd.printf("%d", value2); break;

case 3: lcd.locate(21,10); lcd.printf("= %d",result); break;

default: break; } } } }


All wikipages