Hi Guys,
Im new to this programming lark and have been reading other tutorials on how to merge two sketches and i don't seem to be able to merge them without errors,
I'm trying to control two relays at the same time as operating a servo in a random way for both of them.
i have each sketch separately and they both work but I'm wanting to merge them so they both run together not one after the other.
can anyone help please,
see sketches below.
relay sketch:
void setup() {
// initialize the digital pins as an output.
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // Turns ON Relay on digital pin 4
delay(2000); // wait for 2 second
digitalWrite(13, LOW); // Turns OFF Relay on digital pin 4
delay(4000); // wait for 4 second
digitalWrite(13, HIGH); // Turns ON Relay on digital pin 4
delay(1000); // wait for 1 second
digitalWrite(13, LOW); // Turns OFF Relay on digital pin 4
delay(2000); // wait for 2 second
digitalWrite(12, HIGH); // Turns ON Relay on digital pin 5
delay(5000); // wait for 5 second
digitalWrite(12, LOW); // Turns OFF Relay on digital pin 5
delay(500); // wait for .5 second
digitalWrite(13, HIGH); // Turns ON Relay on digital pin 4
delay(2000); // wait for 2 second
digitalWrite(13, LOW); // Turns OFF Relay on digital pin 4
delay(4000); // wait for 4 second
digitalWrite(13, HIGH); // Turns ON Relay on digital pin 4
delay(3000); // wait for 3 second
digitalWrite(13, LOW); // Turns OFF Relay on digital pin 4
delay(6000); // wait for 6 second
digitalWrite(12, HIGH); // Turns ON Relay on digital pin 5
delay(5000); // wait for 5 second
digitalWrite(12, LOW); // Turns OFF Relay on digital pin 5
delay(500); // wait for .5 second
digitalWrite(12, HIGH); // Turns ON Relay on digital pin 4
delay(2000); // wait for 2 second
digitalWrite(12, LOW); // Turns OFF Relay on digital pin 4
delay(4000); // wait for 4 second
}
servo sketch:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 100; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(8); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(8); // waits 15ms for the servo to reach the position
}
for (pos = 80; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(40); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(0); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(9); // waits 15ms for the servo to reach the position
}
for (pos = 80; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(60); // waits 15ms for the servo to reach the position
}
}
thanks for the future help