Sensor Toys

I had to use if statements to make the switch wires work, then I used switch statements for each of the interactions.

Code after the jump.

int ledPin = 5;
int speakerPin = 2;
int pin1 = 8;
int pin2 = 7;
int case1, case2;
int photoRead, photoSound, photoBright;
int potBright, potRead, potSound;
int photoMin = 50;
int photoMax = 250;

int inByte;

void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(pin1, INPUT);
pinMode(pin2, INPUT);
}

void loop() {
photoRead = analogRead(A0);
potRead = analogRead(A1);
photoSound = map(photoRead, photoMin, photoMax, 300, 3000);
potSound = map(potRead, 0, 1023, 300, 3000);

photoBright = map(photoRead, photoMin, photoMax, 0, 255 );
potBright = map(potRead, 0, 1023, 0, 255);

case1 = digitalRead(pin1); // assign the reading from pin 8 to case 1
case2 = digitalRead(pin2); // assign the reading from pin 7 to case 2

if(case1 == LOW && case2 == LOW) { // no pins are in
inByte = 0;
}
else if(case1 == HIGH && case2 == LOW) { // pin 8 is IN, pin 7 is OUT
inByte = 1;
}
else if (case1 == HIGH && case2 == HIGH) { // pin 8 is IN, pin 7 is IN
inByte = 2;
}
else if(case1 == LOW && case2 == HIGH) { // pin 8 is OUT, pin 7 is IN
inByte = 3;
}

switch(inByte) {
case 0:
Serial.println(inByte);
analogWrite(ledPin, photoBright);
tone(speakerPin, photoSound);
break;
case 1:
Serial.println(inByte);
analogWrite(ledPin, potBright);
tone(speakerPin, potSound);
break;
case 2:
Serial.println(inByte);
analogWrite(ledPin, 255);
delay(photoBright);
analogWrite(ledPin, 0);
delay(photoBright);
tone(speakerPin, potSound);
break;
case 3:
analogWrite(ledPin, 255);
delay(potBright);
analogWrite(ledPin, 0);
delay(potBright);
tone(speakerPin, photoSound);
Serial.println(photoSound);
break;

}
}