Hi guys so I'm really new with Arduino and Arduino programming, and I really need help with the programming aspect.
So for more context, my project is that Whenever the proximity sensor senses an object, the if statements on my light sensor will execute, which will then program servo motors. I have been able to program the Light sensor already, but I have no idea how to program the proximity sensor.
Do i make an If statement before the other if statements? Is there a way to create a new program then call out to another program file to execute?
I'm really lost and I would appreciate any insight someone can give me. Thank you all
btw this is the code I have so far:
Servo myservo;
Servo spinny;
int light;
int pos = 0;
int lol = 0;
void setup() {
myservo.attach(9);
spinny.attach(10);
Serial.begin(9600);
myservo.write(0);
spinny.write(0);
}
void loop() {
light = analogRead(A0);
Serial.println(light);
if (light<11){
for (pos = 0; pos <= 80; pos += 1) {
myservo.write(pos);
delay(15);
}
delay(1000);
for (pos = 80; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
myservo.detach();
for (lol = 0; lol <= 80; lol += 1) {
// in steps of 1 degree
spinny.write(lol);
delay(15);
}
delay(1000);
for (lol = 80; lol >= 0; lol -= 1) {
spinny.write(lol);
delay(15);
}
spinny.detach();
}
else if (light>13) {
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15);
}
delay(1000);
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
myservo.detach();
for (lol = 0; lol <= 180; lol += 1) {
spinny.write(lol);
delay(15);
}
delay(1000);
for (lol = 180; lol >= 0; lol -= 1) {
spinny.write(lol);
delay(15);
}
spinny.detach();
}
else
myservo.detach();
spinny.detach();
}