I’m new to this so its taking me a little bit to get things working. I’m attempting to write a code that will move from position 135 at a pin Write being HIGH and 45 at the reading being LOW. The idea is to be able to turn the light to my room on or off from my phone. I also plan on using a light sensor that will be able to tell me if the light is actually on or off, however that’s further down the line. My current code that I tried looks like this;
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 135; // variable to store the servo position
void setup()
{
myservo.attach(A5); // attaches the servo on pin 0 to the servo object
}
void loop()
{
if (digitalRead(A0) == HIGH)
{
pos = 45;
myservo.write(pos);
delay(15);
}
if (digitalRead(A0) == LOW)
{
pos = 135;
myservo.write(pos);
delay(15);
}
}
My servo is connected to pin A5. I placed this in a new app on the Particle build platform and flashed it and there were no issues, however when I go to the app from my phone I’m not getting the result I’m looking for. I realize that i need to place the code in the Tinker app already installed with the device, however when I try to place this code (or something similar into the tinker app I get an error. Does anyone have advice or direction for me? It would be greatly appreciated.
-PB