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.
Revision 6:8dc45846a8db, committed 2020-02-13
- Comitter:
- ex19397
- Date:
- Thu Feb 13 07:26:10 2020 +0000
- Parent:
- 5:86742cfaf4e4
- Commit message:
- Final
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Jan 30 08:16:04 2020 +0000
+++ b/main.cpp Thu Feb 13 07:26:10 2020 +0000
@@ -6,16 +6,22 @@
// is pressed
// The callback uses a shared variable to signal another thread
-InterruptIn button(PTD0); // Pin must be on ports A or D
-DigitalOut led(LED_GREEN);
+InterruptIn button(PTD0);// Pin must be on ports A or D
+InterruptIn button1(PTD5);
+DigitalOut led(LED_BLUE);
+DigitalOut led1(LED_RED);
volatile int pressEvent = 0 ;
+volatile int pressEvent1 = 0 ;
// This function is invoked when then interrupt occurs
// Signal that the button has been pressed
// Note: bounce may occur
void buttonCallback(){
- pressEvent = 1 ;
+ pressEvent = !pressEvent;
+}
+void buttonCallback1(){
+ pressEvent1 = !pressEvent1 ;
}
/* ---- Main function (default thread) ----
@@ -24,13 +30,17 @@
int main() {
button.mode(PullUp); // Ensure button i/p has pull up
button.fall(&buttonCallback) ; // Attach function to falling edge
-
+ button1.mode(PullUp); // Ensure button i/p has pull up
+ button1.fall(&buttonCallback1) ; // Attach function to falling edge
+
while(true) {
// Toggle the LED every time the button is pressed
- if (pressEvent) {
+ if (pressEvent) {
led = !led ;
- pressEvent = 0 ; // Clear the event variable
}
- ThisThread::sleep_for(100) ; // delay for 100ms
+ if (pressEvent1) {
+ led1 = !led1 ;
+ }
+ ThisThread::sleep_for(500) ; // delay for 100ms
}
}
\ No newline at end of file