Go Down

Topic: (LED Flash) Need help finding an alternating quadruple flash pattern (Read 377 times) previous topic - next topic

LightChaser

I have two LEDs I want to flash back and forth between each other. But I want each led do somthing like a quadruple flash. Like make it do a fast strobe for one second before switching to the other led it dose the same and switch back. The only part of the code I have is making it flash back and forth slowly, I need help making the strobe effect. Could help me out?

Code: [Select]
void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop(){
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  delay(500);
  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  delay(500);
}

Grumpy_Mike

That standard code uses the delay function. As long as you are satisfied to only do one thing at one time that is fine. If not the code needs to be way more complex.
This code will give a short blink on pin 13 and then a long one.

Code: [Select]

void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop(){
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  delay(100);
  digitalWrite(13, LOW);
  delay(100);
  digitalWrite(13, High);
  delay(500);
  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  delay(500);
}

LightChaser

Thank you for your help. I just started playing with the Ardunio for first time today. I tried your code but it told me there was an error with digitaWrite(13, High) took me while but it was the "High" needed be spelled out as HIGH. :)

I don't think the code you gave is going work for me with the type of pattern I wanting.

I was messing with it a few hours now and I found this code that seems to be working. Just want to know if I could make it shorter to save space. Right now I'm just testing, learning and playing with it. In the end, I hope to use this Arduino to make a whole bunch of LEDs flash on and off with many types of flash speeds and patterns.

Code: [Select]
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(55);
  digitalWrite(13, LOW);
  delay(55);
  digitalWrite(13, HIGH);
  delay(55);
  digitalWrite(13, LOW);
  delay(55);
  digitalWrite(13, HIGH);
  delay(55);
  digitalWrite(13, LOW);
  delay(150);
  digitalWrite(11, HIGH);
  delay(55);
  digitalWrite(11, LOW);
  delay(55);
  digitalWrite(11, HIGH);
  delay(55);
  digitalWrite(11, LOW);
  delay(55);
  digitalWrite(11, HIGH);
  delay(55);
  digitalWrite(11, LOW);
  delay(300);
  
}

codlink

//LiNK

Grumpy_Mike

Sorry about the spelling error, I was doing it on my iPad. You seem to have the idea. However there is a lot more you can do when you get going but it is more complicated. Look at using arrays to store your blinking pattern and the time between blinking and you can reduce almost any length of flash sequence to less than ten lines.

LightChaser

I've got seven codes typed up using 38% of the space of the Arduino. I bet I could make it more short could you please show me a small example of what you meant by " using arrays to store your blinking pattern"?

------------------
The only other problem I have is picking a way to power the Arduino and the LEDs, and finding way uses a push button to change between these patterns and how paste all these codes together for the button to work.

I know the Arduino needs 5volts and this light I'm making is being used in my car so I'll have a max of 14.5volts. Thinking just using car charger or a 5 volt voltage regulator.
I have a printed circuit board layout already made for the LEDs and it works for me.  It has three LEDs in series and twenty of them three/series in parallel with each other. Each set of LEDs has a 220 ohm 1/2watt resistor. I plan on making sixteen of these PCBs

Other info,
Power supply: Automotive 12.5~14.5v
Transistors being used between Arduino and LEDs PN2222A was using a IRF510 mosfet but guess it wouldn't work well with the Arduino
Single LED: Blue 5mm 3.4v 20mA
One PCB for LEDs series/parallel: 10.2 volt 400mA

Still need a resistor value picked that goes between the Arduino and Base of the transistors

dwightthinker


Jobi-Wan

Here is a different approach:


The flashing pattern of each LED is a function of time.




This plays that same pattern:
Code: [Select]
void loop()
{
  boolean flash;
  boolean ledOne;
 
  flash = (millis() % 250) < 50;      // Flash LED on in the first 50ms of each 250ms
  ledOne = (millis() % 2000) < 1000;  // LED1 on even seconds, LED2 on odd seconds.
 
  digitalWrite(ledOnePin,flash && ledOne);
  digitalWrite(ledTwoPin,flash && !ledOne); // not Led1, so Led2.
}


On each loop, it looks at the clock and decides whether any LED should be on and which one.



... and this light I'm making is being used in my car ...
^^ You should look into what is and isn't legal. Impersonating police is not.

Grumpy_Mike

This code will flash as many lights as you want in any order by only changing the numbers in the first two lines.

Code: [Select]
// Flashing lights demo by Grumpy Mike

#define inSequence 9
int timeDealy [] = { 400,200,100,800,200,1000,300,400,600 }; // time delay between change
byte pinToggle [] = { 9,5,8,10,9,5,8,10,9 };  // pin to change - matches up with above times

void setup() {
 for(int i =0; i<inSequence; i++){
  pinMode(pinToggle[i],OUTPUT); // set all the pins you will use to outputs
 }

}

void loop() {
static int nextLight = 0;
byte temp = digitalRead(pinToggle[nextLight]);
if( temp ) {
  digitalWrite(pinToggle[nextLight], LOW);
}
else {
  digitalWrite(pinToggle[nextLight], HIGH);
}
delay(timeDealy[nextLight]);
nextLight++;
if(nextLight >= inSequence) nextLight = 0;

}


The line
Code: [Select]
#define inSequence 9
Defines the number of steps in the sequence, this number must match the number of elements in the next two lines.
Code: [Select]
int timeDealy [] = { 400,200,100,800,200,1000,300,400,600 }; // time delay between change
Each number is the delay before the next change.
Code: [Select]
byte pinToggle [] = { 9,5,8,10,9,5,8,10,9 };  // pin to change - matches up with above times
These are the pins to toggle ( change from on to off or off to on ) on each change.

Have fun playing about with this.
When you have it under your belt ask again about changing the flashing pattern.

LightChaser

I've been messing with them two codes last five days now. I'm having a hard time getting it down. By the looks of it about same amount space being used as the codes I know how to do. I think I might stick with them, and just move on to the changing the flashing pattern stuff unless it will not work with the type of codes I'm using.

Here an example
Code: [Select]
void setup() {
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(10, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(150);
digitalWrite(12, HIGH);
delay(200);
digitalWrite(12, LOW);
delay(200);
digitalWrite(11, HIGH);
delay(200);
digitalWrite(11, LOW);
delay(200);
digitalWrite(10, HIGH);
delay(200);
digitalWrite(10, LOW);
delay(200);
}   





^^ You should look into what is and isn't legal. Impersonating police is not.
^I have a permit that allows me to display a blue light while responding to emergencies

Grumpy_Mike

The whole point is that you can increase the number of LEDs and complexity of the pattern with no more code, just by adding extra numbers into the arrays. There is no need to add any more code.

If you are having a hard time understanding any aspect of this then just ask.


The way you are doing it now is like the way that a five year old would speak. If you intend to grow up you have to change your view of code. If you don't intend to learn anything then why post here?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy