Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "main.h"
- #include "motors.h"
- #include "hc595.h"
- //typedef uint8_t bool;
- #define true 1
- #define false 0
- static volatile int8_t stop=1;
- static uint32_t delay=10000/2;
- static uint8_t motor_number=1;
- bool step=false;
- void motor_select(MotorType type)
- {
- motor_number=type;
- }
- void motor_mode12(void)
- {
- hc_outbits((hc_getbits()&(~(MOTOR_M0|MOTOR_M1|MOTOR_M2)))|MOTOR_M0);
- }
- void motor_mode14(void)
- {
- hc_outbits((hc_getbits()&(~(MOTOR_M0|MOTOR_M1|MOTOR_M2)))|MOTOR_M1);
- }
- void motor_mode18(void)
- {
- hc_outbits((hc_getbits()&(~(MOTOR_M0|MOTOR_M1|MOTOR_M2)))|MOTOR_M0|MOTOR_M1);
- }
- void motor_mode116(void)
- {
- hc_outbits((hc_getbits()&(~(MOTOR_M0|MOTOR_M1|MOTOR_M2)))|MOTOR_M2);
- }
- void motor_mode132(void)
- {
- hc_outbits((hc_getbits()&(~(MOTOR_M0|MOTOR_M1|MOTOR_M2)))|MOTOR_M0|MOTOR_M2);
- }
- void motor_modegfull(void)
- {
- hc_outbits((hc_getbits()&(~(MOTOR_M0|MOTOR_M1|MOTOR_M2))));
- }
- void motor_left(void)
- {
- stop=1;
- if(motor_number==1)
- {
- hc_setbits(MOTOR1_DIR);
- }else if(motor_number==2)
- {
- hc_setbits(MOTOR2_DIR);
- }if(motor_number==3)
- {
- hc_setbits(MOTOR3_DIR);
- }
- }
- void motor_right(void)
- {
- stop=1;
- if(motor_number==1)
- {
- hc_clearbits(MOTOR1_DIR);
- }else
- if(motor_number==2)
- {
- hc_clearbits(MOTOR2_DIR);
- }else if(motor_number==3)
- {
- hc_clearbits(MOTOR3_DIR);
- }
- }
- void motor_step(void)
- {
- if(motor_number==1)
- {
- hc_tooglebits(MOTOR1_STEP);
- }else
- if(motor_number==2)
- {
- hc_tooglebits(MOTOR2_STEP);
- }
- else
- if(motor_number==3)
- {
- hc_tooglebits(MOTOR3_STEP);
- }
- }
- void motor_control(MotorType type, MotorDirection direction, MotorMode mode, uint64_t steps, uint32_t speed)
- {
- uint32_t timestamp=0;
- uint32_t step_time=0;
- switch (type)
- {
- case MOTOR_ROTATION:
- motor_select(MOTOR_ROTATION);
- break;
- case MOTOR_CAMERA:
- motor_select(MOTOR_CAMERA);
- break;
- case MOTOR_PLATFORM:
- motor_select(MOTOR_PLATFORM);
- break;
- default:
- break;
- }
- switch (direction)
- {
- case LEFT:
- motor_left();
- break;
- case RIGHT:
- motor_right();
- break;
- default:
- break;
- }
- switch (mode)
- {
- case MODE_FULL:
- motor_modegfull();
- break;
- case MODE_2:
- motor_mode12();
- break;
- case MODE_4:
- motor_mode14();
- break;
- case MODE_8:
- motor_mode18();
- break;
- case MODE_16:
- motor_mode116();
- break;
- case MODE_32:
- motor_mode132();
- break;
- default:
- break;
- }
- workLED(1,1);
- for(int i=0; i<steps; i++)
- {
- timestamp++;
- if((timestamp-step_time)>speed)
- {
- motor_step();
- step_time=timestamp;
- if (BTN_START_STOP && BTN_OPTIONS_BACK)
- {
- workLED(0,1);
- return 0;
- }
- }
- }
- workLED(0,1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement