Hi,
I recently started with programming my arduino and hardly know anything about it, so I hope you can help me. I try to make a stepper motor change it's RPM every minute to a value described in an array. However somehow the delay I use seems to stop the stepper motor completely. I use the CustomStepper library. Can you help me with what I'm doing wrong?
Thanks a lot!
//Copyright 2012 Igor Campos
//
//This file is part of CustomStepper.
//
//CustomStepper is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//CustomStepper is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with CustomStepper. If not, see <http://www.gnu.org/licenses/>.
#include <CustomStepper.h>
//lcdschermpje
#include <LiquidCrystal.h>
//rs op pin 12
//rw op pin 11
//d4,d5,d6,d7 op pin 6,7,8,9
LiquidCrystal lcd(12,11,6,7,8,9);
//Full constructor, just the first 4 parameters are necessary, they are the pins connected to the motor,
//the others are optional, and default to the following below
//the 5th paramater is the steps sequence, where the 1st element of the array is the number of steps
//it can have a maximum of 8 steps
//the 6th parameter is the SPR (Steps Per Rotation)
//the 7th parameter is the RPM
//the 8th parameter is the rotation orientation
CustomStepper stepper(2, 3, 4, 5, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 4075.7728395, 12, CW);
//boolean rotate1 = false;
//boolean rotatedeg = false;
//boolean crotate = true;
float lut[] = {10,5,1,.5,1,2};
int i=0;
void setup()
{
//sets the RPM
stepper.setRPM(15);
//sets the Steps Per Rotation, in this case it is 64 * the 283712/4455 annoying gear ratio
//for my motor (it works with float to be able to deal with these non-integer gear ratios)
stepper.setSPR(4075.7728395);
lcd.begin(16, 2);
// Print the message to the lcd.
lcd.setCursor(0, 0); // First row.
lcd.print("Volg de sterren!!!!");
lcd.setCursor(0, 1); // First row.
lcd.print("***************************");
lcd.display();
}
void loop()
{
float value = lut[i%6];
stepper.setRPM(value);
//when a command is finished the isDone will return true, it is important to notice that
//you can't give one command just after another since they don't block the execution,
//which allows the program to control multiple motors
if (stepper.isDone()
)
{
//this method sets the direction of rotation, has 3 allowed values (CW, CCW, and STOP)
//clockwise and counterclockwise for the first 2
stepper.setDirection(CCW);
//this method sets the motor to rotate a given number of times, if you don't specify it,
//the motor will rotate untilyou send another command or set the direction to STOP
stepper.rotate(1);
}
stepper.run();
lcd.setCursor(0,0);
lcd.print(value);
lcd.display();
delay(60000);
i++;
}