Hi,
i have one small problem. New in programming arduino.
Have on RF remote control with 4 buttons. I want to regulate 2 motors in the folowing way:
- Button A - On/Off both motors
- Button B - change direction for 2 motor both ways
- Button C - minus speed for 2 motor
- Button D - plus speed for 2 motor.
Till now i only managed to get working On/Off option, all other options dont wokr and i dont know how to solve it.
The remote is PT2272
Here the code :
const int buttonOnOff = 4;
const int buttonDirection = 2 ;
const int buttonUp = 5;
const int buttonDown = 3;
int stanje = LOW;
int stanje1 = LOW;
int buttonState = 0;
int buttonPushCounter = 0;
int ParamCount = 20;
int Parameter = 1;
int Param[20];
int outPin0 = 8; // Digital Input 2
int outPin1 = 9; // Digital Input 1
int outPin2 = 10; // PWM Motor 1
int outPin3 = 11; // PWM Motor 2
int outPin4 = 12; // Digital Input 1
int outPin5 = 13; // Digital Input 2
boolean Mode[] = {HIGH, LOW, LOW};
boolean lastButtonState[] = {LOW, LOW, LOW, LOW};
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 400; // the debounce time, increase if the output flickers
void setup() {
// RF is input
pinMode(buttonOnOff, INPUT);
pinMode(buttonDirection, INPUT);
pinMode(buttonUp, INPUT);
pinMode(buttonDown, INPUT);
//Motor enable PINS
pinMode(outPin2, OUTPUT);
pinMode(outPin3, OUTPUT);
//Motor PINS
pinMode(outPin1, OUTPUT);
pinMode(outPin0, OUTPUT);
pinMode(outPin4, OUTPUT);
pinMode(outPin5, OUTPUT);
}
void loop() {
//Read button OnOFF
buttonState = digitalRead(buttonOnOff); //Read button state
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (buttonState == HIGH && lastButtonState[1] == LOW && millis() - time > debounce) {
if (stanje == HIGH)
stanje = LOW;
else
stanje = HIGH;
time = millis();
}
if (stanje == LOW) {
digitalWrite(outPin2, LOW);
digitalWrite(outPin3, LOW);
digitalWrite(outPin1, HIGH);
digitalWrite(outPin0, LOW);
digitalWrite(outPin4, HIGH);
digitalWrite(outPin5, LOW);
}
else
digitalWrite(outPin2, HIGH);
analogWrite(outPin3, 255);
lastButtonState[1] = buttonState;
//Read direction button
if (digitalRead(buttonDirection) == HIGH)
{
digitalWrite(outPin2, HIGH);
digitalWrite(outPin3, HIGH);
digitalWrite(outPin1, HIGH);
digitalWrite(outPin0, LOW);
digitalWrite(outPin4, LOW);
digitalWrite(outPin5, HIGH);
}
}
Regards!
Leo