Pages: [1]   Go Down
Author Topic: programming arduino uno  (Read 2125 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 131
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Edit: Since it has been moved, my response no longer applies.
« Last Edit: August 03, 2013, 08:12:55 am by Arrch » Logged

Sitting in the garage.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 451
I made the pretty light blink.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
« Last Edit: August 03, 2013, 10:00:59 am by bigred1212 » Logged

Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 439
Posts: 23758
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Chicago
Offline Offline
Sr. Member
****
Karma: 5
Posts: 456
With every answer comes more questions.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.   smiley-mr-green
Logged

Pages: [1]   Go Up
Jump to: