Go Down

Topic: Multiple projects (Read 856 times) previous topic - next topic

asiuklis

Hello thhere. i am new here and i need some help. I want to control 7 leds and i have two projects which works well for me. All i want is to combine or run two projects so they can continiously loop. These are my two projects:

Code: [Select]


void setup() {
  unsigned int delayvar = 100;
 
  pinMode(13, OUTPUT);  //define pins as output
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(13, HIGH);  //blink twice
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  delay(delayvar);
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  delay(delayvar);
  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);
  delay(delayvar);
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  delay(delayvar);
   

}

void loop() {
  unsigned int strobespeed = 50;
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(7, HIGH);
  delay(strobespeed);
  digitalWrite(7, LOW);
  digitalWrite(10, HIGH);
  delay(strobespeed);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  delay(strobespeed);
  digitalWrite(11, LOW);
  digitalWrite(12, HIGH);
  delay(strobespeed);
  digitalWrite(12, LOW);
  digitalWrite(8, HIGH);
  delay(strobespeed);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  delay(strobespeed);
  digitalWrite(9, LOW);
  digitalWrite(13, HIGH);
  delay(strobespeed);
  digitalWrite(13, LOW);
  digitalWrite(9, HIGH);
  delay(strobespeed);
  digitalWrite(9, LOW);
  digitalWrite(8, HIGH);
  delay(strobespeed);
  digitalWrite(8, LOW);
  digitalWrite(12, HIGH);
  delay(strobespeed);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH);
  delay(strobespeed);
  digitalWrite(11, LOW);
  digitalWrite(10, HIGH);
  delay(strobespeed);
  digitalWrite(10, LOW);


}



Code: [Select]


// constants won't change. Used here to
// set pin numbers:
const int ledPin13 =  13;
const int ledPin12 =  12;
const int ledPin11 =  11;
const int ledPin10 =  10;
const int ledPin9 =  9;
const int ledPin8 =  8;
const int ledPin7 =  7; // 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 = 35;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin13, OUTPUT);
  pinMode(ledPin12, OUTPUT);
  pinMode(ledPin11, OUTPUT);
  pinMode(ledPin10, OUTPUT);
  pinMode(ledPin9, OUTPUT);
  pinMode(ledPin8, OUTPUT);
  pinMode(ledPin7, 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(ledPin13, ledState);
    digitalWrite(ledPin12, ledState);
    digitalWrite(ledPin11, ledState);
    digitalWrite(ledPin10, ledState);
    digitalWrite(ledPin9, ledState);
    digitalWrite(ledPin8, ledState);
    digitalWrite(ledPin7, ledState);
               
  }
}



Go Up