uwezi icon

labb_7_stepper_demo.c

uwezi | PRO | 12/02/20 08:47:34 PM UTC | 0 ⭐ | 1778 👁️ | Never ⏰ | []
C |

390 B

|

None

|

0 👍

/

0 👎

#include <avr/io.h>
#include <util/delay.h>
 
// quick and dirty: the stepping sequence as 8 constant values
uint8_t steps[8]={0b0001,0b0011,0b0010,0b0110,0b0100,0b1100,0b1000,0b1001};
 
int main(void)
{
  uint8_t i=0;
  DDRD = 0x0F;  // motor driver connected to PD0-PD3
 
  while (1)
  {
    PORTD = steps[i];
    i++;
    i %= 8;
    _delay_ms(1);    // delay between steps
  } 
}
 

Comments