In: Computer Science
FOR ARDUINO PROGRAMMING;
WRITE CODE TO FIT THE BELOW REQUIREMENTS;
1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON
2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION
THANK YOU!
Please up vote ,comment if any query . Thanks for question . Be safe .
Note : check attached image for output ,code compiled and tested in Proteus VSM ,for code used in ARDUINO ide.
Program : led turn on and turn off at 30
int i=0;
int led=13; //led1 to PB5
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(led, OUTPUT); //set output to led 1 and led2
}
// the loop function runs over and over again forever
void loop() {
//if i==0 when program starts it value is
0
if(i==0)
{
//turn on led 1
digitalWrite(led, HIGH);
}
else if(i==30) //if its 30 seconds
{
digitalWrite(led, LOW);
// turn off led1
i=-1; //i=-1
}
++i; //increment i
delay(1000);
//delay of 1 second when i will 30 its 30 second led will turn off
for 1 second
}
Program : turn on led2 when its light off when dark
int led2=12; //led2 to PB4
int ldrPin = A0; // select the input pin for LDR
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(led2, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
int ldr = analogRead(ldrPin); // read the value from the
sensor
if(ldr>=700) //if its light
digitalWrite(led2, HIGH); //turn on led 2
else // its dark
digitalWrite(led2, LOW); //turn off led2
delay(1000);
//delay of 1 second
}
Simulation : when program run led1 is turn on
Simulation : when its 30 seconds
Simulation of LDR :
Please up vote ,comment if any query .