Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
You are viewing an older revision! See the latest version
Homepage
#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
unsigned int newEvent =0;
unsigned int event=0, state=0;
char OP;
int erg;
int noFunction();
int getOperator();
int printOutput();
uint8_t debounce(DigitalIn myIn);
uint8_t nextstate_tab[2][2]=
// current event/ present state 0 1
//----------------------
/* Event 0 (Joystick UP) */{{ 1, 1 },
/* Event 1 (Eingabe ) */ { 0, 0 }};
int (*action[2][2])()= // 0 1
/* event 0 */ {{ getOperator, noFunction },
/* event 1 */ { noFunction, printOutput }};
int noFunction() {
return 0;
}
int getOperator() {
int RandomNumber1;
int RandomNumber2;
OP = pc.getc();
RandomNumber1 = rand() % 100 + 1;
RandomNumber2 = rand() % 100 + (-50);
switch(OP) {
case '+' : erg = RandomNumber1 + RandomNumber2;
case '-' : erg = RandomNumber1 - RandomNumber2;
}
return 0;
}
int printOutput(){
pc.printf(erg);
return 0;
}
void init() {
newEvent = false;
state=0;
event=0;
}
unsigned char debounce(PinName name, unsigned char samples) {
DigitalIn joystick(name);
unsigned char i = 0;
for(unsigned char j=0; j < samples; j++) {
if(joystick == 1)
j++;
else {
j = 0;
i++;
}
if(j >= samples)
break;
if(i >= samples)
break;
wait(0.001);
}
return joystick;
}
int main() {
unsigned char released = 0;
init();
pc.printf("Random Calculator mit der Taste JoyStick UP starten: Mark Ilgerl");
while(1) {
if(debounce(p15, 6)) {
if (released == 1) {
event = 0;
newEvent =1;
released =0;
}
}
else {
released =1;
}
if (newEvent==1) {
newEvent =0;
(*action[event][state])();
state=nextstate_tab[event][state];
}
}
}