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:
- 2:af576070220a
- Parent:
- 1:c186d9b63164
- Child:
- 3:896a932d47fc
--- a/main.cpp Thu Oct 06 14:05:24 2022 +0000
+++ b/main.cpp Thu Oct 06 14:44:47 2022 +0000
@@ -7,15 +7,48 @@
int main() {
+int currentstate=0;
+int previousstate=0;
+int counter=0;
+
while(1) {
- if (button.read()==1){
+
+ currentstate=button.read(); // set current state
+
+ if (currentstate==1){ //blinks 1s interval when pressed
myled2=!myled2;
wait(1);
+
+ if (currentstate==previousstate){
+ }
+
+ else{ // change in state adds counter
+ counter=counter+1;
+ pc.printf("count=%i \r\n",counter);
+ }
+
} //if
- if (button.read()==0){
+
+ else { //blinks 0.3s interval when released
myled2=!myled2;
wait(0.3);
+
+ if (currentstate==previousstate){
+ }
+
+ else{ // change in state adds counter
+ counter=counter+1;
+ pc.printf("count=%i \r\n",counter);
+ }
+
+ } //else
+
+ if (counter==10){ // counter reaches 10 turns on led1
+ myled1=1;
} //if
-
+
+ previousstate=currentstate; //set previous state
+
} //while
+
} //main
