Dependencies: mbed Servo Pulse1
Diff: main.cpp
- Revision:
- 0:b806d9855f21
- Child:
- 1:1e4ebe0da2ea
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 20 07:32:15 2019 +0000 @@ -0,0 +1,70 @@ +#include "mbed.h" +#include "Servo.h" +#include "Map.h" + + + +PwmOut led_left(LED1); //확인용 LED1 +PwmOut led_right(LED2); //확인용 LED2 + +Servo bldc_left(D12); // 왼쪽 BLDC +Servo bldc_right(PC_7); // 오른쪽 BLDC + +AnalogIn joystick_X(A0); +AnalogIn joystick_Y(A1); + +int main() { + bldc_left.write(0); // BLDC 초기 설정 + bldc_right.write(0); + + led_left = 1; + led_right=1; + + wait(0.5); + + bldc_left.write(1); + bldc_right.write(1); + + led_left =0; + led_right=0; + wait(2); + + bldc_left.write(0); + bldc_right.write(0); + wait(2); + + float raw1,raw2; + float mod1,mod2; + printf("\nBLDC Setup & end\n"); + + while (1) { + + raw1 = joystick_X.read(); + raw2 = joystick_Y.read(); + raw1 = raw1 * 1000; + raw2 = raw2 * 1000; + + printf("measure1 = %.0f mV\t", raw1); + mod1 = map(raw1, 520, 1000, 0, 100); + + printf("measure2 = %.0f mV\t", raw2); + mod2 = map(raw2, 520, 1000, 0, 100); + + + + printf("measure1 = %.0f mV\t", mod1); + printf("measure2 = %.0f mV\t", mod2); + + mod1 = mod1/100; + mod2 = mod2/100; + printf("measure1 = %f mV\n", mod1); + printf("measure2 = %f mV\t", mod2); + + bldc_left.write(mod1); + bldc_right.write(mod2); + + + led_left.write(mod1); + led_right.write(mod2); + } +} \ No newline at end of file