Arduino MEGA 2560
SyRen50 motor controller
5V Wall Wart for Arduino
eTopxizu 12V, 30A regulated supply for SyRen/Motor (this may be undersized (12V, 900W tarp motor) but it seems to be holding up for the moment.
Arrangement: Arduino has 2 PBs with pulldown resistors and 2 LEDs with series resistors. TX1 is connected to a serial terminal on the SyRen motor controller. The motor controller interfaces the power supply and the motor.
Problem: I want the motor to ramp up to a max speed (63 in this case) when button 1 is held but immediately ramp down when button 1 is released. Ideally, the motor would stop ramping up immediately upon button 1 release regardless of where it is in the ramp and start ramping down towards 0. If button 1 is pressed again before reaching 0, the motor would pick up ramping from its current speed back to it’s maximum provided button 1 is held sufficiently long. (Think of those silly helicopter games where the longer you hold the space bar, the higher it flies until it crashes into something; release the space bar and it starts to fall)
The next step, once this is figured out, would be for button 2 to do the same as button 1, just in the opposite direction. Then some equipment safety code to prevent a change of direction when the motor speed is != 0.
With the code I have below, the motor ramps to full speed regardless of how long I press button 1. If I press button 2 (again, I don’t want to use button 2 for this purpose but it’s the only thing I’ve been able to figure out) nothing happens unless the motor is at full speed, at which point it will ramp to 0.
If curious there is some additional detail at this link but I believe everything pertinent is here.
Previous Related Topic
Current Code In Its Entirety:
#include <SyRenSimplified.h>
SyRenSimplified SR;
const int BUTTON1 = 52; //ccw direction button
const int BUTTON2 = 53; //cw direction button
const int LED1 = 22; //input confirmation light for B1
const int LED2 = 23; //input confirmation light for B2
int BUTTONstate1 = 0;
int BUTTONstate2 = 0;
void setup()
{
pinMode(BUTTON1, INPUT);
pinMode(BUTTON2, INPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
SyRenTXPinSerial.begin(9600);
}
void loop()
{
int power = 0;
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
BUTTONstate1 = digitalRead(BUTTON1);
BUTTONstate2 = digitalRead(BUTTON2);
for (power = 0; power <= 63 && BUTTONstate1 == HIGH; power ++)
{
SR.motor(power);
delay(20);
}
for (power = 63; power >= 0 && BUTTONstate2 == HIGH; power --)
{
SR.motor(power);
delay(20);
}
}
If further curious, here is the endgame: I don’t know if it helps any but, at the end of what will probably be a very long exercise for me, I will be using this hardware to drive an observatory dome. As such, it will need to be able to go either direction by knowing the domes position (I plan to use an encoder) and how far it is from the desired position. It would then energize the motor in the appropriate direction, stopping at the right spot within some TBD margin of error. The ramping feature is intended to minimize mechanical wear and tear. I’m not looking for help on the whole shebang at this point just on these baby steps. I sincerely appreciate any further input!!!
SabertoothArduinoLibraries.zip (382 KB)