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@1:55c209e14e75, 2018-03-07 (annotated)
- Committer:
- nehalmathur
- Date:
- Wed Mar 07 10:31:13 2018 +0000
- Revision:
- 1:55c209e14e75
- Parent:
- 0:3f81076404ad
- Child:
- 2:b261cb3cafcf
Changed Button
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nehalmathur | 0:3f81076404ad | 1 | #include "mbed.h" |
| nehalmathur | 0:3f81076404ad | 2 | |
| nehalmathur | 0:3f81076404ad | 3 | DigitalOut M3_DIR (D4); |
| nehalmathur | 0:3f81076404ad | 4 | DigitalIn button1(SW3); |
| nehalmathur | 0:3f81076404ad | 5 | DigitalIn button2(SW2); |
| nehalmathur | 1:55c209e14e75 | 6 | DigitalIn ButtonClockwise(D2); |
| nehalmathur | 1:55c209e14e75 | 7 | DigitalIn ButtonAnticlockwise(D3); |
| nehalmathur | 0:3f81076404ad | 8 | PwmOut M3 (D5); |
| nehalmathur | 0:3f81076404ad | 9 | DigitalOut led_red_base(LED_RED); |
| nehalmathur | 0:3f81076404ad | 10 | |
| nehalmathur | 0:3f81076404ad | 11 | float frequency_pwm = 10000.0f; |
| nehalmathur | 0:3f81076404ad | 12 | |
| nehalmathur | 0:3f81076404ad | 13 | |
| nehalmathur | 0:3f81076404ad | 14 | int main() |
| nehalmathur | 0:3f81076404ad | 15 | { |
| nehalmathur | 0:3f81076404ad | 16 | M3.period(1.0f/frequency_pwm); |
| nehalmathur | 0:3f81076404ad | 17 | |
| nehalmathur | 0:3f81076404ad | 18 | while(true) { |
| nehalmathur | 0:3f81076404ad | 19 | |
| nehalmathur | 1:55c209e14e75 | 20 | if(ButtonClockwise) |
| nehalmathur | 0:3f81076404ad | 21 | { |
| nehalmathur | 0:3f81076404ad | 22 | M3.write(0.0f); |
| nehalmathur | 0:3f81076404ad | 23 | } |
| nehalmathur | 0:3f81076404ad | 24 | else |
| nehalmathur | 0:3f81076404ad | 25 | { |
| nehalmathur | 0:3f81076404ad | 26 | M3.write(0.03f); |
| nehalmathur | 0:3f81076404ad | 27 | M3_DIR.write(1); |
| nehalmathur | 0:3f81076404ad | 28 | } |
| nehalmathur | 0:3f81076404ad | 29 | |
| nehalmathur | 1:55c209e14e75 | 30 | if(ButtonAnticlockwise) |
| nehalmathur | 0:3f81076404ad | 31 | { |
| nehalmathur | 0:3f81076404ad | 32 | M3.write(0.0f); |
| nehalmathur | 0:3f81076404ad | 33 | } |
| nehalmathur | 0:3f81076404ad | 34 | else |
| nehalmathur | 0:3f81076404ad | 35 | { |
| nehalmathur | 0:3f81076404ad | 36 | M3.write(0.03f); |
| nehalmathur | 0:3f81076404ad | 37 | M3_DIR.write(0); |
| nehalmathur | 0:3f81076404ad | 38 | } |
| nehalmathur | 0:3f81076404ad | 39 | } |
| nehalmathur | 0:3f81076404ad | 40 | |
| nehalmathur | 0:3f81076404ad | 41 | return 0; |
| nehalmathur | 0:3f81076404ad | 42 | |
| nehalmathur | 0:3f81076404ad | 43 | } |
| nehalmathur | 0:3f81076404ad | 44 |