I'm trying to combine the following sketches:
int outPin = 1; // output on digital pin 1
void setup() {
pinMode(outPin, OUTPUT);
Serial.begin(38400);
}
void loop()
{
Serial.write('t'); // lowercase "t" must be in single quotes…
Serial.write(001); // followed by the track number without quotes
delay(10000);
Serial.write('t');
Serial.write(002);
delay(9000);
Serial.write('t');
Serial.write(006);
delay(15000);
Serial.write('t');
Serial.write(003);
delay(5000);
Serial.write('t');
Serial.write(004);
delay(10000);
Serial.write('t');
Serial.write(005);
delay(9000);
Serial.write('t');
Serial.write(006);
delay(8000);
Serial.write('t');
Serial.write(007);
delay(6000);
Serial.write('t');
Serial.write(8);
delay(9000);
Serial.write('t');
Serial.write(9);
delay(6000);
Serial.write('t');
Serial.write(010);
delay(11000);
Serial.write('t');
Serial.write(18);
delay(15000);
Serial.write('t');
Serial.write(011);
delay(10000);
Serial.write('t');
Serial.write(012);
delay(12000);
Serial.write('t');
Serial.write(013);
delay(8000);
Serial.write('t');
Serial.write(014);
delay(9000);
Serial.write('t');
Serial.write(015);
delay(11000);
Serial.write('t');
Serial.write(016);
delay(7000);
Serial.write('t');
Serial.write(017);
delay(6000);
Serial.write('t');
Serial.write(18);
delay(10000);
Serial.write('t');
Serial.write(006);
delay(12000);
Serial.write('t');
Serial.write(19);
delay(9000);
Serial.write('t');
Serial.write(18);
delay(30000);
}
void setup() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
}
void loop(){
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(200);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(200);
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Left
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(200);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(10000); //Pause
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Left
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(4000);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(8000);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(1000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(12, LOW); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Left
delay(2000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(2000);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(1000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(20000);
}
I'm using a sparkfun mp3 trigger for the first code and the official motor control shield for the second. I've followed a tutorial and got this so far:
void setup(){
setupMotor();
setupSound();
}
void loop(){
loopMotor();
loopSound();
}
void setupMotor() {
//Setup Channel A
pinMode(12, OUTPUT); //Initiates Motor Channel A pin
pinMode(9, OUTPUT); //Initiates Brake Channel A pin
}
void loopMotor(){
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(200);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(200);
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Left
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(200);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(10000); //Pause
digitalWrite(12, LOW); //Establishes backward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Left
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(4000);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(400);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(8000);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(1000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
digitalWrite(12, LOW); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Left
delay(2000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(2000);
digitalWrite(12, HIGH); //Establishes forward direction of Channel A
digitalWrite(9, LOW); //Disengage the Brake for Channel A
analogWrite(3, 255); //Spins Right
delay(1000);
digitalWrite(9, HIGH); //Engage the Brake for Channel A
delay(20000);
}
int outPin = 1; // output on digital pin 1
void setupSound() {
pinMode(outPin, OUTPUT);
Serial.begin(38400);
}
void loopSound()
{
Serial.write('t'); // lowercase "t" must be in single quotes…
Serial.write(001); // followed by the track number without quotes
delay(10000);
Serial.write('t');
Serial.write(002);
delay(8000);
Serial.write('t');
Serial.write(003);
delay(5000);
Serial.write('t');
Serial.write(004);
delay(10000);
Serial.write('t');
Serial.write(005);
delay(9000);
Serial.write('t');
Serial.write(006);
delay(8000);
Serial.write('t');
Serial.write(007);
delay(6000);
Serial.write('t');
Serial.write(8);
delay(7000);
Serial.write('t');
Serial.write(9);
delay(6000);
Serial.write('t');
Serial.write(010);
delay(11000);
Serial.write('t');
Serial.write(011);
delay(10000);
Serial.write('t');
Serial.write(012);
delay(12000);
Serial.write('t');
Serial.write(013);
delay(5000);
Serial.write('t');
Serial.write(014);
delay(4000);
Serial.write('t');
Serial.write(015);
delay(7000);
Serial.write('t');
Serial.write(016);
delay(4000);
Serial.write('t');
Serial.write(017);
delay(6000);
Serial.write('t');
Serial.write(18);
delay(10000);
Serial.write('t');
Serial.write(19);
delay(6000);
Serial.write('t');
Serial.write(005);
delay(6000);
Serial.write('t');
Serial.write(021);
delay(6000);
Serial.write('t');
Serial.write(022);
delay(6000);
Serial.write('t');
Serial.write(023);
delay(5000);
Serial.write('t');
Serial.write(024);
delay(6000);
Serial.write('t');
Serial.write(025);
delay(30000);
}
However I can't seem to get them both running at the same time. Please help!