Having problems joining these three codes in to one.
Keeping getting changeLED not declared in scope error message. I am completely new to this, so I am using codes found on the internet that I have edited.
My Try at Joining
int led = 2;
int led1 = 3;
int led2 = 4;
int led3 = 5;
int led4 = 6;
int led5 = 7;
int led6 = 8;
long heartBeatArray[] = {
50, 100, 15, 1200 };
int hbeatIndex = 1; // this initialization is important or it starts on the "wrong foot"
long prevMillis;
byte ledPin[] = {2, 3, 4, 6, 7, 8}; // Create array for LED pins
int ledDelay = 65; // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() {
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
for (int x = 0; x < 10; x++) { // set all pins to output
pinMode(ledPin[x], OUTPUT);
}
changeTime = millis();
}
void loop() {
{
digitalWrite(led3, HIGH);// turn the LED on (HIGH is the voltage level // wait for a second
digitalWrite(led2, HIGH); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led4, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);
digitalWrite(led2, LOW);
digitalWrite(led4, LOW);// turn the LED on (HIGH is the voltage level // wait for a second
delay(500);
digitalWrite(led2, HIGH);
digitalWrite(led4, HIGH);// turn the LED on (HIGH is the voltage level // wait for a second
digitalWrite(led1, HIGH); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led5, HIGH);// turn the LED off by making the voltage LOW
delay(1000);
digitalWrite(led2, LOW);
digitalWrite(led4, LOW);// turn the LED on (HIGH is the voltage level // wait for a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led5, LOW);
delay(500);
digitalWrite(led2, HIGH);
digitalWrite(led4, HIGH);// turn the LED on (HIGH is the voltage level // wait for a second
digitalWrite(led1, HIGH); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led5, HIGH);
digitalWrite(led, HIGH); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led6, HIGH);// turn the LED on (HIGH is the voltage level)
delay(1000);
digitalWrite(led2, LOW);
digitalWrite(led4, LOW);// turn the LED on (HIGH is the voltage level // wait for a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led5, LOW);
digitalWrite(led, LOW); // turn the LED off by making the voltage LO // wait for a second
digitalWrite(led6, LOW);// turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
}
{
if ((millis() - changeTime) > ledDelay) { // if it has been ledDelay ms since last change
changeLED();
changeTime = millis();
}
}
void changeLED() {
for (int x = 0; x < 10; x++) { // turn off all LED's
digitalWrite(ledPin[x], LOW);
}
digitalWrite(ledPin[currentLED], HIGH); // turn on the current LED
currentLED += direction; // increment by the direction value
// change direction if we reach the end
if (currentLED == 7) {
direction = -1;
}
if (currentLED == 0) {
direction = 1;
}
}
{
heartBeat(1.5); // try changing the parameter
}
void heartBeat(float tempo) {
if ((millis() - prevMillis) > (long)(heartBeatArray[hbeatIndex] * tempo)) {
hbeatIndex++;
if (hbeatIndex > 3) hbeatIndex = 0;
if ((hbeatIndex % 2) == 0) {
digitalWrite(led3, HIGH);
delay((int)heartBeatArray[hbeatIndex]) ;
digitalWrite(led3, LOW);
}
hbeatIndex++;
// Serial.println(hbeatIndex);
prevMillis = millis();
}
}
}
Any help greatly appreciated, its for university project. Thanks