#include <Servo.h> //includes the servo library
/*create servo object*/
Servo myServo; //creates the servo object
/*define pins for the componente*/
const int bluLedPin = 5; //RED LED TO PIN 5
const int grnLedPin = 6; //BLUE LED TO PIN 6
const int offSlideSwitchPin = 4; //off is pin 4
const int onSlideSwitchPin = 2; //on is pin 2
const int buzzerPin = 12; //buzzer pin 12
const int LDRpin = A0;
/*define variables*/
int pos; //starting position of the servo
int bluLedState; //variable for the state of blu led
int grnLedState; //variable for the state of grn led
int slideSwitchState;
int onSlideSwitchState;
int offSlideSwitchState;
int Lux = 0; //variable to store Lux value
int luxThreshold = 7; //threshold for the lux value
unsigned long currentMillis = 0; //variable to store current time
unsigned long previousMillis = 0; //variable to store previous time
unsigned long elapsedTime = 0; //variable to store elapsed time
const unsigned long period = 1000; //variable to store the period to check periods of time
void setup(){
Serial.begin(9600); //begin the serial monitor
pinMode(bluLedPin, OUTPUT); //SETS PIN 5 AS OUTPUT
pinMode(grnLedPin, OUTPUT); //SETS PIN 6 AS AN OUTPUT
pinMode(onSlideSwitchPin, INPUT); //SETS PIN 2 AS AN INPUT
pinMode(offSlideSwitchPin, INPUT); //SETS PIN 4 AS AN INPUT
pinMode(LDRpin, INPUT); //SETS PIN a0 AS AN INPUT
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
digitalWrite(bluLedPin, LOW); //TURNS blue LED off
digitalWrite(grnLedPin, HIGH); //TURNS green led ON
digitalWrite(offSlideSwitchPin, HIGH); //off switch is on or high (system is off)
digitalWrite(onSlideSwitchPin, LOW); //on switch is off or low (system is off)
}
void loop(){
millis();
bluLedState = digitalRead(bluLedPin); //reads the current state of the blue led ie on or off
grnLedState = digitalRead(grnLedPin); //reads the current state of the redled ie on or off
onSlideSwitchState = digitalRead(onSlideSwitchPin); //reads the current state of the on switch ie on or off
offSlideSwitchState = digitalRead(offSlideSwitchPin); //reads the current state of the off switch ie on or off
currentMillis = millis();
/*turns on or off the led depending on switch position on/off*/
if (onSlideSwitchState == HIGH) {digitalWrite(grnLedPin, HIGH);}
else {digitalWrite(grnLedPin, LOW);}
if (offSlideSwitchState == HIGH) {digitalWrite(bluLedPin, HIGH);}
else {digitalWrite(bluLedPin, LOW);}
currentMillis = previousMillis;
if (currentMillis - previousMillis <= period) {digitalRead(onSlideSwitchPin);}
if (onSlideSwitchState == LOW) {digitalWrite(bluLedPin, HIGH);}
else {digitalWrite(bluLedPin, LOW);}
/*end "turns on or off" the led depending on switch position on/off*/
if (currentMillis - previousMillis <= period){analogRead(LDRpin);
Lux = analogRead(LDRpin);
Serial.println(Lux);
digitalRead(grnLedPin);
if ((Lux << luxThreshold) && (grnLedPin == HIGH)){digitalWrite(grnLblinkGrnLed()
else {digitalWrite(bluLedPin, HIGH);
delay(500);
digitalWrite(bluLedPin, LOW);
delay(500);}
if (Lux >> luxThreshold) {digitalWrite(bluLedPin, HIGH);
delay(500);
digitalWrite(bluLedPin, LOW);
delay(500);}
/*else {digitalWrite(grnLedPin,HIGH);
delay(500);
digitalWrite(grnLedPin, LOW);
delay(500);}*/
}
}
void blinkGrnLed(){
digitalWrite(grnLed, HIGH);
delay(500);
digitalWrite(grnLed, LOW);
delay(500);
}
/*
if ((Lux <= luxThreshold) && (grnLedState == HIGH)) {
digitalWrite(buzzerPin, LOW);}
if ((Lux <= luxThreshold) && (grnLedState == HIGH)) {
digitalWrite(buzzerPin, HIGH);
}*/
/*currentMillis = millis();
elapsedTime = currentMillis - previousMillis;
//if (elapsedTime < 30000) {digitalWrite(buzzerPin, HIGH);}
//else {digitalWrite(buzzerPin, LOW);}
previousMillis = currentMillis;
}*/
/*{for (pos = 90; pos <= 180; pos += 1) { // goes from 0 degrees to 90 degrees in steps of 1 degree
myServo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);} // waits 15ms for the servo to reach the position
for (pos = 180; pos >= 90; pos -= 1) { // goes from 90 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
for (pos = 0; pos == 0; pos == 0){
myServo.write(90);
delay(15);
}*/