int wedCurrentState = 0;
int rightSwitch = 2;//switch that controlls the direction of the servo
int wrongSwitch = 3;
int rightSwitchState = 0;//variable for the switch state
int wrongSwitchState = 0;//variable for the switch state
int servoPin1 = 4; // signal pin for servo motor
int servoPin2 = 5; // signal pin for servo motor
int minPulse =500; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // var for the pulse
int speed1 = 10;//sets the speed of the servo range 0 - 5
int speed2 = 10;//sets the speed of the servo range 0 - 5
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
int dcMotor = 6;
int firstMp3Play = 7;
int firstMp3Forward = 8;
int firstMp3PlayCounter = 0;
int secondMp3PlayCounter = 0;
int thirdMp3PlayCounter = 0;
int fourthMp3PlayCounter = 0;
int firstLayerLEDs = 9;
int secondLayerLEDs = 10;
int thirdLayerLEDs = 11;
//int loveLEDs = 12;
int resetSwitch = 13;
int resetSwitchState = 0;//variable for the switch state
int micDigital = 12; //analogue input
//int microPhone = 1; //analogue input
//int AmpVar = 0;
int micVal = 0;
//int THRESHOLD = 400;
int micCounter = 0;
void setup() {
pinMode(rightSwitch, INPUT);//initialize the switchPin as an INPUT
pinMode(wrongSwitch, INPUT);
pinMode(servoPin1, OUTPUT); // initialize the servo signal pin as an OUTPUT
pinMode(servoPin2, OUTPUT); // initialize the servo signal pin as an OUTPUT
pulse =maxPulse; // Set the motor position value to the minimum
pinMode(dcMotor, OUTPUT);
pinMode(firstMp3Play, OUTPUT);
pinMode(firstMp3Forward, OUTPUT);
pinMode(firstLayerLEDs, OUTPUT);
pinMode(secondLayerLEDs, OUTPUT);
pinMode(thirdLayerLEDs, OUTPUT);
//pinMode(loveLEDs, OUTPUT);
pinMode(micDigital, INPUT);
pinMode(resetSwitch, INPUT);
Serial.begin(9600);//initialize the serial
digitalWrite(firstMp3Play,HIGH);
delay (3000);
digitalWrite(firstMp3Play, LOW);
delay (500);
Serial.println("firstMp3Play was pressed onece - turn on");
}
void loop() {
wrongSwitchState = digitalRead(wrongSwitch);//read the state of the switch
switch (wrongSwitchState){
case 1:
firstMp3PlayCounter = firstMp3PlayCounter+1;
if (firstMp3PlayCounter == 1){
digitalWrite(firstMp3Play,HIGH);
delay (500);
digitalWrite(firstMp3Play, LOW);
delay (5000);
Serial.println("firstMp3Play was pressed twice - play");
digitalWrite(firstMp3Play,HIGH);
delay (500);
digitalWrite(firstMp3Play, LOW);
//digitalWrite(loveLEDs, HIGH);
//delay (1000);
//digitalWrite(loveLEDs, LOW);
Serial.println("firstMp3Play was pressed third - stop");
}
break;
case 0:
firstMp3PlayCounter = 0;
break;
}
rightSwitchState = digitalRead(rightSwitch);//read the state of the switch
switch (rightSwitchState){
case 1:
if(pulse>minPulse){
pulse--;
delay(speed1); // 0-5 slow to fast
}
break;
case 0:
if(pulse 0) {
micCounter = micCounter+1;
}
//micRead();
/*if (micVal>=512){
AmpVar = micVal-512;
}
else {
AmpVar = 512-micVal;
}
micValue = AmpVar; // read the analog input
//Serial.println(AmpVar);
//Serial.println(micVal);
if (AmpVar > THRESHOLD) {
micCounter = micCounter+1;
}
*/
if (micCounter == HIGH){
digitalWrite(dcMotor, LOW);
thirdMp3PlayCounter = thirdMp3PlayCounter+1;
if (thirdMp3PlayCounter == 1){
digitalWrite(firstMp3Forward,HIGH);
delay (500);
digitalWrite(firstMp3Forward, LOW);
delay (500);
Serial.println("firstMp3Forward was pressed onece - mic change");
}
//digitalWrite(loveLEDs, HIGH);
digitalWrite(firstLayerLEDs, LOW);
digitalWrite(secondLayerLEDs,LOW);
digitalWrite(thirdLayerLEDs, LOW);
delay(500);
//digitalWrite(loveLEDs, LOW);
digitalWrite(firstLayerLEDs, HIGH);
digitalWrite(secondLayerLEDs, HIGH);
digitalWrite(thirdLayerLEDs, HIGH);
delay(500);
}
resetSwitchState = digitalRead(resetSwitch);//read the state of the switch
switch (resetSwitchState){
case 1:
Serial.println("resetSwitch on");
micCounter = 0;
firstMp3PlayCounter = 0;
secondMp3PlayCounter = 0;
thirdMp3PlayCounter = 0;
digitalWrite(firstLayerLEDs, LOW);
digitalWrite(secondLayerLEDs,LOW);
digitalWrite(thirdLayerLEDs, LOW);
//digitalWrite(loveLEDs, LOW);
digitalWrite(dcMotor, LOW);
fourthMp3PlayCounter = fourthMp3PlayCounter+1;
if (fourthMp3PlayCounter == 1){
digitalWrite(firstMp3Forward,HIGH);
delay (500);
digitalWrite(firstMp3Forward, LOW);
delay (1000);
Serial.println("firstMp3Forward was pressed onece - change");
digitalWrite(firstMp3Play,HIGH);
delay (500);
digitalWrite(firstMp3Play, LOW);
delay (1000);
Serial.println("firstMp3Play was pressed onece - stop");
}
break;
case 0:
fourthMp3PlayCounter = 0;
break;
}
}
void movetheServo(){
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin1, HIGH); // Turn the motor on
digitalWrite(servoPin2, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin1, LOW); // Turn the motor off
digitalWrite(servoPin2, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}