bdfagfdasgfd
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 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() % 19 + (-9);
/* switch(OP) { case '+' : RandomNumber = rand() % 100 + 1; break; case '-' : RandomNumber2 = rand() % 100 + 1; break; }
- /
pc.printf("BLABLABLA");
return 0; }
int printOutput(){ 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]; }
}
}