Modelspoormagazine 234 – april 2023 – Arduino Sketch van de draaischijf:
#include <Stepper.h>
#include <SpeedyStepper.h>
#define STEP_PIN A4 // to STEP pin of driver
#define DIR_PIN A3 // to DIR pin of driver
#define POS_1_PIN 2 // LOW = go to pos 1
#define POS_2_PIN 3 // LOW = go to pos 2
#define POS_3_PIN 4 // LOW = go to pos 3
#define POS_4_PIN 5 // LOW = go to pos 4
#define POS_5_PIN 6 // LOW = go to pos 5
#define POS_6_PIN 7 // LOW = go to pos 6
#define MS1 A1
#define MS2 A2
#define PULSES_PER_REV 600
int new_pos = 0;
int current_pos = 0;
int numsteps = 0;
//define in steps the track positions from homing point.
int a = 800;
int b = 1208;
int c = 2150;
int d = 2650;
int e = 3200;
int f = 3608;
// create the stepper motor object
SpeedyStepper stepper;
void setup() {
pinMode(8,OUTPUT); // relay 1
pinMode(9,OUTPUT); // relay 2
pinMode(POS_1_PIN, INPUT_PULLUP);
pinMode(POS_2_PIN, INPUT_PULLUP);
pinMode(POS_3_PIN, INPUT_PULLUP);
pinMode(POS_4_PIN, INPUT_PULLUP);
pinMode(POS_5_PIN, INPUT_PULLUP);
pinMode(POS_6_PIN, INPUT_PULLUP);
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
digitalWrite(MS1, HIGH);
digitalWrite(MS2, HIGH);
// connect and configure the stepper motor to its IO pins
stepper.connectToPins(STEP_PIN, DIR_PIN);
}
void rotate()
{
stepper.setSpeedInStepsPerSecond(100);
stepper.setAccelerationInStepsPerSecondPerSecond(30);
stepper.moveRelativeInSteps(numsteps);
}
void loop()
{
if(digitalRead(POS_1_PIN) == LOW) {new_pos = a; digitalWrite (8, LOW); digitalWrite (9, LOW);}
if(digitalRead(POS_2_PIN) == LOW) {new_pos = b; digitalWrite (8, LOW); digitalWrite (9, LOW);}
if(digitalRead(POS_3_PIN) == LOW) {new_pos = c; digitalWrite (8, LOW); digitalWrite (9, LOW);}
if(digitalRead(POS_4_PIN) == LOW) {new_pos = d; digitalWrite (8, LOW); digitalWrite (9, LOW);}
if(digitalRead(POS_5_PIN) == LOW) {new_pos = e; digitalWrite (8, HIGH); digitalWrite (9, HIGH);}
if(digitalRead(POS_6_PIN) == LOW) {new_pos = f; digitalWrite (8, HIGH); digitalWrite (9, HIGH);}
numsteps = (new_pos – current_pos);
rotate();
current_pos = new_pos;
}