Keiju Nakano
/
mbed_blinky_analog
Platform : mbed LPC1114FN28 , pwmが更新する度に長時間停波するので今回の用途にはつかえない
main.cpp@0:5ac8ea653724, 2015-05-05 (annotated)
- Committer:
- maxonK
- Date:
- Tue May 05 08:25:50 2015 +0000
- Revision:
- 0:5ac8ea653724
0.5s???pwm?????????????????mbed?????pwm?????????????????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maxonK | 0:5ac8ea653724 | 1 | #include "mbed.h" |
maxonK | 0:5ac8ea653724 | 2 | |
maxonK | 0:5ac8ea653724 | 3 | AnalogIn position(dp4); |
maxonK | 0:5ac8ea653724 | 4 | PwmOut servo(dp1); |
maxonK | 0:5ac8ea653724 | 5 | |
maxonK | 0:5ac8ea653724 | 6 | Serial device (USBTX,USBRX); |
maxonK | 0:5ac8ea653724 | 7 | |
maxonK | 0:5ac8ea653724 | 8 | int main() |
maxonK | 0:5ac8ea653724 | 9 | { |
maxonK | 0:5ac8ea653724 | 10 | // servo requires a 20ms period |
maxonK | 0:5ac8ea653724 | 11 | servo.period(0.015f); |
maxonK | 0:5ac8ea653724 | 12 | while (1) { |
maxonK | 0:5ac8ea653724 | 13 | wait(0.5); |
maxonK | 0:5ac8ea653724 | 14 | // servo position determined by a pulse width between 1-2ms |
maxonK | 0:5ac8ea653724 | 15 | servo.pulsewidth(0.001f + 0.001f * position); |
maxonK | 0:5ac8ea653724 | 16 | |
maxonK | 0:5ac8ea653724 | 17 | } |
maxonK | 0:5ac8ea653724 | 18 | } |