#include <Servo.h>
//#include <pcmRF.h>
#include <TMRpcm.h>
#include <SD.h> // need to include the SD library
#define SD_ChipSelectPin 10 // using digital pin 10 on arduino uno 328, can use other pins
#include <SPI.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
int mus = 1;
void setup() {
myservo.attach(3); // attaches the servo on pin 9 to the servo object
// put your setup code here, to run once:
TMRpcm tmrpcm;
tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin))
{
Serial.println("SD fail");
return;
}
tmrpcm.setVolume(6);
tmrpcm.play(mus + ".wav");
//set the switch input, pin 8, as an
//pinMode(8, INPUT);
//set both the LED pins, pin 5 and 6 as OUTPUTs
//pinMode (5, OUTPUT);
//pinMode (6, OUTPUT);
}
void loop() {
TMRpcm tmrpcm;
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(15);
digitalWrite(11, HIGH);
digitalWrite(12 LOW);
tmrpcm.setVolume(6);
tmrpcm.play(mus + ".wav");
// 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(15); // waits 15ms for the servo to reach the position
digitalWrite(11, HIGH);
digitalWrite(12, LOW);
tmrpcm.setVolume(6);
tmrpcm.play(mus + ".wav");
}
}