servo(pot ile) ve step motor kontrolu
Dependencies: mbed servo_motor mbed-rtos
Diff: main.cpp
- Revision:
- 1:f43b9b2d82be
- Parent:
- 0:75bd93370a68
--- a/main.cpp Wed Dec 18 11:13:06 2019 +0000 +++ b/main.cpp Wed Dec 18 12:34:42 2019 +0000 @@ -1,17 +1,58 @@ #include "mbed.h" +#include "rtos.h" +#include "servo.h" + +float oku; +Thread servo_is_parcasi; +servo servo_motor(PC_8); +AnalogIn pot(PA_0); PortOut step_motor(PortB,0xC006); -int main() +int adim=0; +int aci=0; +void servo_motor_metodu() { while(1) { -step_motor=0x0002;//PB_1 hex -wait_ms(3); -step_motor=0x0004;//PB_2 hex -wait_ms(3); -step_motor=0x4000;//PB_14 hex -wait_ms(3); -step_motor=0x8000;//PB_15 hex -wait_ms(3); + oku=pot.read();//0.0 ile 1.0 arasında değer okuması yapar + aci=int(oku*175); + printf("%d \n",aci); + + servo_motor.derece(aci); + } + } + +int main() +{ + servo_is_parcasi.start(servo_motor_metodu); + step_motor=0x0000; + while(1) { + adim++; + if(adim<500) {//saat yönünde döner + step_motor=0x0002;//PB_1 hex + wait_ms(3); + step_motor=0x0004;//PB_2 hex + wait_ms(3); + step_motor=0x4000;//PB_14 hex + wait_ms(3); + step_motor=0x8000;//PB_15 hex + wait_ms(3); + } + else if(adim==500) + { + step_motor=0x0000; + } + else if(adim>500 && adim<750) {//saat yönünün tersine döner + step_motor=0x8000;//PB_15 hex + wait_ms(3); + step_motor=0x4000;//PB_14 hex + wait_ms(3); + step_motor=0x0004;//PB_2 hex + wait_ms(3); + step_motor=0x0002;//PB_1 hex + wait_ms(3); + } else { + adim=0; + } } return 0; - } \ No newline at end of file +} \ No newline at end of file