All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stepper.bas File Reference

Example: control a stepper motor. More...

`#include "../pruio/pruio.bi"`
`#include "../pruio/pruio_pins.bi"`
Include dependency graph for stepper.bas:

Go to the source code of this file.

## Macros

#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.

## Functions

SUB | move (BYVAL_AS_PruIo_PTR Io, BYVAL_AS_BYTE Rot=1)
| make the motor move the next step. More...
int | main ()

## Variables

VAR | io = NEW PruIo
| Create a PruIo structure, wakeup subsystems.
VAR | w = 128
| The wait (delay) value.
VAR | d = 0
| The direction value.
VAR | x = 16
| The cursor column for output.
VAR | y = CSRLIN() - 1
| The cursor line for output.
VAR | k = ASC(INKEY())
| The key code.

## Detailed Description

Example: control a stepper motor.

This file contains an example on how to use libpruio to control a 4-wire stepper motor:

- configure 4 pins as output
- receive user action in loop
- inform user about the current state
- change motor direction
- change motor speed
- stop holded or in power off mode
- move a single step (in holded mode)
- quit

Licence: GPLv3

Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net

Compile by: `fbc -w all stepper.bas`

Definition in file stepper.bas.

## Function Documentation

int main | ( |  | ) |

The main function.

Definition at line 151 of file stepper.bas.

Here is the call graph for this function:

SUB move | ( | BYVAL_AS_PruIo_PTR | Io,
|  | BYVAL_AS_BYTE | Rot = `1`
| ) |  |

make the motor move the next step.

Parameters

  Io | pointer to PruIo structure
  Rot | direction of rotation (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 50 of file stepper.bas.