LED 밝기 조절 - Laboratory of Intelligent Networks

Download Report

Transcript LED 밝기 조절 - Laboratory of Intelligent Networks

Ubiquitous Computing Practice
(Photo Resistor)
Youn-Hee Han, In-Seok Kang
{yhhan, Iseka}@kut.ac.kr
Laboratory of Intelligent Networks
Advanced Technology Research Center
Korea University of Technology
http://link.kut.ac.kr
Contents
Introduction
PhotoResistor
LED 밝기 조절
Processing를 이용한 Graph
2 / 24
Introduction
PhotoResistor (Cadmium sulfide or Light dependent resistor)

빛의 세기에 따라 저항 값이 변하는 센서이다
3 / 24
Introduction
4 / 24
Introduction
http://www.ladyada.net/learn/sensors/cds.html
5 / 24
Introduction
6 / 24
Introduction
7 / 24
PHOTO RESISTOR
8 / 24
Photo resistor
9 / 24
schematic
10 / 24
Result
11 / 24
Reference
Functions


analogRead(pin) – analog pin 에서 int (0~1023) 반환
analogWrite(pin, val) – val(0~255) 값 출력
Serial

begin(baud) – bits per second
 ex)9600, 19200..

print(val) – 시리얼 통신 이용 val 출력
 Serial.print(78) gives "78"

print(val, format) – val 을 원하는 format에 맞춰 출력
 Serial.print(78, BIN) gives "1001110"
12 / 24
Reference
Math

map(value, fromLow, fromHigh, toLow, toHigh)
 Value 현재 값의 범위 fromLow ~ fromHigh
 변경하고 싶은 값의 범위 toLow, toHigh
 ex) int val = analogRead(0);
val = map(val, 0, 1023, 0, 255);

constrain(inputVal, lowRange, highRange)
 inputVal 값이 lowRange ~ highRange 사이의 값이면 inputVal 반환
 inputVal 값이 lowRange 값 보다 작으면 lowRange 값 반환
 inputVal 값이 highRange 값 보다 크면 highRange 값 반환
13 / 24
센서의 analog값 출력 Sketch
int photocellPin = 0;
int photocellReading;
void setup(void) {
Serial.begin(9600); // bit per second.
}
void loop(void) {
photocellReading = analogRead(photocellPin);
Serial.print("Analog reading = ");
Serial.println(photocellReading);
delay(1000);
}
14 / 24
LED 밝기 조절
15 / 24
LED 밝기 조절
16 / 24
schematic
17 / 24
LED 밝기 조절 Sketch
int lightPin = 0;
int ledPin = 11;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int lightLevel = analogRead(lightPin);
lightLevel = 1023 – lightLevel;
lightLevel = map(lightLevel, 0, 1023, 0, 255);
lightLevel = constrain(lightLevel, 0, 255);
analogWrite(ledPin, lightLevel);
}
18 / 24
Processing 을 이용하여 Graph를 출력하기
PROCESSING를 이용한 GRAPH
19 / 24
Arduino board
20 / 24
Arduino - Sketch
int lightPin = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println(analogRead(lightPin));
delay(100);
}
21 / 24
Processing - Sketch
import processing.serial.*;
Serial myPort;
int xPos = 1;
// The serial port
// horizontal position of the graph
void setup () {
size(400, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}
22 / 24
Processing - Sketch
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
}
}
if (xPos >= width) {
xPos = 0;
background(0);
} else {
xPos++;
}
23 / 24
Result
24 / 24