servo(pot ile) ve step motor kontrolu
Dependencies: mbed servo_motor mbed-rtos
main.cpp
- Committer:
- marvas
- Date:
- 2019-12-18
- Revision:
- 1:f43b9b2d82be
- Parent:
- 0:75bd93370a68
File content as of revision 1:f43b9b2d82be:
#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 adim=0; int aci=0; void servo_motor_metodu() { while(1) { 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; }