Go Down

Topic: simple sketch question (Read 660 times) previous topic - next topic

markthespark

Sep 22, 2012, 05:51 pm Last Edit: Sep 22, 2012, 09:23 pm by markthespark Reason: 1
hi all
i have this sketch but it aal runs as one sketch i would like for it to 3 different sketches in one
i would like led1 to blink constantly led2 to blink more slowly as led 3 but the problem i have is thet led 2 follows led 1 and led 3 follows led2 i would like them to blink seperatly can this be done and how i'm still a noob ?
the idea is for a halloween mouth
led1 blink eyes
led2 mouth open
led3 mouth close

cheers marko

sketch

Code: [Select]
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 9;
int led2 = 10;
int led3 = 11;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);               // wait for a second
  digitalWrite(led1, LOW);    // turn the LED off by making the voltage LOW
  delay(150);               // wait for a second
    digitalWrite(led2, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);               // wait for a second
  digitalWrite(led2, LOW);    // turn the LED off by making the voltage LOW
  delay(150);
    digitalWrite(led3, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);               // wait for a second
  digitalWrite(led3, LOW);    // turn the LED off by making the voltage LOW
  delay(500);
   
 
}

Jimmy60

It's probably a simple fix but without the sketch how can we know?

This is always a good place to start.

http://arduino.cc/forum/index.php/topic,97455.0.html


AWOL

Blink without delay is always a good starting point.
Understand it, and many things suddenly become doable.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

markthespark

#3
Sep 22, 2012, 08:45 pm Last Edit: Sep 22, 2012, 09:21 pm by markthespark Reason: 1
if i used this sketch how do i make each led have its own delay ?


Code: [Select]
/* Blink without Delay

Turns on and off a light emitting diode(LED) connected to a digital 
pin, without using the delay() function.  This means that other code
can run at the same time without being interrupted by the LED code.

The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.


created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen

This example code is in the public domain.


http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/

// constants won't change. Used here to
// set pin numbers:
const int ledPin1 =  10;      // the number of the LED pin
const int ledPin2 =  11;      // the number of the LED pin
const int ledPin3 =  12;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 100;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis( );

  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis; 

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin1, ledState);
    digitalWrite(ledPin2, ledState);
    digitalWrite(ledPin3, ledState);
  }
}

AWOL

You don't need to use delay.
Can you please start using code tags? My scrolling finger is hurting.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

markthespark

so how do i make 3 pins blink sepperate to each other like an eye blinking while mouth chatting ?

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up