Hi All,
Bit of a nerve but I am coding a buggy controller I can get the forward, left, right, and back action needed from the below sketch but the Arduino Uno I am using gets hung up, enters a loop which I can't get out of with the below sketch (I know its not elegant but its a proof of concept)
Robot 1a 7/1/2014 10:53,
Code to get Switching of LED switch LED's See Photo
Test for driving H-Bridge 13/03/2014
Getting Second set of switches to switch 15/3/2014 16:24
Got H-Bridge soldered up and tested connection to Uno,
sucessfully, next work on case! 29/03/2014 18:44`
Now getting Uno to Drive Motors Sensibly 24/12/2014
Getting responce to switches better needs more testing 27/12/2014
Getting Left & Right Turns & Backwards control 29/12/2014
Suddenly working further test tomorrow! 29/12/2014
*/
const int LEDPin = 13;
const int LEDPin1 = 7;
const int LEDPin2 = 8;
const int LEDPin3 = 9;
const int LEDPin4 = 10;
const int InputPin1 = 2;
const int InputPin2 = 4;
const int InputPin3 = 3;
const int InputPin4 = 5;
int delayTime = 100;
void setup()
{
pinMode(LEDPin1, OUTPUT);
pinMode(LEDPin, OUTPUT);
pinMode(LEDPin2, OUTPUT);
pinMode(LEDPin3, OUTPUT);
pinMode(LEDPin4, OUTPUT);
pinMode(InputPin1, INPUT);
pinMode(InputPin2, INPUT);
pinMode(InputPin3, INPUT);
pinMode(InputPin4, INPUT);
digitalWrite(InputPin1, HIGH);
digitalWrite(InputPin2, HIGH);
digitalWrite(InputPin3, HIGH);
digitalWrite(InputPin4, HIGH);
}
void loop()
{
Serial.begin(9600);
digitalWrite(LEDPin,HIGH);
int val1 = digitalRead(InputPin1);
int val2 = digitalRead(InputPin2);
int val3 = digitalRead(InputPin3);
int val4 = digitalRead(InputPin4);
int a;
if(val1 == HIGH && val3 == HIGH)
{
for(a = 0; a<=10; a++)
{
digitalWrite(LEDPin1,HIGH);
digitalWrite(LEDPin3,HIGH);
Serial.println(" Forwards!");
delay(delayTime);
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
}
}
if(val2 == LOW)
{
for(a = 0;a<=100;a++)
{
Serial.println("RESET");
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
delay(delayTime);
}
}
//will drive forwards until switch hit, need to find way of getting turn and then resetting to drive
//might have it, needs more testing & tuning of for loop
/*
{
//Serial.println(" Forwards Called ");
}else
while(val1 == HIGH && val3 == HIGH)
{
}
*/
if(val1 == LOW && val3 == HIGH)
{
for(a = 0; a<=10; a++)
{
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
delay(delayTime);
digitalWrite(LEDPin1,HIGH);
digitalWrite(LEDPin3,LOW);
Serial.println(" Turn Left!");
delay(delayTime);
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
}
}
if(val1 == HIGH && val3 == LOW)
{
for(a = 0; a<=10; a++)
{
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
delay(delayTime);
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,HIGH);
Serial.println(" Turn Right!");
delay(delayTime);
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
}
}
if(val1 == LOW && val3 == LOW)
{
for(a = 0; a <=10;a++)
{
Serial.println("STOP!!");
digitalWrite(LEDPin1,LOW);
digitalWrite(LEDPin3,LOW);
//digitalWrite(LEDPin1,LOW);
//digitalWrite(LEDPin3,LOW);
}
for(a = 0; a <=4 ; a++)
{
delay(delayTime);
Backwards();
}
}
}
*/
void Backwards()
{
for(int a = 0; a <= 10; a++)
{
//both motors Backwards
digitalWrite(LEDPin2,HIGH);
digitalWrite(LEDPin4,HIGH);
Serial.println(" Backwards! ");
}
}