Skip to main content
Fixed minor typos, added code formatting, inlined link and removed thanks
Source Link

trouble Trouble when avoiding delays

I am new to Arduino and I am learning how to avoid using delay. 

I have written asome code to move my servo by 20 degrees20° using delays, but can only move the servo once with my current code. In setupsetup(), 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, https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay, with no luck.

hereHere 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); } 

thank you for any help,

Corey

trouble when avoiding delays

I am new to Arduino and am learning how to avoid using delay. I have written a code to move my servo by 20 degrees 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 https://www.arduino.cc/en/Tutorial/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); } 

thank you for any help,

Corey

Trouble when avoiding delays

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); } 
Tweeted twitter.com/StackArduino/status/684676433705349120
Source Link
Corey
  • 51
  • 1

trouble when avoiding delays

I am new to Arduino and am learning how to avoid using delay. I have written a code to move my servo by 20 degrees 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 https://www.arduino.cc/en/Tutorial/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); } 

thank you for any help,

Corey