Go Down

Topic: help adding 2 sketches together (Read 927 times) previous topic - next topic


hi all
i have 2 sketches and i want then both to run together one after the other but i'm new to arduino so need help and instructions on how to compile the 2 together if i add the second to the bottom of the other i get
redefinition of void setup so i know i'm doing something wron but dont know what

first sketch

//    FILE: lightning.pde
//  AUTHOR: Rob Tillaart
//    DATE: 2012-05-08
// PUPROSE: simulate lighning POC
#define BETWEEN 2579
#define DURATION 43
#define TIMES 7

#define LEDPIN 13

unsigned long lastTime = 0;
int waitTime = 0;

void setup()
  Serial.println("lightning 0.0");

  pinMode(LEDPIN, OUTPUT);

void loop()
  if (millis() - waitTime > lastTime)  // time for a new flash
    // adjust timing params
    lastTime += waitTime;
    waitTime = random(BETWEEN);

    for (int i=0; i< random(TIMES); i++)
      digitalWrite(LEDPIN, HIGH);
      delay(20 + random(DURATION));
      digitalWrite(LEDPIN, LOW);
  // do other stuff here

second sketch

  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 led = 9;

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

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


I would start like this.
Pick one sketch and make a copy of it, say called lightning2.
Then I would look at your other sketch and start adding the relevant parts.
Add all you variables and what the sketch actually does.

You do not need to add void setup()
or void loop(){
}, just the relevant parts inside.

Good luck.

Go Up