Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Flasher for my 1950s emergency vehicle roof revolving beacons

1309 views
7 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, January 24, 2019 1:08 PM

 This is sort of what I do for my servo controller, so it can be pollign the buttons for one servo while it is noving the other. Primitive multitaskign but it works.

 The code I based mine one comes from searching for something like "arduino more than one thing at a time". There's a library someone wrote that wraps up the whole method of using millis. There's also a newer version than the one I used but when I checked it out there was some reason I didn;t use it - it did more than the one I used, but I didn;t need those added features, but it also did something differently that needed more function calls or something to work. I'd post a link to where I first found it, it started out as a discussion on using millis() and had an example that moved a servo and had a button toggle an LED and it all ran at the same time, but it's a 7 page thread that for a while degenerated into a bunch of so-called programming experts callign each other names over the used of break() in a case statement - to listen to some of them you'd think someone suggested using a goto! Anyway, a while back I did post my code for the servo controller, and you can see the library and the calls to it in there. In the background it is effectively doing the millis() calculations, but you don't really have to know that. It's the Metro library (I guess from Metronome, since Arduinos were targeted at artists). You declare a Metro object for each task, with a parameter of how many milliseconds you want:

 Metro hbMetro = Metro(750);

and then within the loop() function you just test it

 if (hbMetro.check() == 1) {

   hbstate = ! hbstate;

   digitalWrite(HBLED, hbstate);

}

and you have an LED that blicks on and off a 750ms intervals. If 750ms has not yet elapeds, the if test simple falls through and you cna have a test of another Metro object, or do something else.

It's primitive multitasking - because if you do somethign that takes longer than the interval you are testing for, it will miss - it's cooperative multitasking, like Windows prior to Windows 2000. If, for example my next line after the if block in that example was delay(1000) the LED would flash very irregularly.

                                            --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Thursday, January 24, 2019 12:44 PM

That wasn’t my doing, I found the millis thing on the Arduino Forum.
 
 
Mel
 
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 
  • Member since
    January 2010
  • 170 posts
Posted by nycmodel on Thursday, January 24, 2019 12:00 PM

It certainly has come in handy for me, Mel. I am looking for a way to dump serial data from an Arduino to a Visual Basic serial input so I can graphically display block status, etc. I was afraid that using Serial.println at the end of each loop would overload the VB serial buffer. However, using a delay statement to prevent this would stop the program execution.  Your millis() based approach should take care of that.

  • Member since
    July 2007
  • From: Yorkton, Sk, Cnd
  • 441 posts
Posted by wvg_ca on Thursday, January 17, 2019 8:49 PM

looks pretty good ..

will come in handy for some people

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Wednesday, January 16, 2019 8:57 PM

I used 1500 milliseconds as base timing and split it into 350 milliseconds on and 950 milliseconds off.  Figuring a rotating beacon revolves between 50 to 80 RPM with a dual flash.  By tweaking the times a bit no two bulbs flash at the same rate causing a random pattern.  Over several minutes the various bulbs will sync momentarily then drift apart.   
 
 
 
Mel
 
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 
  • Member since
    December 2015
  • From: Shenandoah Valley
  • 9,094 posts
Posted by BigDaddy on Wednesday, January 16, 2019 8:06 PM

I'm lost too and think you are a wizard, but it looks like it starts off with a repetitive pattern.  By the end of the video it changes

Henry

COB Potomac & Northern

Shenandoah Valley

  • Member since
    May 2010
  • From: SE. WI.
  • 8,253 posts
Posted by mbinsewi on Wednesday, January 16, 2019 7:55 PM

Cool Mel!  Only you could come up with this.  I watch the short video of the flashers, and seen the picture, but everything beyond that, which must be your "sketch", was so far over my head, it got lost in the stars!  Confused

I can't wait until I see your emergency vehicles flashing.

Mike.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Flasher for my 1950s emergency vehicle roof revolving beacons
Posted by RR_Mel on Wednesday, January 16, 2019 7:40 PM

I have a half dozen vehicles on my layout with roof mounted emergency beacons.  As I model the 1950s I built a few transistor flasher circuits to make them look like they are rotating beacons.  I control them from my control panel labeled Police, Fire & Road Maintenance.  I always wanted a better looking flasher circuit but didn’t act on it until recently.
 
I decided to give an Arduino a shot to drive all of the beacons.  The problem with using an Arduino is they don’t multitask and one of the most important things about my layout lighting is realism.  I like to get it to as close to the real thing as I can.
 
I set out to come up with a flasher that would flash multiple emergency lights so that the aren’t synced.  I had seen articles on the Internet about using Millis instead of delay with an Arduino allowing it to run more than one device at a time with out delays.  It took many attempts but I finally got it working.  It will flash 7 LEDs without a driver but because I use incandescent Grain of Rice 1mm 1½ volt bulbs that draw more current than the Arduino will handle I made a seven channel high current driver expansion board.  The video on my blog is a UNO that I use for testing but I’m going to use a Arduino Nano for my flasher with a single TD62304AP seven channel driver chip.
 
 I did a post on my blog on the flasher with a video and the Sketch.
 
 
 
Mel
 
 
My Model Railroad   
 
Bakersfield, California
 
I'm beginning to realize that aging is not for wimps.
 

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!