This time of year is project time for me and the success of the flag waver has got me thinking !
It would be great if I could hook up ,say three yellow flag waving marshalls, on a bend who could be triggered to wave in sequence.
PCLC already fires up flashing yellow lights around the track through an Arduino Uno ,when the race director hits the yellow flag button - so I’m hoping that with the correct extra bit of code in the sketch this could be used to also trigger servos to work in sequence, while the yellow flag call is on.
I would very much appreciate it if anybody could take a look at this for me (as I'm not a coder!!

)
Here is the current sketch to look at:-
//start
// define which pins are to be used for the various light functions
#define GREEN1 12 //edit for your green pin
#define AMBER1 11 //edit for your amber/yellow pin
#define AMBER2 2 //edit for your amber/yellow pin // Extra amber light output - Greg Kilkenny, 08/04/18
#define RED1 10 //edit for your 5th red pin
#define RED2 9 //edit for your 4th red pin
#define RED3 8 //edit for your 3rd red pin
#define RED4 7 //edit for your 2nd red pin
#define RED5 6 //edit for your 1st red pin
#define BLUE1 5 //edit for your blue pin
#include <Servo.h>
int amberswPin = 4;//edit to be any unused digital pin
int blueswPin = 3;//edit to be any unused digital pin
int ledPin = 13;
unsigned long nextBlink;
char amberswState = LOW;
char blueswState = LOW;
char ledState = LOW;
int CarsInPits = 0;
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
bool Green_State = 0;
int pos = 0; // variable to store the servo position
// setup the pins for outputs, blinking and open the serial port
void setup()
{
myservo.attach(A0); // attaches the servo on pin A0 to the servo object (change to suit your setup)
myservo.write(0); // tell servo to go to Zero position in degrees 0-90
pinMode(GREEN1, OUTPUT);
pinMode(RED1, OUTPUT);
pinMode(RED2, OUTPUT);
pinMode(RED3, OUTPUT);
pinMode(RED4, OUTPUT);
pinMode(RED5, OUTPUT);
pinMode(AMBER1, OUTPUT);
pinMode(AMBER2, OUTPUT);
pinMode(BLUE1, OUTPUT);
pinMode(ledPin, OUTPUT);
amberswState = LOW;
ledState = LOW;
nextBlink = millis();
Serial.begin(9600);
}
void blink (void)
{
unsigned long now;
now = millis();
if (now >= nextBlink)
{
nextBlink = now + 1000; // Next change in one second or edit value 1000 to prefered milliseconds
if (ledState == LOW) {digitalWrite(ledPin, HIGH); ledState = HIGH;} else {digitalWrite(ledPin, LOW); ledState = LOW;}
}
}
// look for data on the serial port and turn on/off the lights - data is ascii strings
void loop()
{
blink();
if (ledState == HIGH && amberswState == HIGH) {digitalWrite (AMBER1, HIGH); digitalWrite (AMBER2, HIGH);digitalWrite(GREEN1, LOW);}
else {digitalWrite (AMBER1, LOW); digitalWrite (AMBER2, LOW);} // GPK
if (ledState == LOW && amberswState == HIGH) {digitalWrite (AMBER1, LOW); digitalWrite (AMBER2, LOW);} // GPK
if (ledState == HIGH && blueswState == HIGH) {digitalWrite (BLUE1, HIGH);}
else {digitalWrite (BLUE1, LOW);}
if (ledState == LOW && blueswState == HIGH) {digitalWrite (BLUE1, LOW);}
if ( Serial.available() )
{
String b;
b = Serial.readStringUntil('[');
{
String s;
s = Serial.readStringUntil(']');
if ( s == "SL010" ) { digitalWrite(RED1, LOW); }
if ( s == "SL011" ) { digitalWrite(RED1, HIGH); }
if ( s == "SL020" ) { digitalWrite(RED2, LOW); }
if ( s == "SL021" ) { digitalWrite(RED2, HIGH); }
if ( s == "SL030" ) { digitalWrite(RED3, LOW); }
if ( s == "SL031" ) { digitalWrite(RED3, HIGH); }
if ( s == "SL040" ) { digitalWrite(RED4, LOW); }
if ( s == "SL041" ) { digitalWrite(RED4, HIGH); }
if ( s == "SL050" ) { digitalWrite(RED5, LOW); }
if ( s == "SL051" ) { digitalWrite(RED5, HIGH); digitalWrite(RED1, LOW);
digitalWrite(RED2, LOW); digitalWrite(RED3, LOW);
digitalWrite(RED4, LOW); digitalWrite(AMBER1, LOW); digitalWrite (AMBER2, LOW); // GPK
digitalWrite(GREEN1, LOW);}
if ( s == "SL060" ) { digitalWrite(GREEN1, LOW); }
if ( s == "SL061" ) { digitalWrite(GREEN1, HIGH); }
if ( s == "SL080" ) { digitalWrite(amberswPin, LOW); amberswState = LOW; digitalWrite(GREEN1, HIGH);}
if ( s == "SL081" ) { digitalWrite(amberswPin, HIGH); amberswState = HIGH;}
if ( s == "PT010" ) { CarsInPits-- ;} // A car just left the pits, minus one car from CarsInPits count
if ( s == "PT011" ) { CarsInPits++ ;} // A car just entered the pits, plus one car to CarsInPits count
if ( s == "PT020" ) { CarsInPits-- ;}
if ( s == "PT021" ) { CarsInPits++ ;}
if ( s == "PT030" ) { CarsInPits-- ;}
if ( s == "PT031" ) { CarsInPits++ ;}
if ( s == "PT040" ) { CarsInPits-- ;}
if ( s == "PT041" ) { CarsInPits++ ;}
if ( s == "PT050" ) { CarsInPits-- ;}
if ( s == "PT051" ) { CarsInPits++ ;}
if ( s == "PT060" ) { CarsInPits-- ;}
if ( s == "PT061" ) { CarsInPits++ ;}
if (CarsInPits <= 0 )
{ //if there are zero cars in the pit, turn off the blue lights
digitalWrite(blueswPin, LOW); blueswState = LOW;
}
else
{ // if there is one or more cars in the pit , keep the blue lights going
digitalWrite(blueswPin, HIGH); blueswState = HIGH;
}
if (CarsInPits < 0 || CarsInPits > 6) {CarsInPits = 0; } //if number of cars in pits gets messed up reset to zero [ '||' = 'or' ]
//Serial.println(CarsInPits); //debug
}
}
if (digitalRead(GREEN1) ){ //test if green is on and save
Green_State = 1 ;
}
if ((digitalRead(GREEN1)==0 ) && ( Green_State == 1 )){ //test if green is off but was on
if (amberswState == LOW){ //make sure we are not in a track call
Green_State = 0 ;
Wave_Flag (); ///wave the flag
}
}
} //end main loop
void Wave_Flag () {
for(int b=0; b<5; b ++){ //loop 5 times ( 5 x 500ms x 2 >>= 5000ms = 5 Seconds
myservo.write(180); // tell servo to go to position in degrees 0-180
delay(500); // give it time to get there
myservo.write(0); // tell servo to go to position in degrees 0-180
delay(500); // give it time to get there
}
}
//end
Tim