Hello everybody,
I'm new to Arduino, and I have a relatively simple question to ask. It is possible for an else if statement to return and run the original if statement code upon completion?
Here is my code:
#include <IRremote.h>
#include <MotorLibrary.h>
MotorLibrary motorLibrary;
int RECV_PIN = 2; //define input pin on Arduino
IRrecv irrecv(RECV_PIN);
decode_results results;
#include <Ultrasonic.h>
int PIEZOPin = 9; // Pin used for the PIEZO Speaker
int maximumRange = 45; // Maximum range needed
int minimumRange = 0; // Minimum range needed
Ultrasonic ultrasonic(5, 6); // (Trig PIN,Echo PIN)
void setup()
{
pinMode(PIEZOPin, OUTPUT);// Use Piezo (if required)
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
motorLibrary.debugMotors(true);
}
void loop() {
long distance = ultrasonic.Ranging(CM); // CM or INC
//Serial.print("Object distance (in cm's) = ");
if (results.actualKey == "*")
{
motorLibrary.forward(255);
}
else if (distance <= maximumRange)
{
motorLibrary.stopMotors();
}
irrecv.resume(); // Receive the next value
}
Basically, I want my tank to detect and object, avoid it, and then continue on.
I've tried using while statements and the like to no avail, so I'm back to where I have started.
Any help is greatly appreciated