Well my next round of experimentation failed nicely...
The next step is to ramp the speed of the motor. Start at value 0 (fully stopped) for either button, then add power in whichever direction (button 1 - ccw, button 2 - cw) incrementally over the next 10 seconds or so by holding the button. Let go of the button, the motor stops. Ideally it would automatically stop accelerating (adding value to 'power') at 127 or -127 (max speed) and then decelerate when the button is released.
All I was trying to do with this round is make the motor ramp up upon button press and hold, then stop on button release. What happens is the LEDs function as expected but the motor starts running as soon as 12V is applied. Then it acts like it is getting conflicting instructions from the Arduino by jerking randomly when I press either button.
I tried using for loops as well ex; for (power = 0; power <=127; power ++) but that didn't get me very far either.
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!!!
Full code here:
#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);
if (BUTTONstate1 == HIGH)
{
digitalWrite(LED1, HIGH);
power = power++;
delay(20);
}
else if (BUTTONstate2 == HIGH)
{
digitalWrite(LED2, HIGH);
power = power--;
delay(20);
}
Serial.println(power);
delay(100);
SR.motor(power);
}