Toggles an LED whenever a digital joystick input goes high

Dependencies:   mbed

Committer:
mb4899
Date:
Tue Feb 17 11:46:41 2015 +0000
Revision:
0:188b8ea8f365
Toggles an LED whenever a digital joystick input goes high

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mb4899 0:188b8ea8f365 1 #include "mbed.h"
mb4899 0:188b8ea8f365 2
mb4899 0:188b8ea8f365 3 InterruptIn joystick_Reset(p14); // Configure InterruptIn object with p14, which corresponds to joystick reset function
mb4899 0:188b8ea8f365 4 DigitalOut myLED(LED4); // Has to be LED1-4, not a pin
mb4899 0:188b8ea8f365 5
mb4899 0:188b8ea8f365 6 void toggle(void);
mb4899 0:188b8ea8f365 7
mb4899 0:188b8ea8f365 8 int main()
mb4899 0:188b8ea8f365 9 {
mb4899 0:188b8ea8f365 10 joystick_Reset.rise(&toggle); // Attach the address of the toggle to the rising edge
mb4899 0:188b8ea8f365 11 }
mb4899 0:188b8ea8f365 12
mb4899 0:188b8ea8f365 13 void toggle()
mb4899 0:188b8ea8f365 14 {
mb4899 0:188b8ea8f365 15 myLED=!myLED;
mb4899 0:188b8ea8f365 16 }