พยายามแล้วค่ะ กดอัพโหลดแต่จอก็ไม่ขึ้นตัวอักษรอะไรเลย
อันนี้คือโค้ดที่เขียน
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define btnRESET 0
#define btnONE 1
#define btnFIVE 2
#define btnTEN 3
LiquidCrystal_I2C lcd(0x27,16,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
unsigned int coinONE = 0;
unsigned int coinFIVE = 0;
unsigned int coinTEN = 0;
unsigned int previouscoinONE = 0;
unsigned int previouscoinFIVE = 0;
unsigned int previouscoinTEN =0;
unsigned int coinSUM = 0;
boolean stateONE = 0;
boolean stateFIVE = 0;
boolean stateTEN =0;
void setup()
{
attachInterrupt(0, FIVE, FALLING); // #define btnFIVE 2
attachInterrupt(1, TEN, FALLING); // #define btnTEN 3
pinMode(btnRESET, INPUT);
pinMode(btnONE, INPUT);
pinMode(btnFIVE, INPUT);
pinMode(btnTEN, INPUT);
pinMode(13, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Count Coin ");
lcd.setCursor(0, 1);
lcd.print(" 2 ");
lcd.setCursor(0, 2);
lcd.print(" System ");
lcd.setCursor(0, 3);
lcd.print(" ");
delay(1500);
Show();
}
void loop()
{
if((digitalRead(btnONE) == LOW)&&
stateONE == 0))
{
stateONE = 1;
delay(500);
if((stateFIVE == 0)&&
stateTEN == 0))
{
coinONE++;
}
}
if((coinONE != previouscoinONE)||(coinFIVE != previouscoinFIVE)||(coinTEN != previouscoinTEN))
{
Show();
previouscoinONE = coinONE;
previouscoinFIVE = coinFIVE;
previouscoinTEN = coinTEN;
}
}
void Show()
{
coinSUM = ((coinONE*1)+(coinFIVE*5)+(coinTEN*10));
lcd.setCursor(0, 0);
lcd.print(" 1 THB = ")
;if(coinONE < 10) {lcd.print("000"); }
else if(coinONE < 100) {lcd.print("00"); }
else if(coinONE < 1000) {lcd.print("0"); }
lcd.print(coinONE);
lcd.setCursor(0, 1);
lcd.print(" 5 THB = ");
if(coinFIVE < 10) {lcd.print("000"); }
else if(coinFIVE < 100) {lcd.print("00"); }
else if(coinFIVE < 1000) {lcd.print("0"); }
lcd.print(coinFIVE);
lcd.setCursor(0, 2);
lcd.print(" 10 THB = ")
;if(coinTEN < 10) {lcd.print("000"); }
else if(coinTEN < 100) {lcd.print("00"); }
else if(coinTEN < 1000) {lcd.print("0"); }
lcd.print(coinTEN);
lcd.setCursor(0, 3);
lcd.print(" SUM ")
;if(coinSUM < 10) {lcd.print("00000" );}
else if(coinSUM < 100) {lcd.print("0000"); }
else if(coinSUM < 1000 ) {lcd.print("000"); }
else if(coinSUM < 10000 ) {lcd.print("00"); }
else if(coinSUM < 100000) {lcd.print("0"); }
lcd.print(coinSUM);
lcd.setCursor(14, 0); lcd.print("Coin ");
lcd.setCursor(14, 1); lcd.print("Coin ");
lcd.setCursor(14, 2); lcd.print("Coin ");
lcd.setCursor(16, 3); lcd.print("B-. ");
stateONE = 0;
stateFIVE = 0;
stateTEN = 0;
}
void FIVE()
{
stateFIVE = 1;
if(stateONE == 0)
{
coinONE++;
}
if(stateONE == 1)
{
coinFIVE++;
}
}
void TEN()
{
stateTEN = 1;
if((stateONE == 1)&&
stateFIVE == 1))
{
coinTEN++;
coinFIVE--;
}
}
จอ LCD ที่ต่อกับ arduino ไม่ขึ้นตัวอักษร
อันนี้คือโค้ดที่เขียน
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define btnRESET 0
#define btnONE 1
#define btnFIVE 2
#define btnTEN 3
LiquidCrystal_I2C lcd(0x27,16,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
unsigned int coinONE = 0;
unsigned int coinFIVE = 0;
unsigned int coinTEN = 0;
unsigned int previouscoinONE = 0;
unsigned int previouscoinFIVE = 0;
unsigned int previouscoinTEN =0;
unsigned int coinSUM = 0;
boolean stateONE = 0;
boolean stateFIVE = 0;
boolean stateTEN =0;
void setup()
{
attachInterrupt(0, FIVE, FALLING); // #define btnFIVE 2
attachInterrupt(1, TEN, FALLING); // #define btnTEN 3
pinMode(btnRESET, INPUT);
pinMode(btnONE, INPUT);
pinMode(btnFIVE, INPUT);
pinMode(btnTEN, INPUT);
pinMode(13, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Count Coin ");
lcd.setCursor(0, 1);
lcd.print(" 2 ");
lcd.setCursor(0, 2);
lcd.print(" System ");
lcd.setCursor(0, 3);
lcd.print(" ");
delay(1500);
Show();
}
void loop()
{
if((digitalRead(btnONE) == LOW)&&stateONE == 0))
{
stateONE = 1;
delay(500);
if((stateFIVE == 0)&&stateTEN == 0))
{
coinONE++;
}
}
if((coinONE != previouscoinONE)||(coinFIVE != previouscoinFIVE)||(coinTEN != previouscoinTEN))
{
Show();
previouscoinONE = coinONE;
previouscoinFIVE = coinFIVE;
previouscoinTEN = coinTEN;
}
}
void Show()
{
coinSUM = ((coinONE*1)+(coinFIVE*5)+(coinTEN*10));
lcd.setCursor(0, 0);
lcd.print(" 1 THB = ")
;if(coinONE < 10) {lcd.print("000"); }
else if(coinONE < 100) {lcd.print("00"); }
else if(coinONE < 1000) {lcd.print("0"); }
lcd.print(coinONE);
lcd.setCursor(0, 1);
lcd.print(" 5 THB = ");
if(coinFIVE < 10) {lcd.print("000"); }
else if(coinFIVE < 100) {lcd.print("00"); }
else if(coinFIVE < 1000) {lcd.print("0"); }
lcd.print(coinFIVE);
lcd.setCursor(0, 2);
lcd.print(" 10 THB = ")
;if(coinTEN < 10) {lcd.print("000"); }
else if(coinTEN < 100) {lcd.print("00"); }
else if(coinTEN < 1000) {lcd.print("0"); }
lcd.print(coinTEN);
lcd.setCursor(0, 3);
lcd.print(" SUM ")
;if(coinSUM < 10) {lcd.print("00000" );}
else if(coinSUM < 100) {lcd.print("0000"); }
else if(coinSUM < 1000 ) {lcd.print("000"); }
else if(coinSUM < 10000 ) {lcd.print("00"); }
else if(coinSUM < 100000) {lcd.print("0"); }
lcd.print(coinSUM);
lcd.setCursor(14, 0); lcd.print("Coin ");
lcd.setCursor(14, 1); lcd.print("Coin ");
lcd.setCursor(14, 2); lcd.print("Coin ");
lcd.setCursor(16, 3); lcd.print("B-. ");
stateONE = 0;
stateFIVE = 0;
stateTEN = 0;
}
void FIVE()
{
stateFIVE = 1;
if(stateONE == 0)
{
coinONE++;
}
if(stateONE == 1)
{
coinFIVE++;
}
}
void TEN()
{
stateTEN = 1;
if((stateONE == 1)&&stateFIVE == 1))
{
coinTEN++;
coinFIVE--;
}
}