오늘은 조도 값(밝기 값)에 따라 도트 매트릭스가 밝아지는 프로그램을 만들어 보겠습니다.
(아이폰의 자동 밝기 설정을 생각하면 이해가 쉽습니다.)
회로
먼저 도트매트릭스 회로 먼저 소개합니다.

220옴의 저항을 사용합니다.
다음은 조도 센서의 회로도입니다.

코드
#define LIGHT_PIN A1
/*
* 도트매트릭스와 조도를 이용한 밝기조절 프로그램
*/
int pins[17] = { -1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, A2, A3, A4, A5};
int cols[8] = { pins[13], pins[3], pins[4], pins[10], pins[6], pins[11], pins[15], pins[16]};
int rows[8] = { pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};
void setup()
{
Serial.begin(9600);
pinMode(LIGHT_PIN, INPUT);
for (int idx = 1; idx <= 16; idx++)
pinMode(pins[idx], OUTPUT);
allOff();
}
void loop()
{
int lux = analogRead(LIGHT_PIN);
Serial.println(lux);
if (lux < 400) {
Row(8);
}
else if (lux > 400 && lux < 500) {
Row(6);
}
else if (lux > 501 && lux < 600) {
Row(4);
}
else if (lux > 601) {
Row(2);
}
}
void allOn() {
for (int idx = 0; idx < 8; idx++) {
digitalWrite(rows[idx], !LOW); //- ROWs ON
digitalWrite(cols[idx], !HIGH); //- COLUMNs ON
}
}
void Row(int high) {
for (int i = 0; i < high; i++) {
for (int j = 0; j < 8; j++) {
dot(i, j);
}
}
}
void allOff()
{ for (int idx = 0; idx < 8; idx++) {
digitalWrite(rows[idx], LOW); //- ROWs OFF
digitalWrite(cols[idx], HIGH); //- COLUMNs OFF
}
}
void dot(int rowIdx, int colIdx)
{
for (int idx = 0; idx < 8; idx++) {
(rowIdx == idx) ? digitalWrite(rows[idx], !LOW) :
digitalWrite(rows[idx], LOW);
(colIdx == idx) ? digitalWrite(cols[idx], !HIGH) :
digitalWrite(cols[idx], HIGH);
}
}
'IoT > 아두이노' 카테고리의 다른 글
[아두이노] 4digit-7세그먼트, 써미스터 (4) | 2022.07.07 |
---|---|
[아두이노] DC모터, 조이스틱 (7) | 2022.06.08 |
[아두이노] RGB LED, 가변저항, 스위치 (0) | 2022.06.07 |
오늘은 조도 값(밝기 값)에 따라 도트 매트릭스가 밝아지는 프로그램을 만들어 보겠습니다.
(아이폰의 자동 밝기 설정을 생각하면 이해가 쉽습니다.)
회로
먼저 도트매트릭스 회로 먼저 소개합니다.

220옴의 저항을 사용합니다.
다음은 조도 센서의 회로도입니다.

코드
#define LIGHT_PIN A1
/*
* 도트매트릭스와 조도를 이용한 밝기조절 프로그램
*/
int pins[17] = { -1, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, A2, A3, A4, A5};
int cols[8] = { pins[13], pins[3], pins[4], pins[10], pins[6], pins[11], pins[15], pins[16]};
int rows[8] = { pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};
void setup()
{
Serial.begin(9600);
pinMode(LIGHT_PIN, INPUT);
for (int idx = 1; idx <= 16; idx++)
pinMode(pins[idx], OUTPUT);
allOff();
}
void loop()
{
int lux = analogRead(LIGHT_PIN);
Serial.println(lux);
if (lux < 400) {
Row(8);
}
else if (lux > 400 && lux < 500) {
Row(6);
}
else if (lux > 501 && lux < 600) {
Row(4);
}
else if (lux > 601) {
Row(2);
}
}
void allOn() {
for (int idx = 0; idx < 8; idx++) {
digitalWrite(rows[idx], !LOW); //- ROWs ON
digitalWrite(cols[idx], !HIGH); //- COLUMNs ON
}
}
void Row(int high) {
for (int i = 0; i < high; i++) {
for (int j = 0; j < 8; j++) {
dot(i, j);
}
}
}
void allOff()
{ for (int idx = 0; idx < 8; idx++) {
digitalWrite(rows[idx], LOW); //- ROWs OFF
digitalWrite(cols[idx], HIGH); //- COLUMNs OFF
}
}
void dot(int rowIdx, int colIdx)
{
for (int idx = 0; idx < 8; idx++) {
(rowIdx == idx) ? digitalWrite(rows[idx], !LOW) :
digitalWrite(rows[idx], LOW);
(colIdx == idx) ? digitalWrite(cols[idx], !HIGH) :
digitalWrite(cols[idx], HIGH);
}
}
'IoT > 아두이노' 카테고리의 다른 글
[아두이노] 4digit-7세그먼트, 써미스터 (4) | 2022.07.07 |
---|---|
[아두이노] DC모터, 조이스틱 (7) | 2022.06.08 |
[아두이노] RGB LED, 가변저항, 스위치 (0) | 2022.06.07 |