Hi,
I'm trying to get my Elegoo stepper motor to use the code I found on this site. So it just moves randomly from left to right.
#include <Adafruit_Soundboard.h>
#include <Servo.h>
//constants
const int soundLoop = 2;
const int servo = 5;
const int IR = 10;
//variables
Servo myservo; // create servo object to control a servo
long randomMove;
long randomDelay;
//======================================
void setup() {
// put your setup code here, to run once:
pinMode(soundLoop, OUTPUT);
pinMode(IR, INPUT);
pinMode(servo, OUTPUT);
myservo.attach(servo);
}
//======================================
void loop() {
digitalWrite(soundLoop, LOW);
servoSweep();
}
// ======================================
void servoSweep() {
randomMove = random(0,360);
myservo.write(randomMove);
randomDelay = random(500,2500); // random amount of time moving
delay(randomDelay); // how long it's moving
myservo.write(90); // Stop
randomDelay = random(5000,15000); // random amount of time to be stopped
delay(randomDelay); // how long it's stopped
}
I removed the bits for sound. I don't need that (yet) and amended the code to this
//Stepper Motor Control - random movement
// Include the Stepper Library
#include <Stepper.h>
//constants
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 15; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
long randomMove;
long randomDelay;
void setup() {
myStepper.setSpeed(rolePerMinute);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
stepperSweep();
}
void stepperSweep() {
randomMove = random(0,180);
myStepper.write(randomMove);
randomDelay = random(500,2500); // random amount of time moving
delay(randomDelay); // how long it's moving
myStepper.write(90); // Stop
randomDelay = random(5000,15000); // random amount of time to be stopped
delay(randomDelay); // how long it's stopped
}
It's a mishmash of the code I found and the code supplied by Elegoo but it returns this error
D:\Projects\stepper_random\stepper_random.ino: In function 'void stepperSweep()':
D:\Projects\stepper_random\stepper_random.ino:31:11: error: 'class Stepper' has no member named 'write'
myStepper.write(randomMove);
^~~~~
D:\Projects\stepper_random\stepper_random.ino:35:11: error: 'class Stepper' has no member named 'write'
myStepper.write(90); // Stop
^~~~~
exit status 1
Compilation error: 'class Stepper' has no member named 'write'
Apparently it's trying to call something from the Servo.h library which isn't in the Stepper.h library?
Any ideas on how to fix this or do it better would be appreciated. I'm a complete noob and this is waaaaay out of my league.