daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int lastState[2]={0,0};
  2. int words[4]={0x08,0x02,0x01,0x04};
  3. //int Owords[1][4]={0x04,0x02,0x01};
  4. //MoveMotor(x or y, number of 90d steps to make, + or - right up or left down)
  5. void moveMotor(char motor,int steps,char direction){
  6.      int i;
  7.      int axis=0;
  8.      int dir=1;
  9. //     if(motor=='y')
  10.      if(direction=='-')
  11.           dir=-1;
  12.      for(i=0;i<steps;i++){
  13.        if(motor=='x'){
  14.            int nextState= (dir+lastState[0]+4)%4;
  15.            PORTB=words[nextState];
  16.            lastState[0]=nextState;
  17.        }
  18.        else{
  19.            int nextState= (dir+lastState[1]+4)%4;
  20.            PORTA=words[nextState];
  21.            lastState[1]=nextState;
  22.        }
  23.        delay_ms(100);
  24.      }
  25. }
  26.  
  27. void main() {
  28.   int i;
  29.   TRISB=0X00;
  30.   TRISA=0X00;
  31.   PORTB=0X00;
  32.   PORTA=0x00;
  33.  
  34.     while(1 ){
  35.       moveMotor('x',8,'+');  
  36.       delay_ms(500);
  37.       moveMotor('y',8,'+');  
  38.       delay_ms(500);
  39.       moveMotor('x',8,'-');
  40.       delay_ms(500);
  41.       moveMotor('y',8,'-');
  42.       delay_ms(500);
  43.     }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top