I am new to Arduino and I am learning how to avoid using delay.
I have written some code to move my servo by 20° using delays, but can only move the servo once with my current code. In setup(), I assign the servo 150. The next value the servo receives is 15, which it performs. It does not iterate through the following values though. I have been using this guide, BlinkWithoutDelay, with no luck.
Here is my code:
#include <Servo.h> Servo myservo; unsigned long previousMillis = 0; const long interval = 1000; void setup() { myservo.attach(9); myservo.write(150); } void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; myservo.write(15); } if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; myservo.write(35); } if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; myservo.write(65); }