Go Down

Topic: putting 2 codes together? (Read 289 times) previous topic - next topic

Hello!
Me and my friend is new to the Arduino, and we are doing a project. We have made two separate codes, and now we want them to work together.
What tool can you use to make them work together?

1. code

nsigned long time, start, finished, elapsed;

void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT); // start button
  pinMode(3, INPUT); // stop button
  Serial.println("Press 1 for Start/reset, 2 for elapsed time");
}

void displayResult()
{
  float h,m,s,ms;
  unsigned long over;
  elapsed=finished-start;
  h=int(elapsed/3600000);
  over=elapsed%3600000;
  m=int(over/60000);
  over=over%60000;
  s=int(over/1000);
  ms=over%1000;
  Serial.print("Raw elapsed time: ");
  Serial.println(elapsed);
  Serial.print("Elapsed time: ");
  Serial.print(h,0);
  Serial.print("h ");
  Serial.print(m,0);
  Serial.print("m ");
  Serial.print(s,0);
  Serial.print("s ");
  Serial.print(ms,0);
  Serial.println("ms");
  Serial.println();
}

void loop()
{
start=millis();
time = millis();
    while (time < 100000){
    time = millis();
    delay(1000); // for debounce
    finished=millis();
    displayResult();
    }
}

2. code

int switchPin = 8;
int ledPin = 13;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{

if (digitalRead(switchPin) == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}
h
int switchPin = 8;
int ledPin = 13;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{

if (digitalRead(switchPin) == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}

Grumpy_Mike


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
 


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