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.
Dependencies: mbed MODSERIAL QEI
Diff: main.cpp
- Revision:
- 2:4dcdf7755a04
- Parent:
- 1:9601b4b78de5
- Child:
- 3:34f7c16a6a7f
diff -r 9601b4b78de5 -r 4dcdf7755a04 main.cpp
--- a/main.cpp Fri Sep 23 12:25:47 2016 +0000
+++ b/main.cpp Fri Sep 23 12:57:50 2016 +0000
@@ -1,59 +1,65 @@
#include "mbed.h"
-
+
DigitalOut led(LED_RED);
DigitalOut led2(LED_BLUE);
DigitalIn sw2(SW2);
-DigitalIn sw3(SW3);
+InterruptIn sw3(SW3);
Serial pc(USBTX, USBRX);
-
+int n = 0;
+
+
+void SwitchN() {
+ n++;
+ }
+
int main()
{
pc.baud(115200);
-int n;
-n = 0;
+
+ // if (sw3 == 0)
+ // { // als knopje 3 wordt ingedrukt dan wordt er 1 opgeteld bij n
+ // n++;
+ // pc.printf("%i \n\r",n);
+ // wait (0.5);
+ // }
+ // else {
+ // n=n;
+ // pc.printf("geen switch");
+ // }
+
while (true) {
-
- if (sw3 == 0){ // als knopje 3 wordt ingedrukt dan wordt er 1 opgeteld bij n
- n++;
- pc.printf("%i \n\r",n);
- wait (0.5);
- }
- else {
- n=n;
- pc.printf("geen switch\r");
- }
+ sw3.fall(&SwitchN);
if (n%2 == 0) { //runt menuutje 1 als het even is
//menu 1
- pc.printf("n is even \n\r");
- wait (0.5);
+ pc.printf("n is even \n");
+ // wait (0.5);
char c = pc.getc();
if (c == 's'){
- pc.printf("up \n\r");
+ pc.printf("up \n");
wait (0.5);
}
else if (c == 'd'){
- pc.printf("down \r\n");
+ pc.printf("down /n");
wait (0.5);}
}
else { // runt menuutje 2 als het oneven is
// menu 2
- pc.printf("n is oneven \n\r");
- wait (0.5);
+ pc.printf("n is oneven \n");
+ // wait (0.5);
char c = pc.getc();
if (c == 's'){
- pc.printf("right \n\r");
+ pc.printf("right \n");
wait (0.5);}
else if (c == 'd'){
- pc.printf("left \n\r");
+ pc.printf("left /n");
wait (0.5);}
else {}
}
}
-}
-
+}
\ No newline at end of file