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:264924f590d2, 2017-12-19 (annotated)
- Committer:
- makia
- Date:
- Tue Dec 19 07:03:16 2017 +0000
- Revision:
- 0:264924f590d2
- Child:
- 1:ef8b9b9fe97d
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
makia | 0:264924f590d2 | 1 | #include "mbed.h" |
makia | 0:264924f590d2 | 2 | |
makia | 0:264924f590d2 | 3 | InterruptIn button(USER_BUTTON); |
makia | 0:264924f590d2 | 4 | Serial pc(USBTX, USBRX); //TX, RX |
makia | 0:264924f590d2 | 5 | DigitalOut led(LED1); |
makia | 0:264924f590d2 | 6 | |
makia | 0:264924f590d2 | 7 | double delay = 0.5; // 500 ms |
makia | 0:264924f590d2 | 8 | int tamp = 0; //เอามาดูค่าที่ใช้ทดลองกดปุ่ม |
makia | 0:264924f590d2 | 9 | |
makia | 0:264924f590d2 | 10 | void pressed() |
makia | 0:264924f590d2 | 11 | { |
makia | 0:264924f590d2 | 12 | delay = 0.1; // 100 ms |
makia | 0:264924f590d2 | 13 | tamp = tamp + 1 ; |
makia | 0:264924f590d2 | 14 | } |
makia | 0:264924f590d2 | 15 | |
makia | 0:264924f590d2 | 16 | void released() |
makia | 0:264924f590d2 | 17 | { |
makia | 0:264924f590d2 | 18 | delay = 0.5; // 500 ms |
makia | 0:264924f590d2 | 19 | pc.printf("tamp stable = %d " , tamp); |
makia | 0:264924f590d2 | 20 | } |
makia | 0:264924f590d2 | 21 | |
makia | 0:264924f590d2 | 22 | int main() |
makia | 0:264924f590d2 | 23 | { |
makia | 0:264924f590d2 | 24 | // Assign functions to button |
makia | 0:264924f590d2 | 25 | button.fall(&pressed); |
makia | 0:264924f590d2 | 26 | button.rise(&released); |
makia | 0:264924f590d2 | 27 | |
makia | 0:264924f590d2 | 28 | while (1) { |
makia | 0:264924f590d2 | 29 | led = !led; |
makia | 0:264924f590d2 | 30 | pc.printf("%d" , tamp); |
makia | 0:264924f590d2 | 31 | wait(delay); |
makia | 0:264924f590d2 | 32 | } |
makia | 0:264924f590d2 | 33 | } |