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.
main.cpp@0:377a50b631cf, 2018-08-30 (annotated)
- Committer:
- JMF
- Date:
- Thu Aug 30 00:35:30 2018 +0000
- Revision:
- 0:377a50b631cf
button class example
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JMF | 0:377a50b631cf | 1 | #include "mbed.h" |
| JMF | 0:377a50b631cf | 2 | #include "Button.hpp" |
| JMF | 0:377a50b631cf | 3 | |
| JMF | 0:377a50b631cf | 4 | void br_callback(int dur) |
| JMF | 0:377a50b631cf | 5 | { |
| JMF | 0:377a50b631cf | 6 | printf("\r\n!! button RELEASE called, press time: %d msec\r\n", dur); |
| JMF | 0:377a50b631cf | 7 | } |
| JMF | 0:377a50b631cf | 8 | |
| JMF | 0:377a50b631cf | 9 | void bp_callback(void) |
| JMF | 0:377a50b631cf | 10 | { |
| JMF | 0:377a50b631cf | 11 | printf("\r\n!! button PRESS called\r\n"); |
| JMF | 0:377a50b631cf | 12 | } |
| JMF | 0:377a50b631cf | 13 | |
| JMF | 0:377a50b631cf | 14 | int main() { |
| JMF | 0:377a50b631cf | 15 | int k, dur; |
| JMF | 0:377a50b631cf | 16 | Button* button_ptr; |
| JMF | 0:377a50b631cf | 17 | |
| JMF | 0:377a50b631cf | 18 | printf("Testing button class\r\n"); |
| JMF | 0:377a50b631cf | 19 | printf("Test Standard polling type implementation\r\n"); |
| JMF | 0:377a50b631cf | 20 | button_ptr = new Button(USER_BUTTON, Button::ActiveHigh); |
| JMF | 0:377a50b631cf | 21 | while( (k=button_ptr->chkButton_press(&dur)) == 0 ) |
| JMF | 0:377a50b631cf | 22 | /* wait */; |
| JMF | 0:377a50b631cf | 23 | printf(">Button pressed %d times, last was %d msec\r\n",k,dur); |
| JMF | 0:377a50b631cf | 24 | delete button_ptr; |
| JMF | 0:377a50b631cf | 25 | |
| JMF | 0:377a50b631cf | 26 | printf("\nTest with Release callback\r\n"); |
| JMF | 0:377a50b631cf | 27 | button_ptr = new Button(USER_BUTTON, Button::ActiveHigh, br_callback); |
| JMF | 0:377a50b631cf | 28 | while( (k=button_ptr->chkButton_press(&dur)) == 0 ) |
| JMF | 0:377a50b631cf | 29 | /* wait */; |
| JMF | 0:377a50b631cf | 30 | printf(">Button pressed %d times, last was %d msec\r\n",k,dur); |
| JMF | 0:377a50b631cf | 31 | delete button_ptr; |
| JMF | 0:377a50b631cf | 32 | |
| JMF | 0:377a50b631cf | 33 | printf("\nTest with Press & Release callback\r\n"); |
| JMF | 0:377a50b631cf | 34 | button_ptr = new Button(USER_BUTTON, Button::ActiveHigh, br_callback); |
| JMF | 0:377a50b631cf | 35 | button_ptr->setButton_press_cb(bp_callback); |
| JMF | 0:377a50b631cf | 36 | while( (k=button_ptr->chkButton_press(&dur)) == 0 ) |
| JMF | 0:377a50b631cf | 37 | /* wait */; |
| JMF | 0:377a50b631cf | 38 | printf(">Button pressed %d times, last was %d msec\r\n",k,dur); |
| JMF | 0:377a50b631cf | 39 | while (1) { |
| JMF | 0:377a50b631cf | 40 | wait(.5); |
| JMF | 0:377a50b631cf | 41 | } |
| JMF | 0:377a50b631cf | 42 | |
| JMF | 0:377a50b631cf | 43 | } |