Thank you for the information abot the millis function. I have uploaded the code i have at the moment, and as you can see its quite crude.
I am not really sure how to incorporate the millis fuction, or any other function for that matter which will help solve my problem.
Any suggestions?
int analogPin = A0;
int sensorValue = 0;
int threshold = 500; //amount of pressure needed to turn motor
const int togglebetweenPin = 30; //To switch between automatic(pressure pad) and manual(toggle switches one to five)
int togglebetween = 0;
const int toggleonePin = 31;
int toggleoneState = 0;
const int toggletwoPin = 32;
int toggletwoState = 0;
const int togglethreePin = 33;
int togglethreeState = 0;
const int togglefourPin = 34;
int togglefourState = 0;
const int togglefivePin = 35;
int togglefiveState = 0;
void setup() {
pinMode(44, OUTPUT); //thumb motor
pinMode(45, OUTPUT);
pinMode(46, OUTPUT); //index motor
pinMode(47, OUTPUT);
pinMode(48, OUTPUT); //middle motor
pinMode(49, OUTPUT);
pinMode(50, OUTPUT); //ring motor
pinMode(51, OUTPUT);
pinMode(52, OUTPUT); //pinky motor
pinMode(53, OUTPUT);
pinMode(2, OUTPUT); //led showing automatic control active
pinMode(3, OUTPUT); //led showing manual control active
pinMode(togglebetweenPin, INPUT);
pinMode(toggleonePin, INPUT); //controls thumb 44,45
pinMode(toggletwoPin, INPUT); //controls index 46,47
pinMode(togglethreePin, INPUT); //controls middle 48,49
pinMode(togglefourPin, INPUT); //controls ring 50,51
pinMode(togglefivePin, INPUT); //controls pinky 52,53
}
void loop() {
togglebetween = digitalRead(togglebetweenPin);
if (togglebetween ==HIGH) { //automatic part
int analogValue = analogRead(analogPin);
if(analogValue > threshold) {
digitalWrite(44, LOW);
digitalWrite(45, HIGH);
digitalWrite(46, LOW);
digitalWrite(47, HIGH);
digitalWrite(48, LOW);
digitalWrite(49, HIGH);
digitalWrite(50, LOW);
digitalWrite(51, HIGH);
delay(3000);
}
if(analogValue < threshold) {
digitalWrite(45, LOW);
digitalWrite(44, HIGH);
digitalWrite(47, LOW);
digitalWrite(46, HIGH);
digitalWrite(49, LOW);
digitalWrite(48, HIGH);
digitalWrite(51, LOW);
digitalWrite(50, HIGH);
delay(3000);
}
}
if (togglebetween == LOW) { //manual part
toggleoneState = digitalRead(toggleonePin);
toggletwoState = digitalRead(toggletwoPin);
togglethreeState = digitalRead(togglethreePin);
togglefourState = digitalRead(togglefourPin);
togglefiveState = digitalRead(togglefivePin);
if (toggleoneState == HIGH) {
digitalWrite(44, LOW);
digitalWrite(45, HIGH);
delay(3000); }
if (toggletwoState == HIGH) {
digitalWrite(46, LOW);
digitalWrite(47, HIGH);
delay(3000); }
if (togglethreeState == HIGH) {
digitalWrite(48, LOW);
digitalWrite(49, HIGH);
delay(3000); }
if (togglefourState == HIGH) {
digitalWrite(50, LOW);
digitalWrite(51, HIGH);
delay(3000); }
if (togglefiveState == HIGH) {
digitalWrite(52, LOW);
digitalWrite(53, HIGH);
delay(3000); }
}
}