Created
June 11, 2020 08:28
-
-
Save dsijanov/0f61f6479e0454aad8d7237fee4ab8c0 to your computer and use it in GitHub Desktop.
Smart city lights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FadeLed.h> //It adds library for LED diode management. | |
FadeLed leds[5] = {3, 5, 6, 9, 10}; //It adds LED pins to the "leds" object. | |
unsigned long millisLast; //variable millisLast | |
int resPin = A1; //It defines photoresistor pin. | |
int resValue = 0; //A variable for storing the value of photoresistors. | |
int sensPin1 = 2; //It defines infrared sensor pins. | |
int sensPin2 = 4; | |
int sensPin3 = 7; | |
int sensPin4 = 8; | |
int sensPin5 = 12; | |
void setup() { //The initial set up for loop. | |
pinMode(sensPin1, INPUT); //It defines pins of infrared sensors as input. | |
pinMode(sensPin2, INPUT); | |
pinMode(sensPin3, INPUT); | |
pinMode(sensPin4, INPUT); | |
pinMode(sensPin5, INPUT); | |
leds[0].setTime(2000); //It sets the time to change the intensity of light | |
leds[1].setTime(2000); //from 0% to 100% for 2 seconds (relatively fast!). | |
leds[2].setTime(2000); | |
leds[3].setTime(2000); | |
leds[4].setTime(2000); | |
} | |
void prog1() { //The first loop program. | |
if (digitalRead(sensPin1) == LOW) { //It checks if the sensor is electromagnetically stimulated. | |
leds[0].set(100); //It gradually sets the LEDs intensity at 100%. | |
} else { //function "else" | |
leds[0].set(10); //It gradually sets the LEDs intensity at 10%. | |
} | |
} | |
void prog2() { //The second loop program. All loops are the same, but they are defining other sensors and LEDs. | |
if (digitalRead(sensPin2) == LOW) { | |
leds[1].set(100); | |
} else { | |
leds[1].set(10); | |
} | |
} | |
void prog3() { //The third loop. | |
if (digitalRead(sensPin3) == LOW) { | |
leds[2].set(100); | |
} else { | |
leds[2].set(10); | |
} | |
} | |
void prog4() { //The fourth loop. | |
if (digitalRead(sensPin4) == LOW) { | |
leds[3].set(100); | |
} else { | |
leds[3].set(10); | |
} | |
} | |
void prog5() { //The fifth loop. | |
if (digitalRead(sensPin5) == LOW) { | |
leds[4].set(100); | |
} else { | |
leds[4].set(10); | |
} | |
} | |
void loop() { //The main loop. | |
FadeLed::update(); //It refreshes the state of the LEDs. | |
resValue = analogRead(resPin); //It defines the variable as the value of the photoresistor. | |
if (resValue < 50) { //It checks whether it is day or night. | |
prog1(); //If detects the night, calls for other loops. | |
prog2(); | |
prog3(); | |
prog4(); | |
prog5(); | |
} else { //function "else" | |
leds[0].set(0); //If detects the daylight, the LEDs remain turned off. | |
leds[1].set(0); | |
leds[2].set(0); | |
leds[3].set(0); | |
leds[4].set(0); | |
} | |
} //that is it!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment