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.
Fork of digitalInInterrupt_sample by
Revision 4:f140d7032fea, committed 2018-02-01
- Comitter:
- Peilingyi
- Date:
- Thu Feb 01 17:56:19 2018 +0000
- Parent:
- 3:05b6a1431a6b
- Commit message:
- lab2-part2
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jan 16 18:14:21 2018 +0000
+++ b/main.cpp Thu Feb 01 17:56:19 2018 +0000
@@ -6,31 +6,69 @@
// is pressed
// The callback uses a shared variable to signal another thread
-InterruptIn button(PTD0);
-DigitalOut led(LED_GREEN);
+InterruptIn buttonblue(PTD0);
+InterruptIn buttonred(PTD5);//need to change the address
+DigitalOut ledblue(LED_BLUE);
+DigitalOut ledred(LED_RED);
-volatile int pressEvent = 0 ;
+volatile int pressREvent = 0 ;
+volatile int pressBEvent = 0 ;
+//volatile bool switchledblue = true; //switch blue led
+//volatile bool switchledred = true; //switch red led
// This function is invoked when then interrupt occurs
-// Signal that the button has been pressed
-// Note: bounce may occur
-void buttonCallback(){
- pressEvent = 1 ;
+void buttonblueCallback()
+{
+ pressBEvent = 1;
+}
+
+void buttonredCallback()
+{
+ pressREvent = 1;
}
/* ---- Main function (default thread) ----
Note that if this thread completes, nothing else works
*/
-int main() {
- button.mode(PullUp); // Ensure button i/p has pull up
- button.fall(&buttonCallback) ; // Attach function to falling edge
-
- while(true) {
- // Toggle the LED every time the button is pressed
- if (pressEvent) {
- led = !led ;
- pressEvent = 0 ; // Clear the event variable
+int main()
+{
+
+ bool allow_flash_red = true;
+ bool allow_flash_blue = true;
+
+ buttonblue.mode(PullUp);
+ buttonred.mode(PullUp); // Ensure button i/p has pull up
+
+ buttonblue.fall(&buttonblueCallback) ; // Attach function to falling edge
+ buttonred.fall(&buttonredCallback) ;
+ while (true)
+ {
+
+ if (pressREvent == 1)
+ {
+ allow_flash_red = !allow_flash_red;
+ pressREvent =0;
+ }
+
+ if (pressBEvent == 1)
+ {
+
+ allow_flash_blue = !allow_flash_blue;
+ pressBEvent = 0;
}
- Thread::wait(100) ;
+
+ if(allow_flash_red)
+ {
+ ledred = !ledred;
+ }
+
+ if(allow_flash_blue)
+ {
+ ledblue = !ledblue;
+
+ }
+
+ Thread::wait(500);
}
+
}
\ No newline at end of file
