So this is my code int
So this is my code
int motor right = 11;
int motor left = 10;
int light sensor 2 = 3;
int light sensor 1 = 2;
void setup() {
pinMode(motor right, OUTPUT);
pinMode(motor left, OUTPUT);
pinMode(light sensor 1, INPUT);
pinMode(light sensor 2, INPUT);
boolean running = true;
}
void loop()
{
if (digitalRead(light sensor 1) == LOW && digitalRead(light sensor 2) == LOW)
{
digitalWrite(motor right, HIGH);
digitalWrite(motor left, HIGH);
delay(500);
}
else if (digitalRead(light sensor 2) == LOW)
{
digitalWrite(mottor right, LOW);
digitalWrite(motor left, HIGH);
delay(500);
}
else if (digitalRead(light sensor 1) == LOW)
{
digitalWrite(motor right, HIGH);
digitalWrite(motor left, LOW);
delay(500);
}
else
{
digitalWrite(motor right, HIGH);
digitalWrite(motor left, HIGH);
}
}
Now say I have 2 of the same sketches but one is for obstacle avoidence and the other for light following how can I put them in to a function?
I think the function is what I need can some pleas show me how to put one in my sketch, so I can make some thing like the first reply thanks.
111swords