Unwanted delay in output

This is a discussion on Unwanted delay in output within the C Programming forums, part of the General Programming Boards category; I'm building a project with Arduino duemilanove and sparkfun usb host shield. I'm basicly driving two stepper motors with a ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9

    Unwanted delay in output

    I'm building a project with Arduino duemilanove and sparkfun usb host shield. I'm basicly driving two stepper motors with a wireless keyboard. I've got the code working except for one thing, it seems like there's a delay between output repeats when a button is pressed so there are unwanted pauses in the motor spin. I was wondering if anyone here can help me smooth out the spin of the motors. I'm not an advanced programmer so there might be unnecessary effort in the code.

    The code below:

    Code:
    /* Lokaverkefni */
    
    /* Kˇ­abankar innfelldir */
    #include <Spi.h> //Kˇ­abanki fyrir Serial Peripheral Interface
    #include <Max3421e.h> //Kˇ­abanki fyrir kubbinn ß USB Host Shield
    #include <Usb.h> //Kˇ­abanki fyrir Universal Serial Bus
    
    /* ┌tgangspinnar skrefmˇtora skilgreindir */
    int motorPin1 = 3;
    int motorPin2 = 4;
    int motorPin3 = 5;
    int motorPin4 = 6;
    int motorPin5 = 14;
    int motorPin6 = 15;
    int motorPin7 = 16;
    int motorPin8 = 17;
    
    int Delay = 20; //Seinkun Ý millisek˙ndum
    
    /*Takkar ß lyklabor­i skilgreindir*/
    #define buttonUp (0x52)
    #define buttonDown (0x51)
    #define buttonLeft (0x50)
    #define buttonRight (0x4f)
     
    /* keyboard data taken from configuration descriptor */
    #define KBD_ADDR  1
    #define KBD_EP    1
    #define EP_MAXPKTSIZE  8
    #define EP_POLL        0x0a
    /**/
    EP_RECORD ep_record[ 2 ];  //endpoint record structure for the keyboard
     
    void setup();
    void loop();
     
    MAX3421E Max;
    USB Usb;
     
    void setup()
    {
        Serial.begin( 9600 );
        Serial.println("Start");
        Max.powerOn();
        delay( 200 );
        
        /*Pinnar skilgreindir sem ˙tgangar*/
        pinMode( motorPin1, OUTPUT);
        pinMode( motorPin2, OUTPUT);
        pinMode( motorPin3, OUTPUT);
        pinMode( motorPin4, OUTPUT);
        pinMode( motorPin5, OUTPUT);
        pinMode( motorPin6, OUTPUT);
        pinMode( motorPin7, OUTPUT);
        pinMode( motorPin8, OUTPUT);
    }
     
    void loop()
    {
        Max.Task();
        Usb.Task();
        if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {  //wait for addressing state
            kbd_init();
            Usb.setUsbTaskState( USB_STATE_RUNNING );
        }
        if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) {  //poll the keyboard
            kbd_poll();
        }
    }
    /* Initialize keyboard */
    void kbd_init( void )
    {
      byte rcode = 0;  //return code
    /**/
        /* Initialize data structures */
        ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 ));  //copy endpoint 0 parameters
        ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE;
        ep_record[ 1 ].Interval  = EP_POLL;
        ep_record[ 1 ].sndToggle = bmSNDTOG0;
        ep_record[ 1 ].rcvToggle = bmRCVTOG0;
        Usb.setDevTableEntry( 1, ep_record );              //plug kbd.endpoint parameters to devtable
        /* Configure device */
        rcode = Usb.setConf( KBD_ADDR, 0, 1 );
        if( rcode ) {
            Serial.print("Error attempting to configure keyboard. Return code :");
            Serial.println( rcode, HEX );
            while(1);  //stop
        }
        /* Set boot protocol */
        rcode = Usb.setProto( KBD_ADDR, 0, 0, 0 );
        if( rcode ) {
            Serial.print("Error attempting to configure boot protocol. Return code :");
            Serial.println( rcode, HEX );
            while( 1 );  //stop
        }
        
        delay(2000);
        Serial.println("Lyklabord virkt");
    }
    /* Poll lyklabor­ og virkjar ˙tgangspinna me­ eftirfarandi skilyr­um */
    void kbd_poll( void )
    {
      char i, j;
      char buf[ 8 ] = { 0 };      //keyboard buffer
      static char old_buf[ 8 ] = { 0 };  //last poll
      byte rcode = 0;     //return code
        /* poll keyboard */
        rcode = Usb.inTransfer( KBD_ADDR, KBD_EP, 8, buf );
        if( rcode != 0 ) {
            return;
        }
        for( i = 0; i < 8; i++ ) {
            if( buf[ i ] != old_buf[ i ] ) {
                for( j = 0; j < 8; j++ ) {
                  do {
                switch( buf[ j ] ) {
                case buttonUp:
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, LOW);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, LOW);
              delay(Delay);       
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
             break;
                }
                  }
                  while( buttonUp == HIGH );              
                  do {
                switch( buf[ j ] ) {              
                case buttonDown:
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, LOW);
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, LOW);          
             break;
                }
                  }
                  while( buttonDown == HIGH );              
                  do {
                switch( buf[ j ] ) {              
                case buttonLeft:
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, LOW);
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, LOW);
             break;
                }
                  }
                  while( buttonLeft == HIGH );              
                  do {
                switch( buf[ j ] ) {              
                case buttonRight:
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, LOW);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, LOW);
              digitalWrite(motorPin6, HIGH);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, HIGH);
              digitalWrite(motorPin8, LOW);
              delay(Delay);
              digitalWrite(motorPin1, LOW);
              digitalWrite(motorPin5, LOW);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, HIGH);
              digitalWrite(motorPin7, HIGH);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, HIGH);
              delay(Delay);
              digitalWrite(motorPin1, HIGH);
              digitalWrite(motorPin5, HIGH);
              digitalWrite(motorPin2, HIGH);
              digitalWrite(motorPin6, LOW);
              digitalWrite(motorPin3, LOW);
              digitalWrite(motorPin7, LOW);
              digitalWrite(motorPin4, LOW);
              digitalWrite(motorPin8, HIGH);          
             break;
                }
                  }
         while( buttonRight == HIGH );
         
                }                       
                    old_buf[ j ] = buf[ j ];
                }
            }    
        }
    Last edited by NightHawk; 12-05-2010 at 08:14 AM.

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    This type of code is pretty proprietary and with having all of these comments in a language other than English, I doubt you will get more than a passing glance from anyone here.

    Try to narrow the problem down to a few lines of code. Overall the code looks fairly simple though.

    First impression right off the bat:
    Your polling function is pretty messy. Lots of embedded loops that you could try to clean up.

    Another think I noticed is you put another delay after the end of your digitalWrite's for case buttonUp, and you didn't for your other cases. Are you by any change experiencing the delay while testing with buttonUp?

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,444
    You could definitely get rid of all the do-while loops in kbd_poll. They are completely useless since it's almost certain that none of buttonUp, buttonDown, buttonLeft and buttonRight will ever equal HIGH. Those 4 button identifiers refer to constants you defined as 0x4f, 0x50, 0x51 and 0x52. I would guess HIGH is defined as 1 or something (it's missing from your file). If they did equal HIGH, you'd be stuck in an infinite loop. If they didn't, you would only execute the loop body once, so just get rid of it.

    This is just a stab in the dark because I'm not totally clear on what your code is doing, but you could also probably get rid of the for j loop in kbd_poll. You're already cycling though buf with your for i loop, and the for j loop is just causing you to process buf 8 times. Once that's gone, you should merge your switch statements into one, so it looks like this:
    Code:
    for (i = 0; i < 8; i++) {
        if (buf[i] != old_buf[i]) {
            switch (buf[i]) {
                case buttonUp:
                    ...
                    break;
                case buttonDown:
                    ...
                    break;
            }
        }
        old_buf[i] = buf[i];
    }
    I'm curious to know why you're using old_buf as though the keyboard buffer may still contain the previous set of data. Doesn't Usb.inTransfer remove the data you just read from the keyboard buffer?

  4. #4
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    Quote Originally Posted by carrotcake1029 View Post
    This type of code is pretty proprietary and with having all of these comments in a language other than English, I doubt you will get more than a passing glance from anyone here.

    Try to narrow the problem down to a few lines of code. Overall the code looks fairly simple though.

    First impression right off the bat:
    Your polling function is pretty messy. Lots of embedded loops that you could try to clean up.

    Another think I noticed is you put another delay after the end of your digitalWrite's for case buttonUp, and you didn't for your other cases. Are you by any change experiencing the delay while testing with buttonUp?
    This is a school project so I'm writing description in my own language, sorry about that. The keyboard code itself is modified from Circuits@home. I've only gone in circles with the digitalWrites, but this version got me the closest to what I'm aiming for. The delay this is just because i've been jumping the code around and observe the result, there's really no missing delay, one is on the bottom and the others are at the top.

    Quote Originally Posted by anduril462 View Post
    You could definitely get rid of all the do-while loops in kbd_poll. They are completely useless since it's almost certain that none of buttonUp, buttonDown, buttonLeft and buttonRight will ever equal HIGH. Those 4 button identifiers refer to constants you defined as 0x4f, 0x50, 0x51 and 0x52. I would guess HIGH is defined as 1 or something (it's missing from your file). If they did equal HIGH, you'd be stuck in an infinite loop. If they didn't, you would only execute the loop body once, so just get rid of it.

    This is just a stab in the dark because I'm not totally clear on what your code is doing, but you could also probably get rid of the for j loop in kbd_poll. You're already cycling though buf with your for i loop, and the for j loop is just causing you to process buf 8 times. Once that's gone, you should merge your switch statements into one, so it looks like this:
    Code:
    for (i = 0; i < 8; i++) {
        if (buf[i] != old_buf[i]) {
            switch (buf[i]) {
                case buttonUp:
                    ...
                    break;
                case buttonDown:
                    ...
                    break;
            }
        }
        old_buf[i] = buf[i];
    }
    I'm curious to know why you're using old_buf as though the keyboard buffer may still contain the previous set of data. Doesn't Usb.inTransfer remove the data you just read from the keyboard buffer?
    For some reason, if I don't use the do while loops the stepper motor only makes one step when I press a button instead of continuously spinning while the button is pressed. No doubt there must be a simpler way to do this, but it's a bit over my head at the moment. There may be leftovers in the keyboard code because it was originally used to write hex trough serial com.

    btw the digitalWrites are stepping motions for the stepper motors, the order indicates direction and the delay indicates speed. motorPin1-4 is motor 1 and motorPin5-8 is motor 2. Unipolar motor.
    Last edited by NightHawk; 12-05-2010 at 11:01 AM.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    I take it the motor is a stepper motor...

    If you can check the documentation you may find it has a distinct sequence to it's pins when moving, usually something like a.c.b.d for a 4 pole motor... more complex of course for 6 or 8 poles. To move left you run it acbd to go right you use dbca sequencing... Usually this is done in a circular fasion, for example if you are at step c you would do dbac ... and so on.

    If you could discover this sequence it would simplify you code enormously... As now you would only need a short array with the sequence imbedded and a pointer to access it circularly...

    Code:
    int move[4] = {1,4,2,8}  // more complex for more poles
    int hotpole = 0;
    
    
    void goleft(void)
      { hotpole = (hotpole + 1) % 4; 
         setbits(move[hotpole]);} 
    
    void goright(void)
      { hotpole -=  1; 
         if (hotpole < 0)
           hotpole = 3;
         setbits(move[hotpole]; }
    That's more or less how we used to do it with disk drive head steppers.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    Quote Originally Posted by CommonTater View Post
    I take it the motor is a stepper motor...

    If you can check the documentation you may find it has a distinct sequence to it's pins when moving, usually something like a.c.b.d for a 4 pole motor... more complex of course for 6 or 8 poles. To move left you run it acbd to go right you use dbca sequencing... Usually this is done in a circular fasion, for example if you are at step c you would do dbac ... and so on.

    If you could discover this sequence it would simplify you code enormously... As now you would only need a short array with the sequence imbedded and a pointer to access it circularly...

    Code:
    int move[4] = {1,4,2,8}  // more complex for more poles
    int hotpole = 0;
    
    
    void goleft(void)
      { hotpole = (hotpole + 1) % 4; 
         setbits(move[hotpole]);} 
    
    void goright(void)
      { hotpole -=  1; 
         if (hotpole < 0)
           hotpole = 3;
         setbits(move[hotpole]; }
    That's more or less how we used to do it with disk drive head steppers.
    The sequence in the code is 1100 0110 0011 1001, it works on my steppers with the wires plugged in a straight row, if that's what you mean. Thanks for the input guys, I'll study this and see if I can rewrite with the new information.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by NightHawk View Post
    The sequence in the code is 1100 0110 0011 1001, it works on my steppers with the wires plugged in a straight row, if that's what you mean. Thanks for the input guys, I'll study this and see if I can rewrite with the new information.
    Yep that's what I was talking about....

    Now all you have to do is write a subroutine to impose those bits on the right pins...

    You may also have to put in a little delay before each subroutine returns to let the motor settle... Unless you've got the world's second slowest computer you'll overrun that motor pretty easily... something like the windows Sleep(milliseconds) command might help you there.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    Getting rid of the
    Code:
            if( buf[ i ] != old_buf[ i ] ) {
                for( j = 0; j < 8; j++ ) {
    
                ...
                
                 }                       
                    old_buf[ j ] = buf[ j ];
             }
    Solved the one time run problem. But the motor hiccup is still there, so next up the array setup.

  9. #9
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    I'm a bit fuzzy on how to translate the binary sequence to pin order inside the array. Since I have two stepper motors, should I make two pin arrays or can I have both motors in one array?

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by NightHawk View Post
    I'm a bit fuzzy on how to translate the binary sequence to pin order inside the array. Since I have two stepper motors, should I make two pin arrays or can I have both motors in one array?
    Translation will depend on what you have available... If you have to write to individual bits
    you will have to do something like a 2d array with values to set the bit to 1 or 0. If you can write to a port, you just arrange the 4 values the port needs in a flat array.

    Code:
    int steps[4][4]={ {1,1,0,0}
                                {0,1,1,0}
                                {0,0,1,1}
                                {1,0,0,1}};
    
    for (i= 0; i < 4; i++)
      PinSet(i, array[step][i]); // where i represents the pin number
    Yes you can have both motors on one array just keep two separate step pointers, one for each's current position in the sequence.

  11. #11
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    That makes sense. I'm writing to individual bits. My thinking power has run out for today, I'm gonna pick it up tomorrow.
    Thanks alot

  12. #12
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    These arrays are surprisingly confusing once you get into it :P

    How does this look?

    Code:
    int motor1[4] = { 3, 4, 5, 6 };
    int count1 = 0;
    int motor2[4] = { 14, 15, 16, 17 };
    int count2 = 0;
    
    int steps[4][4] = { {1, 1, 0, 0},
                        {0, 1, 1, 0}, 
                        {0, 0, 1, 1}, 
                        {1, 0, 0, 1} };
    int Step1 = 0;
    int Step2 = 0;
    int Delay = 20; 
    
    ...
    
    void setup()
    
        for( count1 = 0; count1 < 4; count1++ ) {
          pinMode( motor1[ count1 ], OUTPUT );
        }
        for( count2 = 0; count2 < 4; count2++ ) {
          pinMode( motor2[ count2 ], OUTPUT );
        }
    This is what I got sofar, did I understand this correctly?

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by NightHawk View Post
    These arrays are surprisingly confusing once you get into it :P

    How does this look?

    Code:
    int motor1[4] = { 3, 4, 5, 6 };
    int count1 = 0;
    int motor2[4] = { 14, 15, 16, 17 };
    int count2 = 0;
    
    int steps[4][4] = { {1, 1, 0, 0},
                        {0, 1, 1, 0}, 
                        {0, 0, 1, 1}, 
                        {1, 0, 0, 1} };
    int Step1 = 0;
    int Step2 = 0;
    int Delay = 20; 
    
    ...
    
    void setup()
    
        for( count1 = 0; count1 < 4; count1++ ) {
          pinMode( motor1[ count1 ], OUTPUT );
        }
        for( count2 = 0; count2 < 4; count2++ ) {
          pinMode( motor2[ count2 ], OUTPUT );
        }
    This is what I got sofar, did I understand this correctly?
    If so... nope you're not getting the concept.

    The goal is to take the values from the array and set them onto the correct motor pin... What you have ignores the steps array totally...

    So I should take it from your original coce that motor1 is connected to pins 1, 2 3 & 4 and motor 2 is connected to pins 5, 6, 7 & 8 of some user controlled interface?

    If I'm reading this correctly pinmode sets one bit on or off on your motor driver...
    Code:
    pinmode(Pin#,On/off);
    Something like this....

    Code:
    int steps[4][4] = { {1, 1, 0, 0},
                        {0, 1, 1, 0}, 
                        {0, 0, 1, 1}, 
                        {1, 0, 0, 1} };
    int Step1 = 0;
    int Step2 = 0;
    
    void SingleStep(int step)
      { for (int i = 0; i < 4; i++)          // set motor pins
            SetPin(i + 1, steps[step][i]);      
         Sleep(50);  }                          // wait for motor to settle
       
    
    void RunClockwise(void )
      { while (ButtonDown)             // external value 0 = stop
            for (int 1 = 0; i < 4; i++)
               SingleStep(i);  }
    
    
    void RunCounterClock(void )
      { while (ButtonDown)             // external value 0 =stop
            for (int 1 = 0; i < 4; i--)
               SingleStep(i);  }
    
    
    // in your control code
    if (Button2Down)
      RunClockwise(step1);
    Does that give you the idea? Of course it's not going to be exactly that, I'm not accounting for multiple motors or the starting position in the array.... I will spank you if you try to cut and paste it... but it should point you in the right direction.
    Last edited by CommonTater; 12-06-2010 at 04:26 PM.

  14. #14
    Registered User
    Join Date
    Dec 2010
    Location
    Iceland
    Posts
    9
    pinMode defines a pin as input or output, digitalWrite sets the pin high or low. Sorry if I left that out. I just wanted to get the setup right before I tried the control. But this get's me alot closer though, thanks

  15. #15
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by NightHawk View Post
    pinMode defines a pin as input or output, digitalWrite sets the pin high or low. Sorry if I left that out. I just wanted to get the setup right before I tried the control. But this get's me alot closer though, thanks
    Ok... I just realized that myself (you were posting while I was editing) so where you see SetPin(), substitute DigitalWrite()

    Keep in mind that for any single step the motor is only going to move a couple of degrees, so you will have to cycle through the steps quite rapidly to make it appear to spin...
    Last edited by CommonTater; 12-06-2010 at 04:37 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 02:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 02:29 PM
  3. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  4. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 04:27 AM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21