SlotForum banner
21 - 30 of 30 Posts

·
Registered
Joined
·
401 Posts
Discussion Starter · #22 ·
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
 

Attachments

·
Registered
Joined
·
2,773 Posts
Hey Tim,

Not sure about the code, but I have been thinking about doing a project like this myself. Mainly after I found one of my daughter's figures that should be perfect for this...

Doll Human body Toy Wood Electric blue


The arms move, so it will be easy to automate. Still have many projects to get to first though.

Heath
 

·
Registered
Joined
·
401 Posts
Discussion Starter · #26 ·
Just finished off part two of the project- to have yellow flag waving marshalls triggered by the yellow lag/safety car call in PCLC. Switched the chequered flag waver to the UNO’s 3.3 v supply and it is fine. This left the one remaining 5v supply to power 3 servos for the marshalls connected in parallel. I wasn’t sure if this would work but encouraged by Ade ( thanks yet again) I gave it a go and fortunately everything is fine. I’ve got one spare servo, so I’ll make up one more figure and see if 4 is ok.🤞
The marshalls again started out life as WW2 Airfix figures (German grenade throwers!) -then modified with Milliput and Isopon.
A couple of pictures and a short video- the only down side is the noise made by the servos ,but they’ll never be on for very long at any one time.


Toy Art Sculpture Action figure Fictional character
Automotive tire Fence Asphalt Road surface Font
 

·
Registered
Joined
·
401 Posts
Discussion Starter · #29 ·
Having now made and powered up,8 yellow flag wavers around the track- 3 from the 5v UNO output and the rest with the aid of an extra external 5v supply, I turned to the issue of better Safety Car warning lights. I really like the MAX 7219 8x8 led matrix modules. They are only 30mm x30mm and so great for 1:32 scale and look really good.
As adapting my existing start light sketch was going to be too complicated, I decided that a simple on/off push button for the safety car lights would be fine - the safety car itself is sent out round the track in a similar fashion.
Using some spare bits from some recent Magneticracing builds - plus the brushed metal tube of a garden solar light, I made some housings for the matrix modules.
The control is by an arduino UNO plus external 5v supply with an adaptation of a basic sketch I found online.
Having got the ‘bug’ I made an extra housing for a ‘Pit In‘ flashing sign - used the same adapted sketch this time with an Arduino NANO powered from the same 5v supply.
As ever all great fun and inexpensive!
Here are some pictures and another very short video


Audio equipment Electric blue Cable Pattern Gadget
Rectangle Wood Outdoor furniture Grass Road surface
Water Wood Land lot Natural landscape Grass
Hood Automotive tire Automotive lighting Bicycle tire Line
Automotive lighting Hood Automotive tire Grille Bumper
Car Road surface Asphalt Urban design Mode of transport

Tim
 

Attachments

21 - 30 of 30 Posts
Top