# Lab9 Photoresistor with LCD display
## Members:
411085031 劉又瑄
410985004 陳文彥
411085020 林漢昕
## Principle:
Use photoresistor to detect lightness of enviroment, and store it's digits into an array whitch will be show on LCD screen.
## Program:
```c=
////////////////////////////////16X2LCM 設定////////////////////////////////////////////////////////
#include <LiquidCrystal.h> // 包含LiquidCrystal.h標頭檔
/*====================LCD腳位宣告====================*/
LiquidCrystal LCD(20, 19, 18, 14, 15, 16, 17); // 建構LiquidCrystal物件
// RS, RW, EN, D4,D5,D6,D7
/*====================LCD腳位宣告====================*/
////////////////////////////////16X2LCM 設定//////////////////////////////////////////////////
//////////////////光敏電阻///////////////////////////
const int Photoresistance = A0; // 宣告光敏電阻腳位
int LDR; // 宣告變數
int LDR1, LDR2, LDR3, LDR4;
int LDRD[4] = {0, 0, 0, 0};
//////////////////光敏電阻////////////////////////////
void setup()
{
Serial.begin(115200); // 啟動串列埠,並設定採115200鮑率
pinMode(Photoresistance, INPUT); // 設定PIN腳為輸入端
/////////// 啟用16_2 LCM/////////
LCD.begin(16, 2);
for (int i = 14; i <= 20; i++)
pinMode(i, OUTPUT);
LCD.setCursor(0, 0); /////先設定Cursor在上行最左邊位置
/////////// 啟用16_2 LCM/////////
}
void loop()
{
////////////////////光敏電阻/////////
LDR = analogRead(Photoresistance);
// 讀取括號中Photoresistance的類比訊號值
Serial.println(LDR); // 顯示光敏電阻值
LDRD[3] = LDR / 1000;
LDRD[2] = (LDR % 1000) / 100;
LDRD[1] = (LDR % 100) / 10;
LDRD[0] = LDR % 10;
delay(50); // 延遲0.5秒 delay(1);等於1ms
LCD.setCursor(0, 1);
LCD.print(LDR);
}
```
## Description
### setup()
Setup input and output pin.
### loop()
For every turn of loop, we check the value of photoresistance, turn it into single digits to show in LCD.
## Result
[影片連結](https://drive.google.com/file/d/1EFJzMKbw_IupuM0FbpYtCuYpmWgO8m1k/view?usp=drive_link)