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 MicroBitDALImageRewrite by
inc/MicroBitButton.h@1:3e0360107f98, 2015-04-16 (annotated)
- Committer:
- finneyj
- Date:
- Thu Apr 16 13:50:24 2015 +0000
- Revision:
- 1:3e0360107f98
- Parent:
- 0:47d8ba08580f
Updates to include:; ; - Asynchronous Scrolltext(); - First iteration of MessageBus implementation; - Hardware configuration for SquareBoard protoype
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| finneyj | 0:47d8ba08580f | 1 | /** |
| finneyj | 0:47d8ba08580f | 2 | * Class definition for MicroBit Button. |
| finneyj | 0:47d8ba08580f | 3 | * |
| finneyj | 0:47d8ba08580f | 4 | * Represents a single button on the device. |
| finneyj | 0:47d8ba08580f | 5 | */ |
| finneyj | 0:47d8ba08580f | 6 | |
| finneyj | 0:47d8ba08580f | 7 | #ifndef MICROBIT_BUTTON_H |
| finneyj | 0:47d8ba08580f | 8 | #define MICROBIT_BUTTON_H |
| finneyj | 0:47d8ba08580f | 9 | |
| finneyj | 1:3e0360107f98 | 10 | #include "mbed.h" |
| finneyj | 1:3e0360107f98 | 11 | |
| finneyj | 1:3e0360107f98 | 12 | #define MICROBIT_PIN_LEFT_BUTTON P0_23 |
| finneyj | 1:3e0360107f98 | 13 | |
| finneyj | 1:3e0360107f98 | 14 | #define MICROBIT_BUTTON_EVT_DOWN 1 |
| finneyj | 1:3e0360107f98 | 15 | #define MICROBIT_BUTTON_EVT_UP 2 |
| finneyj | 1:3e0360107f98 | 16 | |
| finneyj | 1:3e0360107f98 | 17 | |
| finneyj | 1:3e0360107f98 | 18 | |
| finneyj | 0:47d8ba08580f | 19 | class MicroBitButton |
| finneyj | 0:47d8ba08580f | 20 | { |
| finneyj | 0:47d8ba08580f | 21 | /** |
| finneyj | 0:47d8ba08580f | 22 | * Unique, enumerated ID for this component. |
| finneyj | 0:47d8ba08580f | 23 | * Used to track asynchronous events in the event bus. |
| finneyj | 0:47d8ba08580f | 24 | */ |
| finneyj | 1:3e0360107f98 | 25 | |
| finneyj | 1:3e0360107f98 | 26 | int id; // Event Bus ID |
| finneyj | 1:3e0360107f98 | 27 | PinName name; // mBed pin name of this pin. |
| finneyj | 1:3e0360107f98 | 28 | DigitalIn pin; // The mBed object looking after this pin at any point in time (may change!). |
| finneyj | 1:3e0360107f98 | 29 | InterruptIn irq; // Handler to detect change events. |
| finneyj | 1:3e0360107f98 | 30 | |
| finneyj | 1:3e0360107f98 | 31 | void rising(); // Interrupt on change handler |
| finneyj | 1:3e0360107f98 | 32 | void falling(); // Interrupt on change handler |
| finneyj | 0:47d8ba08580f | 33 | |
| finneyj | 0:47d8ba08580f | 34 | public: |
| finneyj | 0:47d8ba08580f | 35 | /** |
| finneyj | 0:47d8ba08580f | 36 | * Constructor. |
| finneyj | 0:47d8ba08580f | 37 | * Create a pin representation with the given ID. |
| finneyj | 0:47d8ba08580f | 38 | * @param id the ID of the new LED object. |
| finneyj | 1:3e0360107f98 | 39 | * @param name the physical pin on the processor that this butotn is connected to. |
| finneyj | 0:47d8ba08580f | 40 | */ |
| finneyj | 1:3e0360107f98 | 41 | MicroBitButton(int id, PinName name); |
| finneyj | 0:47d8ba08580f | 42 | |
| finneyj | 0:47d8ba08580f | 43 | /** |
| finneyj | 0:47d8ba08580f | 44 | * Tests if this Button is currently pressed. |
| finneyj | 0:47d8ba08580f | 45 | * @return 1 if this button is pressed, 0 otherwise. |
| finneyj | 0:47d8ba08580f | 46 | */ |
| finneyj | 0:47d8ba08580f | 47 | int isPressed(); |
| finneyj | 0:47d8ba08580f | 48 | |
| finneyj | 0:47d8ba08580f | 49 | }; |
| finneyj | 0:47d8ba08580f | 50 | |
| finneyj | 0:47d8ba08580f | 51 | #endif |
