// FORGET ME NOT
// Squeeze button, if all analogue sensors are above a certain range, activate the vibrator
// If an analogue sensor is below a certain value, light up the corresponding LED for it.
//INPUT PINs
int sensorPin1 = 1; // First analog sensor PIN
int sensorPin2 = 2; // Second analog sensor PIN
//OUTPUT PINs
int switchPin = 5; // Switch PIN
int LedPin1 = 4; // First LED PIN
int LedPin2 = 3; // Second LED PIN
int vibPin = 2; // Vibrator PIN
int valueSensor1 = 0; //Value from Sensor 1
int valueSensor2 = 0; //Value from Sensor 2
int valueSwitch = LOW; //Value from Switch
void setup()
{
// initialize serial communications at 9600 bps:
Serial.begin(9600);
//Set pin modes
pinMode(sensorPin1, INPUT);
pinMode(sensorPin2, INPUT);
pinMode(switchPin, OUTPUT);
pinMode(LedPin1, OUTPUT);
pinMode(LedPin2, OUTPUT);
pinMode(vibPin, OUTPUT);
//Make sure LEDs and Vibrator are off
digitalWrite(LedPin1, LOW);
digitalWrite(LedPin2, LOW);
digitalWrite(vibPin, LOW);
}
void loop()
{
//Read sensors
valueSensor1 = analogRead(sensorPin1); //Variable Potentiometers go from 0 to 1023
valueSensor2 = analogRead(sensorPin2);
valueSwitch = digitalRead(switchPin); //See if Switch is pressed or not
//If Switch is pressed, then go into program
if (valueSwitch == HIGH){
findObjects();
}
else { //Turn LEDs and Vibrator off
digitalWrite(LedPin1, LOW);
digitalWrite(LedPin2, LOW);
digitalWrite(vibPin, LOW);
}
}
void findObjects()
{
//Check to see if any object is missing, if so - blink its light
//Check Sensor 1
if (valueSensor1 < 500){
digitalWrite(LedPin1, HIGH);
delay(300);
digitalWrite(LedPin1, LOW);
delay(300);
}
//Check Sensor 2
if (valueSensor2 < 500){
digitalWrite(LedPin2, HIGH);
delay(300);
digitalWrite(LedPin2, LOW);
delay(300);
}
//Check both sensor for vibrator
if (valueSensor1 > 500 && valueSensor2 > 500) { //if all are present - vibrate
digitalWrite(vibPin , HIGH);
}
}