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 frdm_echo by
main.cpp@13:019e24491f32, 2014-04-18 (annotated)
- Committer:
- silverpanda
- Date:
- Fri Apr 18 21:33:57 2014 +0000
- Revision:
- 13:019e24491f32
- Parent:
- 12:b846b64e3980
- Child:
- 14:73ef945b8def
Push button support added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
silverpanda | 0:6898e364f29a | 1 | // Print "Hello World" to the PC |
silverpanda | 0:6898e364f29a | 2 | |
silverpanda | 13:019e24491f32 | 3 | // push buttons: |
silverpanda | 13:019e24491f32 | 4 | // sw2 on PTC6 |
silverpanda | 13:019e24491f32 | 5 | // sw3 on PTA4 |
silverpanda | 13:019e24491f32 | 6 | |
silverpanda | 0:6898e364f29a | 7 | #include "mbed.h" |
silverpanda | 5:03b7c237c4c4 | 8 | #include "shell.h" |
silverpanda | 7:19da09fe546b | 9 | #include "LEDColors.h" |
silverpanda | 13:019e24491f32 | 10 | #include "PushButtons.h" |
silverpanda | 0:6898e364f29a | 11 | |
silverpanda | 6:78a965b2d2df | 12 | Ticker *scanTicker; |
silverpanda | 6:78a965b2d2df | 13 | Shell *usbSerialShell; |
silverpanda | 7:19da09fe546b | 14 | LEDColors *ledColors; |
silverpanda | 13:019e24491f32 | 15 | PushButtons *pushButtons; |
silverpanda | 7:19da09fe546b | 16 | |
silverpanda | 3:7188bd978801 | 17 | bool scanUSBSerialRxFlag; |
silverpanda | 1:20033a89af0e | 18 | |
silverpanda | 13:019e24491f32 | 19 | void pushButtonPressed() |
silverpanda | 13:019e24491f32 | 20 | { |
silverpanda | 13:019e24491f32 | 21 | if(pushButtons->getPressed(pb2)) ledColors->flash(lcBlue, 10); |
silverpanda | 13:019e24491f32 | 22 | if(pushButtons->getPressed(pb3)) ledColors->flash(lcGreen, 10); |
silverpanda | 13:019e24491f32 | 23 | if(pushButtons->getJustPressed(pb2)) usbSerialShell->reportPushButtonPress(pb2); |
silverpanda | 13:019e24491f32 | 24 | if(pushButtons->getJustPressed(pb3)) usbSerialShell->reportPushButtonPress(pb3); |
silverpanda | 13:019e24491f32 | 25 | } |
silverpanda | 13:019e24491f32 | 26 | //----------------------------------------------------------------------------- |
silverpanda | 13:019e24491f32 | 27 | |
silverpanda | 7:19da09fe546b | 28 | void at10msTick() |
silverpanda | 1:20033a89af0e | 29 | { |
silverpanda | 1:20033a89af0e | 30 | scanUSBSerialRxFlag = true; |
silverpanda | 7:19da09fe546b | 31 | ledColors->tick10ms(); |
silverpanda | 13:019e24491f32 | 32 | if(pushButtons->tick10ms()) pushButtonPressed(); |
silverpanda | 1:20033a89af0e | 33 | } |
silverpanda | 1:20033a89af0e | 34 | //----------------------------------------------------------------------------- |
silverpanda | 1:20033a89af0e | 35 | |
silverpanda | 1:20033a89af0e | 36 | void initMain() |
silverpanda | 1:20033a89af0e | 37 | { |
silverpanda | 4:dfb672184380 | 38 | // increase the baud rate for the USB serial port |
silverpanda | 5:03b7c237c4c4 | 39 | usbSerialShell = new Shell(115200); |
silverpanda | 1:20033a89af0e | 40 | |
silverpanda | 4:dfb672184380 | 41 | // send greeting with first cursor |
silverpanda | 12:b846b64e3980 | 42 | usbSerialShell->sendStartMessage(); |
silverpanda | 1:20033a89af0e | 43 | |
silverpanda | 4:dfb672184380 | 44 | // start polling for characters |
silverpanda | 6:78a965b2d2df | 45 | scanTicker = new Ticker(); |
silverpanda | 7:19da09fe546b | 46 | scanTicker->attach(&at10msTick, 0.01); |
silverpanda | 1:20033a89af0e | 47 | scanUSBSerialRxFlag = false; |
silverpanda | 7:19da09fe546b | 48 | |
silverpanda | 7:19da09fe546b | 49 | ledColors = new LEDColors(); |
silverpanda | 13:019e24491f32 | 50 | pushButtons = new PushButtons(); |
silverpanda | 0:6898e364f29a | 51 | } |
silverpanda | 0:6898e364f29a | 52 | //----------------------------------------------------------------------------- |
silverpanda | 0:6898e364f29a | 53 | |
silverpanda | 0:6898e364f29a | 54 | int main() { |
silverpanda | 1:20033a89af0e | 55 | initMain(); |
silverpanda | 1:20033a89af0e | 56 | |
silverpanda | 4:dfb672184380 | 57 | while(true) { |
silverpanda | 4:dfb672184380 | 58 | |
silverpanda | 4:dfb672184380 | 59 | // check the flag |
silverpanda | 5:03b7c237c4c4 | 60 | if(scanUSBSerialRxFlag) { |
silverpanda | 5:03b7c237c4c4 | 61 | usbSerialShell->scanUSBSerialRx(); |
silverpanda | 5:03b7c237c4c4 | 62 | scanUSBSerialRxFlag = false; |
silverpanda | 5:03b7c237c4c4 | 63 | } |
silverpanda | 4:dfb672184380 | 64 | |
silverpanda | 4:dfb672184380 | 65 | // give the main loop some time |
silverpanda | 1:20033a89af0e | 66 | wait(0.02); |
silverpanda | 0:6898e364f29a | 67 | } |
silverpanda | 0:6898e364f29a | 68 | } |
silverpanda | 0:6898e364f29a | 69 | //----------------------------------------------------------------------------- |