Go Down

### Topic: programming arduino uno (Read 2921 times)previous topic - next topic

#### dbutler0526

##### Aug 02, 2013, 07:19 pm
Can anyone send me an example of a sketch for a police bar with 2 red leds and 2 blue leds for a blinking pattern, but not a blink blink .....a nice alternating light bar blinking.    Send to dbutler0526@gmail.com

#### Arrch

#1
##### Aug 03, 2013, 05:03 amLast Edit: Aug 03, 2013, 03:12 pm by Arrch Reason: 1
Edit: Since it has been moved, my response no longer applies.

#### bigred1212

#2
##### Aug 03, 2013, 04:55 pmLast Edit: Aug 03, 2013, 05:00 pm by bigred1212 Reason: 1
Around here, I've noticed that the state trooper cars employ what is almost a random pattern for flashing their LED's - specifically intended to be unpredictable, catch your eye, and increase safety I'm sure.  I've thought that would be a fun programming exercise.

Here is a sketch that randomly blinks some of 4 LED's each cycle. Maybe you can use this as a base.

Code: [Select]
`int randNumber;void setup(){ // pick a seed for random numbers based on analog noise randomSeed(analogRead(0)); // initialize the LED output pins 2, 3, 4, and 5 for (int thisPin = 2; thisPin < 6; thisPin++)   { pinMode(thisPin, OUTPUT);       }}void loop(){ //walk through the pins for (int thisPin = 2; thisPin < 6; thisPin++) { //generate a random number- either 0 or 1 randNumber = random(0,2);     // if you multiply 0 or 1 by 255 you will get either 0 or 255 // for an analogWrite, 0 is off and 255 is on // write each pin with either a 0 or a 255 analogWrite(thisPin, randNumber * 255); } // let them be on for a half a second        delay(500); // turn them all off for (int thisPin = 2; thisPin < 6; thisPin++) { analogWrite(thisPin, 0); } // let them be off for a tiny bit                delay(200); // go do it again}`

You may want to mess with the timings of the delay to get it just like you want it.

Cheers.

#### 1ChicagoDave

#3
##### Aug 14, 2013, 05:37 pm
Something similar to this, maybe?

http://youtu.be/owYAtqxNjvE

I've since added more "variety" to the pattern, and made the code easy to set up any pattern you'd like.

Let me know.

#4
##### Aug 14, 2013, 07:18 pm
I've built this circuit up and used this code for someone before
http://nootropicdesign.com/projectlab/2010/01/08/arduino-police-lights/
I used 2 Red LEDs in series for one side, and 2 Blue LEDs in parallel for the other.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### 1ChicagoDave

#5
##### Aug 16, 2013, 08:17 pm

I've also made up a single RGB LED sketch on my DigiSpark (ATTiny) w/potentiometer speed control which I think looks pretty decent. The light it throws onto nearby walls makes it look like there's a cop car outside with lights running anyway.

http://youtu.be/DjI3KURfQx8

I've built this circuit up and used this code for someone before
http://nootropicdesign.com/projectlab/2010/01/08/arduino-police-lights/
I used 2 Red LEDs in series for one side, and 2 Blue LEDs in parallel for the other.

Nice work!
I really like the use of random-- gives a great effect. I worked up a quick "version" of your code on my 16 NeoPixel ring from Adafruit. I think I could probably pull someone over with it....if I were that kind of person.

Go Up

Please enter a valid email to subscribe