Commit 21e4a8ee authored by Tim Soderstrom's avatar Tim Soderstrom

Cut down program just to turn the rotary

parent 13e411d9
/* DevDawg Rotary
*
* Open Source Arduino-Based Rotary Film Development Controller.
* by Tim Soderstrom
*
* Licensed under the GPLv3 (see LICENSE for more information)
*
* This is a smaller program that just handles turning the rotary
* (so no display output, no temps, etc.)
* Effectively it's a fancy 555 style timer circuit :P
*/
/**********
* Defines
**********/
#define SECONDS_MS 1000
#define FORWARD 0
#define REVERSE 1
#define ON 1
#define OFF 0
// Specified Motor RPM
// #define MOTOR_RPM 76
// Motor Start Percentage
#define MOTOR_START_PCT 100
// Slowest Motor Will Turn
// #define MOTOR_MIN_RPM 24
#define MOTOR_MIN_PCT 50
// How long to free spin motor when changing direction
// #define COAST_MOTOR_MILLIS 500
#define COAST_MOTOR_MILLIS 1000
// How many seconds between direction changes
#define DEFAULT_DIRECTION_INTERVAL 10
/***********
* Includes
***********/
/*******
* Pins
*******/
const byte motorSpeed = 5;
const byte motorX = 6;
const byte motorY = 7;
/************
* Variables
************/
unsigned long previousMotorMillis = 0;
unsigned long previousCoastMillis = 0;
int motorSpeedCurrent = 0;
bool motorDirection = FORWARD;
// If we need to coast
bool motorCoast = true;
// If we are actively coasting
bool motorCoasting = true;
/*******
* Code
********/
void setup()
{
pinMode(motorSpeed, OUTPUT);
pinMode(motorX, OUTPUT);
pinMode(motorY, OUTPUT);
analogWrite(motorSpeed, 0);
digitalWrite(motorX, LOW);
digitalWrite(motorY, LOW);
}
void loop()
{
runMotor();
}
void runMotor()
{
// byte rpm = MOTOR_RPM;
byte rpm = MOTOR_START_PCT;
byte directionInterval = DEFAULT_DIRECTION_INTERVAL;
bool runMotor = true;
while(true)
{
if(runMotor)
controlMotor(rpm, directionInterval);
else
controlMotor(0, 0);
}
}
void controlMotor(byte speed, byte directionInterval)
{
if(directionInterval > 0)
{
// Coast on direction change
if(motorCoast)
{
analogWrite(motorSpeed, 0);
motorCoasting = true;
if (millis() - previousCoastMillis >= COAST_MOTOR_MILLIS && motorCoast)
{
Serial.println("Done Coasting");
motorCoasting = false;
}
}
// If we're not coasting, make sure we set the speed to whatever is being requested
else if (!motorCoast)
analogWrite(motorSpeed, toSpeed(speed));
if(millis() - previousMotorMillis >= SECONDS_MS * directionInterval)
{
// Flag we need to coast the motor
// If we are coasting, do nothing
if(motorCoasting)
{
}
// If we are not currently coasting, but
else if(!motorCoast)
{
Serial.println("Coast Requested");
previousCoastMillis = millis();
motorCoast = true;
}
// Now Change Direction
else if(!motorCoasting)
{
Serial.println("Motor Running");
analogWrite(motorSpeed, toSpeed(speed));
changeDirection();
motorCoast = false;
previousMotorMillis = millis();
}
}
}
/* If directionInterval is zero, never change speed */
else
{
analogWrite(motorSpeed, toSpeed(speed));
digitalWrite(motorX, HIGH);
digitalWrite(motorY, LOW);
motorDirection = FORWARD;
}
}
int toSpeed(byte value)
{
// return map(value, 0, MOTOR_RPM, 0, 255);
// Changing to percent over raw RPMs
return map(value, 0, 100, 0, 255);
}
void changeDirection()
{
if(motorDirection == FORWARD)
{
Serial.println("Motor: Reverse");
digitalWrite(motorX, LOW);
digitalWrite(motorY, HIGH);
motorDirection = REVERSE;
}
else
{
Serial.println("Motor: Forward");
digitalWrite(motorX, HIGH);
digitalWrite(motorY, LOW);
motorDirection = FORWARD;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment