int sensorValue = 0;
//int potentiometer1 = 0;
bool checkArmed = false;
int checkDoor = digitalRead(13);
int firstNum = 0;
int secondNum = 0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int displaystate = 0;
int distanceThreshold = 0;
int cm = 0;
int inches = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, INPUT); //slideswitch
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
lcd.begin(16, 2); //LCD
pinMode(10, INPUT);
pinMode(9, INPUT);
pinMode(7,OUTPUT); // piezo
pinMode(A1, INPUT);
}
void loop()
{
//photoresistor();
//display();
//distance_sensor();
if(checkDoor == HIGH)
{
tone(7,440,5000);
}
Serial.print(checkArmed);
Serial.println(checkDoor);
}
/*
void photoresistor()
{
// read the value from the sensor
sensorValue = analogRead(A0);
// print the sensor reading so you know its range
//Serial.println(sensorValue);
// map the sensor reading to a range for the LED
analogWrite(9, map(sensorValue,0,1023,0,255));
if(sensorValue > 0 && sensorValue < 858)
{
digitalWrite(9,HIGH);
}
else
{
digitalWrite(9,LOW);
}
}
*/
/*
void potentiometer()
{
potentiometer1 = analogRead(A1);
// print the sensor reading so you know its range
Serial.println(potentiometer1);
// map the sensor reading to a range for the LED
analogWrite(9, map(potentiometer1,0,1023,0,255));
} */
/*
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
//I got this from tinkercad tutorial about ultrasonic distance sensor.
}
*/
void distance_sensor()
{
//Serial.print(digitalRead(13));
// set threshold distance to activate LEDs
//distanceThreshold = 100;
// measure the ping time in cm
//cm = 0.01723 * readUltrasonicDistance(7, 7);
// convert to inches by dividing by 2.54
//inches = (cm / 2.54);
//Serial.print(cm);
//Serial.print("cm, ");
//Serial.print(inches);
//Serial.println("in");
/*
if(cm >= distanceThreshold && cm < 200 && displaystate == 1)
{
//led blinks
Serial.println("if statement is running");
noTone(7);
//tone(7,440,5000);
delay(2000);
noTone(7);
}
else
{
//led turns on
//digitalWrite(A1, HIGH);
delay(1000);
}
delay(100);
*/
if(checkArmed == true && checkDoor == HIGH)
{
tone(7,440,5000);
}
}
void display()
{
firstNum= digitalRead(10);
secondNum = digitalRead(8);
//Serial.print(firstNum);
//Serial.println(secondNum);
checkArmed = true;
lcd.clear();
lcd.setCursor(0,1);
lcd.print("ARMED");
displaystate = 1;
delay(500);
/*
checkArmed = false;
lcd.clear();
lcd.setCursor(0,1);
lcd.print("UNARMED");
displaystate = 0;
delay(500);
*/
}
Sorry about earlier, here is the complete code, the only part I'm worried about is the loop(). I'm just trying to test the slide switch and Piezo buzzer to see if they work, but it doesn't even seem to work as intended.