Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Simple LED program...

Status
Not open for further replies.

Rescue1

Member
Hello all. I am loving the arduino as it has made my basic electronic tinkering a heck of a lot easier. It's much easier to have one board and and program rather than a bunch of gates and other IC chips to get a job done....

Anyway, I have had good luck with LED's(I know NoOb stuff) and flash patterns being controlled by a push button switch. What I want to do is have 3 LED's blink in a certain pattern upon receiving a HIGH on a Pin, flash the pattern, then stop,while the INPUT is HIGH then goes LOW. Then do it all over upon HIGH again.

Any ideas to put me in the right direction, thanks for the help, it's much appreciated..:)
 
Thank you, I will study up.. I guess the hardest part is making the program do one thing then stop till its told to do so again. So many of the programs have loops in them. Thanks again..:)
 
Thanks. Well it's simple what I want to do. When a HIGH is applied to a pin, I want 3 LEDs to flash in a quick pattern. Not sure what pattern yet, but for the purposes of this let's just say LED 1(blink) 2(blink) 3(blink) Then stop. During this the HIGH would not change it's state until the external circuit is turned offt. Hope I am explaining it well. This is just for a set of LEDs that I want to look cool when a device is powered on instead of simply have 1 LED stay steady on. Thanks again for the assistance.
 
Something like this...

Code:
// constants won't change. They're used here to 
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() 
 {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
 }

void loop()
 {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) 
   {     
    flash(1) ; 
    delay(300);
    flash(3) ;
    delay(300);
    flash(2) ; 
    delay(300);
   } 

 }

void flash(int pattern)
{
 int fl;
 for(fl = 0;fl<pattern;fl++)
   {
     	digitalWrite(ledPin, HIGH); 
     	delay(100);
     	digitalWrite(ledPin, LOW); 
     	delay(100);
   }
}

Using a flash routine allows multiple flashes
 
Thank you so much for the help, some of the code you placed in there intrigues me and I will study up on that more. The only problem is when the input stays HIGH then the LED will continue to blink. One cycle of blinking is all I want for initial power up, then stop. When the unit powers up again I would want the same pattern to take place. Any ideas? I'm sure I can come up with a hardware solution, however I wanted to see if it could be done all in the code. Thanks again, I love tinkering with this thing. Hopefully I will grab ahold of a better understanding soon thanks to your input..:)
 
So I ended up throwing an endless loop at the end of the LED blink code. I will simply have it also power off the entire circuit when the power supply is turned off, and when powered back up it will do its thing again.

do {} while (1>0);
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top