Basically I'm doing a very very basic command (a remote car), and I wanted to do so every 10 seconds of inactivity on the inputs, it randomizes movement until a input is inserted. I am pretty sure on how to do the randomizer one but I just cant seem to tell how to write "the robot isn't receiving any inputs" to arduino.
Here's the code:
#include <TimeLib.h>
int r=random(1, 8);
int c=random(0, 5000);
int d=random(0,5000);
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Stop();
}
void loop() {
time_t t=now();
Serial.println(analogRead(A0));
Serial.println(analogRead(A1));
Serial.println(analogRead(A2));
Serial.println(analogRead(A3));
if (analogRead(A0)<1)
{
backward();
}
else if (analogRead(A1)<1)
{
forward();
}
else if (analogRead(A2)<1)
{
left();
}
else if (analogRead(A3)<1)
{
right();
}
else {
Stop();
}
while (t>=10 && /*i am not sure of what to put here*/)
{
/*here is the random code, of which i didnt do yet*/
}
}
void forward()
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
void backward()
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
void left()
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void right()
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
void Stop()
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void start()
{
if (analogRead(A0)<1)
{
backward();
}
else if (analogRead(A1)<1)
{
forward();
}
else if (analogRead(A2)<1)
{
left();
}
else if (analogRead(A3)<1)
{
right();
}
}