SkillDev4- Chengzhi Zhang
Made by Chengzhi Zhang
Made by Chengzhi Zhang
Created: November 28th, 2021
int servoPin = A3;
int servoPosition = 0;
Servo servo;
void setup()
{
//Serial.begin( 9600 );
//Particle.function( "pos", setPosition );
servo.attach( servoPin );
}
void loop()
{
for (servoPosition = 0; servoPosition <= 180; servoPosition+=1) {
servo.write(servoPosition);
delay(15);
}
for (servoPosition = 180; servoPosition >= 0; servoPosition-=1) {
servo.write(servoPosition);
delay(15);
}
}
Click to Expand
int servoPin = A3;
int servoPosition;
Servo servo;
int countDown;
// bool flag = true;
void setup()
{
Serial.begin( 9600 );
countDown = Particle.function( "Set time to remind (unit: seconds):", setTime );
servo.attach( servoPin );
}
void loop() {
delay( countDown * 1000);
for (servoPosition = 0; servoPosition <= 180; servoPosition+=1) {
servo.write(servoPosition);
delay(5);
}
for (servoPosition = 0; servoPosition <= 180; servoPosition+=1) {
servo.write(servoPosition);
delay(5);
}
// for (servoPosition = 180; servoPosition >= 0; servoPosition-=1) {
// servo.write(servoPosition);
// delay(5);
// }
//pinMode( servoPin, OUTPUT );
//pinMode( servoPin, INPUT );
}
int setTime( String command ){
Serial.println( "setTime: " + command );
return command.toInt();
}
Click to Expand
Firstly, I used the servo with simple code to test whether the servo works or not. The servo does not have great connectivity. It works better when I pushed the jumper wires to the bread board. Laters on, I tried to implement the particle function with servo. I drew inspiration from the Google paper prototype and also the "pomodoro technique" software that I use. In the end, the servo doesn't work that stable.
Reflecting on last time's project, I made improvements on the code of my project, like calling the function input a more intuitive name and so on. It turned out to be it has really bad connectivity so that the servo is not running in an ideal way. Next time, when you have confidence in your code, maybe it's not the code to blame, but the physical prototype that you should keep an eye on and test. Maybe test it with other people's prototype will work