#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int analogX;
int val;
void setup()
{
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(3,OUTPUT);
lcd.init();
pinMode(A0,INPUT);
lcd.backlight();
}
void loop()
{
analogX=analogRead(A0);
lcd.setCursor(0,0);
lcd.print("Nontapat Satitphum");
lcd.setCursor(0,1);
lcd.print(analogX);
lcd.print(" ");
val = analogX;
val = map(val,0,1023,0,90);
lcd.setCursor(7,1);
lcd.print("RGB:");
if (val<30){
lcd.setCursor(11,1);
lcd.print("RED");
lcd.print(" ");
digitalWrite(6,1);
digitalWrite(5,0);
digitalWrite(3,0);
}
else if (val<60){
lcd.setCursor(11,1);
lcd.print("BLUE");
lcd.print(" ");
digitalWrite(6,0);
digitalWrite(5,1);
digitalWrite(3,0);
}
else{
lcd.setCursor(11,1);
lcd.print("GREEN");
lcd.print(" ");
digitalWrite(6,0);
digitalWrite(5,0);
digitalWrite(3,1);
}
// Your code here (if any)
}
สอนเขียนโค๊ดหน่อยได้ไหมคะ
LiquidCrystal_I2C lcd(0x27, 16, 2);
int analogX;
int val;
void setup()
{
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(3,OUTPUT);
lcd.init();
pinMode(A0,INPUT);
lcd.backlight();
}
void loop()
{
analogX=analogRead(A0);
lcd.setCursor(0,0);
lcd.print("Nontapat Satitphum");
lcd.setCursor(0,1);
lcd.print(analogX);
lcd.print(" ");
val = analogX;
val = map(val,0,1023,0,90);
lcd.setCursor(7,1);
lcd.print("RGB:");
if (val<30){
lcd.setCursor(11,1);
lcd.print("RED");
lcd.print(" ");
digitalWrite(6,1);
digitalWrite(5,0);
digitalWrite(3,0);
}
else if (val<60){
lcd.setCursor(11,1);
lcd.print("BLUE");
lcd.print(" ");
digitalWrite(6,0);
digitalWrite(5,1);
digitalWrite(3,0);
}
else{
lcd.setCursor(11,1);
lcd.print("GREEN");
lcd.print(" ");
digitalWrite(6,0);
digitalWrite(5,0);
digitalWrite(3,1);
}
// Your code here (if any)
}