I want to create a script for a steppermotor that finds it 0point when the Photomicrosensor is activated.
I tried combinding 2 existing working scripts but i failed horribly.
Can any of you point me in the right direction?
- Code: Select all
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
#define STEPS 2000
// Connect a stepper motor with variable steps per revolution
// to motor port #2 (M3 and M4)
AF_Stepper motor(STEPS, 2);
int previous = 0;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Stepper test!");
motor.setSpeed(30); // 30 rpm
}
void loop()
{
Serial.println("Single coil steps");
motor.step(100, FORWARD, SINGLE);
motor.step(100, BACKWARD, SINGLE);
// get the sensor value
int val = analogRead(0);
// move a number of steps equal to the change in the
// sensor reading
AF_Stepper.step(val - previous);
// remember the previous value of the sensor
previous = val;
}

