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.
Diff: main.cpp
- Revision:
- 0:76669ad2c30b
- Child:
- 1:0072ef0302ec
diff -r 000000000000 -r 76669ad2c30b main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Nov 26 09:31:01 2014 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+
+DigitalIn b1(p8);
+DigitalIn b2(p14);
+DigitalOut led[] = {(LED1), (LED2),(LED3),(LED4)};
+
+
+bool shortPress =false;
+bool longPress = false;
+
+int counterTime = 0;
+int counterBlink=4;
+
+Ticker timeTasterTest;
+Ticker timeLedTest;
+
+void tasterTest();
+void ledTest();
+
+int main()
+{
+ while(1) {
+ timeTasterTest.attach(&tasterTest,0.01);
+ timeLedTest.attach(&ledTest,0.5);
+ }
+}
+
+void ledTest()
+{
+ if(shortPress) {
+ if(counterBlink>=0) {
+ led[1]=!led[1];
+ counterBlink--;
+ } else {
+ led[1]=0;
+ counterBlink=4;
+ }
+ }
+ if(longPress) {
+ led[1]=!led[1];
+ }
+
+}
+
+void tasterTest()
+{
+ if(!b1) {
+ if(counterTime<500) {
+ longPress=false;
+ shortPress=true;
+ counterTime ++;
+ } else {
+ counterTime=0;
+ longPress=true;
+ shortPress=false;
+ }
+ } else {
+ if(longPress) {
+ counterTime=0;
+ longPress=false;
+ shortPress=false;
+ }
+ }
+}