This is my first post. I have been playing with this project and can not figure out how to make my motor not delay but to continue.
At the end of the if statement "if (digitalRead(StopSensor) == LOW) {" the motor will not move as needed. I need the motor to move without a time limit, to move on infinitely until a button or switch is pushed.
[code]
int StartButton = 13;
const int forwards = 7; // Actuator
const int backwards = 6; // Actuator
int ForwardSwitch = 5;
int ReverseSwitch = 4;
int StopSensor = 2; // Proximity Sensor
#include <SoftwareSerial.h> // Wheel Chair Motor
#include <SyRenSimplified.h> // Wheel Chair Motor
SyRenSimplified SR; // Wheel Chair Motor
void setup() {
pinMode(StartButton, INPUT);
pinMode(StopSensor, INPUT_PULLUP); // Proximity Sensor
pinMode(ForwardSwitch, INPUT);
pinMode(ReverseSwitch, INPUT);
pinMode(forwards, OUTPUT); // Actuator set relay as an output
pinMode(backwards, OUTPUT); // Actuator set relay as an output
SyRenTXPinSerial.begin(9600); // Wheel Chair Motor
}
void loop() {
if (digitalRead(ForwardSwitch) == HIGH) {
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
SR.motor(40); // -127 full reverse. 0 os Stop. +127 if full forward
delay(250);
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
}
if (digitalRead(StartButton) == HIGH) {
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
SR.motor(40); // -127 full reverse. 0 os Stop. +127 if full forward
delay(20);
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
}
if (digitalRead(StopSensor) == LOW) { // Proximity Sensor
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
digitalWrite(forwards, LOW); // Actuator-Activate the relay one direction, they must be different to move the motor
digitalWrite(backwards, HIGH); // Actuator
delay(1000); // Actuator
digitalWrite(forwards, HIGH); // Actuator-Deactivate both relays to brake the motor
digitalWrite(backwards, HIGH); // Actuator-Deactivate both relays to brake the motor
delay(2000); // Actuator
digitalWrite(forwards, HIGH); // Actuator
digitalWrite(backwards, LOW); // Actuator-Activate the relay the other direction, they must be different to move the motor
delay(1000); // Actuator
digitalWrite(forwards, HIGH); // Actuator-Deactivate both relays to brake the motor
digitalWrite(backwards, HIGH); // Actuator
delay(2000); // Actuator
//Here is the Problem
SR.motor(40); // -127 full reverse. 0 os Stop. +127 if full forward
delay(20);
}
if (digitalRead(ReverseSwitch) == HIGH) {
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
SR.motor(-40); // -127 full reverse. 0 os Stop. +127 if full forward
delay(1000);
SR.motor(0); // Stop Wheel Chair Motor
delay(20);
}
}
[/code]