Example: control a stepper motor. More...
#include "stdio.h"
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include "libpruio/pruio.h"
#include "libpruio/pruio_pins.h"
Go to the source code of this file.
Macros | |
#define | _GNU_SOURCE 1 |
Message for the compiler. | |
#define | P1 P8_08 |
The first pin of the stepper. | |
#define | P2 P8_10 |
The second pin of the stepper. | |
#define | P3 P8_12 |
The third pin of the stepper. | |
#define | P4 P8_14 |
The fourth pin of the stepper. | |
#define | PIN_OUT(a, b, c, d) |
Set values of all four output pins. More... | |
Functions | |
int | isleep (unsigned int mseconds) |
Wait for keystroke or timeout. More... | |
void | move (pruIo *Io, int Rot) |
Make the motor move the next step. More... | |
int | main (int argc, char **argv) |
The main function. More... | |
Example: control a stepper motor.
This file contains an example on how to use libpruio to control a 4-wire stepper motor:
Find a functional description in section stepper.
Licence: GPLv3, Copyright 2014-2023 by Thomas{ doT ]Freiherr[ At ]gmx[ DoT }net
Compile by: gcc -Wall -o stepper stepper.c -lpruio
Definition in file stepper.c.
Set values of all four output pins.
int isleep | ( | unsigned int | mseconds | ) |
int main | ( | int | argc, |
char ** | argv | ||
) |
void move | ( | pruIo * | Io, |
int | Rot | ||
) |
Make the motor move the next step.
Io | Pointer to PruIo structure. |
Rot | Rotation direction (1 or -1). |
This function sets 4 output pins for a stepper motor driver. It remembers the last step as static variable (starting at 0 = zero) and adds the new position to it. So the Rot parameter should either be 1 or -1 to make the motor move one step in any direction.
Definition at line 90 of file stepper.c.