Anastasios Barlas
/
digitalInInterrupt_sample
Lab 2 answer to part 2
Fork of digitalInInterrupt_sample by
Diff: main.cpp
- Revision:
- 4:86fd8725e198
- Parent:
- 3:05b6a1431a6b
diff -r 05b6a1431a6b -r 86fd8725e198 main.cpp --- a/main.cpp Tue Jan 16 18:14:21 2018 +0000 +++ b/main.cpp Thu Feb 01 17:57:01 2018 +0000 @@ -7,17 +7,23 @@ // The callback uses a shared variable to signal another thread InterruptIn button(PTD0); -DigitalOut led(LED_GREEN); +InterruptIn button2(PTD5); +DigitalOut led(LED_RED); +DigitalOut led2(LED_BLUE); volatile int pressEvent = 0 ; - +volatile int pressEvent2 = 0 ; +volatile int x; +volatile int z; // This function is invoked when then interrupt occurs // Signal that the button has been pressed // Note: bounce may occur void buttonCallback(){ pressEvent = 1 ; } - +void button2Callback(){ + pressEvent2 = 1 ; +} /* ---- Main function (default thread) ---- Note that if this thread completes, nothing else works */ @@ -25,12 +31,30 @@ button.mode(PullUp); // Ensure button i/p has pull up button.fall(&buttonCallback) ; // Attach function to falling edge + button2.mode(PullUp); // Ensure button i/p has pull up + button2.fall(&button2Callback) ; // Attach function to falling edge while(true) { // Toggle the LED every time the button is pressed if (pressEvent) { - led = !led ; + + x=!x; + if (x==1){ + //led=!led; + } pressEvent = 0 ; // Clear the event variable } - Thread::wait(100) ; + if (x==0){ + led = !led;} + // led2 = !led2 ; + if (pressEvent2) { + z=!z; + if (z==1){ + //led2=!led2; + } + pressEvent2 = 0 ; // Clear the event variable + } + if (z==0){ + led2 = !led2;} + Thread::wait(500) ; } } \ No newline at end of file