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.
10 years, 1 month ago. This question has been closed. Reason: Unclear question
test
// Calculator: Addition and Subtraction
// Joystick Up: + ; Joystick Down - (Operator selection)
// Joystick Left: count value up (+1); Joystick Right: count value down (-1)
// Joystick Center: 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);
uint8_t step = 0;
char calcOp = '+';
bool updateLcd = true;
int value1, value2, result;
// 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
// main program
int main() {
C12832_LCD lcd;
lcd.cls();
lcd.locate(0,0);
lcd.printf("5ABELI: Calulator");
while(1) {
if (updateLcd) {
updateLcd = false;
switch (step) {
case 0:
lcd.locate(0, 20);
lcd.printf("%d ", value1);
break;
case 1:
break;
default: break;
}
}
}
}
When posting code please use
<<code>>tags so that the formatting is correct e.g.See the editing tips link for more details.
posted by Andy A 15 Apr 2016