반응형
불을 끄면 CDS값이 50이하로 떨어지고 LCD화면에 plz turn on을 출력합니다.
다시 불을 켜면 cds값은 올라가게 되고 LCD화면에 plz turn off를 출력합니다.
한줄만 지우는 방법을 못찾아서 약간 깜박입니다.
소스코드
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- int cdsPIN = 0;
- int ledPIN = 6;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- lcd.begin(16,2);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int value = analogRead(cdsPIN);
- if ( value < 50 )
- {
- lcd.setCursor(0,0);
- lcd.print( " ");
- lcd.setCursor(0,0);
- lcd.print( "plz turn on" );
- }
- else
- {
- lcd.setCursor(0,0);
- lcd.print( " ");
- lcd.setCursor(0,0);
- lcd.print( "plz turn off" );
- }
- //cds값 출력
- lcd.setCursor(0,1);
- lcd.print( "000" );
- lcd.setCursor(0,1);
- lcd.print( value );
- delay(10);
- }
참고
http://arduino.cc/en/Tutorial/LiquidCrystalSerial
http://playground.arduino.cc/Learning/PhotoResistor
반응형