First, you've helped me and dozens of others to understand "blink w/o delay". I have employed it a number of times but struggle with it each time. Delay is easy to use, you want an action to continue for a set period of time you write delay(time in ms). So very easy. "blink w/o delay" is not as easy to implement (at least for me).
In the first instance I write to the servo using the millis timing method as I have used it in the past. It does not work. I have obviously missed something.
What I want to do is indicated by the three other servo processes. The code follows:
#include <Servo.h>
#include <Ping.h>
Ping ping = Ping(8,74,19);
Servo myservo; // create servo object to control a servo
long blinkTimer2;
int pos = (0); // variable to store the servo position
int outputPin = 12;
int outputPin2 = 13;
int outputPin3 = 11;
void setup()
{
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(outputPin, OUTPUT);
pinMode(outputPin2, OUTPUT);
pinMode(outputPin3, OUTPUT);
}
void loop()
{
ping.fire();
Serial.print("Microseconds: ");
Serial.print(ping.microseconds());
Serial.print(" | Inches ");
Serial.print(ping.inches());
//Serial.print(" | Centemeters: ");
//Serial.print(ping.centemeters());
Serial.println();
{
myservo.write(0);
Serial.print(0);
Serial.println(" ");
digitalWrite(outputPin2, HIGH);
blinkTimer2 = millis() + 1500;
digitalWrite(outputPin2, LOW);
blinkTimer2 = millis() + 35;
}
{
myservo.write(90);
Serial.print(90);
Serial.println(" ");
digitalWrite(outputPin3, HIGH);
delay(1000);
digitalWrite(outputPin3, LOW);
delay(35);
}
{
myservo.write(180);
Serial.print(180);
Serial.println(" ");
digitalWrite(outputPin, HIGH);
delay(1000);
digitalWrite(outputPin, LOW);
delay(35);
}
{
myservo.write(90);
Serial.print(90);
Serial.println(" ");
digitalWrite(outputPin3, HIGH);
delay(1000);
digitalWrite(outputPin3, LOW);
delay(35);
}
}