March 2019
Intermediate to advanced
312 pages
7h 37m
English
In this smart light program, we will first read input from the LDR sensor and, based on the input value, we will turn the LED on or off. The program for smart light is described as follows. You can download the SmartLight.cpp program from the Chapter02 folder of this book's GitHub repository:
#include <iostream>#include <wiringPi.h>int main(void){wiringPiSetup();pinMode(0,OUTPUT); pinMode(8,INPUT); for(;;){int ldrstate = digitalRead(8); if(ldrstate == HIGH) {digitalWrite(0,HIGH); }else{digitalWrite(0,LOW); } }return 0; }
The explanation of the preceding program is as follows: