ใบงานที่ 3. การแสดงค่าความเข้มของแสงด้วย 7-Segment และ LED
ผู้จัดทำ
1.นาย รุจ พรชัยประสิทธิ์ 1 สทค 1 6031280017
2.นาย ธีรพงษ์ เฉลยพงษ์ 1 สทค 2 6031280034
อุปกรณ์ที่ใช้
1.7 segment 1 ตัว
2.ตัวต้านทาน 1k 1 ตัว
3.ตัวต้านทาน 220R 1 ตัว
3.ตัวต้านทาน 220R 1 ตัว
4.สายไฟ 12 เส้น
5.บอร์ด Arduino
6.LDR
6.LDR
6.โฟโต้บอร์ด
7.สาย UPLOAD
รูปวงจร
CODE
LED
const int sensorMin = 0;
const int sensorMax = 600;
int LED1=3;
int LED2=4;
int LED3=5;
int LED4=6;
void setup()
{
pinMode (LED1,OUTPUT);
pinMode (LED2,OUTPUT);
pinMode (LED3,OUTPUT);
pinMode (LED4,OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(A0);
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0:
digitalWrite (LED1,HIGH);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,LOW);
Serial.println("dark");
break;
case 1:
digitalWrite (LED1,LOW);
digitalWrite (LED2,HIGH);
digitalWrite (LED3,LOW);
digitalWrite (LED4,LOW);
Serial.println("dim");
break;
case 2:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,HIGH);
digitalWrite (LED4,LOW);
Serial.println("medium");
break;
case 3:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,HIGH);
Serial.println("bright");
break;
}
delay(1);
}
7-segment
const int sensorMin = 0;
const int sensorMax = 600;
int LED1=2;
int LED2=3;
int LED3=4;
int LED4=5;
int LED5=6;
int LED6=7;
int LED7=8;
int LED8=9;
void setup()
{
pinMode (LED1,OUTPUT);
pinMode (LED2,OUTPUT);
pinMode (LED3,OUTPUT);
pinMode (LED4,OUTPUT);
pinMode (LED5,OUTPUT);
pinMode (LED6,OUTPUT);
pinMode (LED7,OUTPUT);
pinMode (LED8,OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(A0);\
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0:
digitalWrite (LED1,HIGH);
digitalWrite (LED2,LOW);
digitalWrite (LED3,HIGH);
digitalWrite (LED4,HIGH);
digitalWrite (LED5,LOW);
digitalWrite (LED6,HIGH);
digitalWrite (LED7,HIGH);
digitalWrite (LED8,LOW);
Serial.println("dark");
break;
case 1:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,LOW);
digitalWrite (LED5,HIGH);
digitalWrite (LED6,HIGH);
digitalWrite (LED7,LOW);
digitalWrite (LED8,LOW);
Serial.println("dim");
break;
case 2:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,HIGH);
digitalWrite (LED5,LOW);
digitalWrite (LED6,HIGH);
digitalWrite (LED7,LOW);
digitalWrite (LED8,LOW);
Serial.println("medium");
break;
case 3:
digitalWrite (LED1,HIGH);
digitalWrite (LED2,LOW);
digitalWrite (LED3,HIGH);
digitalWrite (LED4,HIGH);
digitalWrite (LED5,LOW);
digitalWrite (LED6,LOW);
digitalWrite (LED7,LOW);
digitalWrite (LED8,LOW);
Serial.println("bright");
break;
}
delay(1);
}
VDO
รูปวงจร
CODE
LED
const int sensorMin = 0;
const int sensorMax = 600;
int LED1=3;
int LED2=4;
int LED3=5;
int LED4=6;
void setup()
{
pinMode (LED1,OUTPUT);
pinMode (LED2,OUTPUT);
pinMode (LED3,OUTPUT);
pinMode (LED4,OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(A0);
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0:
digitalWrite (LED1,HIGH);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,LOW);
Serial.println("dark");
break;
case 1:
digitalWrite (LED1,LOW);
digitalWrite (LED2,HIGH);
digitalWrite (LED3,LOW);
digitalWrite (LED4,LOW);
Serial.println("dim");
break;
case 2:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,HIGH);
digitalWrite (LED4,LOW);
Serial.println("medium");
break;
case 3:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,HIGH);
Serial.println("bright");
break;
}
delay(1);
}
7-segment
const int sensorMin = 0;
const int sensorMax = 600;
int LED1=2;
int LED2=3;
int LED3=4;
int LED4=5;
int LED5=6;
int LED6=7;
int LED7=8;
int LED8=9;
void setup()
{
pinMode (LED1,OUTPUT);
pinMode (LED2,OUTPUT);
pinMode (LED3,OUTPUT);
pinMode (LED4,OUTPUT);
pinMode (LED5,OUTPUT);
pinMode (LED6,OUTPUT);
pinMode (LED7,OUTPUT);
pinMode (LED8,OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorReading = analogRead(A0);\
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
switch (range) {
case 0:
digitalWrite (LED1,HIGH);
digitalWrite (LED2,LOW);
digitalWrite (LED3,HIGH);
digitalWrite (LED4,HIGH);
digitalWrite (LED5,LOW);
digitalWrite (LED6,HIGH);
digitalWrite (LED7,HIGH);
digitalWrite (LED8,LOW);
Serial.println("dark");
break;
case 1:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,LOW);
digitalWrite (LED5,HIGH);
digitalWrite (LED6,HIGH);
digitalWrite (LED7,LOW);
digitalWrite (LED8,LOW);
Serial.println("dim");
break;
case 2:
digitalWrite (LED1,LOW);
digitalWrite (LED2,LOW);
digitalWrite (LED3,LOW);
digitalWrite (LED4,HIGH);
digitalWrite (LED5,LOW);
digitalWrite (LED6,HIGH);
digitalWrite (LED7,LOW);
digitalWrite (LED8,LOW);
Serial.println("medium");
break;
case 3:
digitalWrite (LED1,HIGH);
digitalWrite (LED2,LOW);
digitalWrite (LED3,HIGH);
digitalWrite (LED4,HIGH);
digitalWrite (LED5,LOW);
digitalWrite (LED6,LOW);
digitalWrite (LED7,LOW);
digitalWrite (LED8,LOW);
Serial.println("bright");
break;
}
delay(1);
}
VDO
7-Segment
https://youtu.be/85SAnWlnfeg
LED
https://youtu.be/9CDMS8s_Eco
ความคิดเห็น
แสดงความคิดเห็น