#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TridentTD_LineNotify.h>
#include <WiFiManager.h>
#define LINE_TOKEN "utaElHMnTZRVZFvKZSGAgUxlF7Fzlgwg0flppaKwUHX"
LiquidCrystal_I2C lcd(0x27,16,2);
int sensor = 5;
int i = 0;
int a = 0; // Total amount
int ten = 0;
int ten10 = 0; // 10-coin type
int five = 0;
int five5 = 0; // 5-coin type
int two = 0;
int two2 = 0; // 2-coin type
int one = 0;
int one1 = 0; // 1-coin type
int i10 = 0; // Counter for types
int i5 = 0;
int i2 = 0;
int i1 = 0;
//char LINE_TOKEN[43] = "Input Line notify Token";
bool shouldSaveConfig = false;
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;
}
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "เชื่อมต่อ...");
}
void ICACHE_RAM_ATTR doCounter();
void setup() {
Serial.begin(115200);
WiFiManager wifiManager;
Serial.println("Connecting...");
if (!wifiManager.startConfigPortal("All")) {
Serial.println("NO");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println("WiFi connected");
pinMode(sensor, INPUT);
attachInterrupt(digitalPinToInterrupt(sensor), doCounter, FALLING);
server.on("/", handleRoot);
server.begin();
lcd.begin();
lcd.backlight();
lcd.print("Project");
lcd.setCursor(0, 1);
lcd.print("Smart Piggybank");
}
boolean isCounter = false;
int count = 0;
void loop() {
if (isCounter == true) {
isCounter = false;
delay(500);
}
if (i != 1000 && count != 0 ) {
i = i + 1;
}
if (i == 1000) {
i = 0;
if (count == 10){
i10 = i10 + 1;
ten = i10 * 10;
ten10 = 10;
}
if (count == 5){
i5 = i5 + 1;
five = i5 * 5;
five5 = 5;
}
if (count == 2){
i2 = i2 + 1;
two = i2 * 2;
two2 = 2;
}
if (count == 1){
i1 = i1 + 1;
one = i1 * 1;
one1 = 1;
}
a = ten + five + two + one;
// Sending Line Notify
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
LINE.setToken(LINE_TOKEN);
String message1 = "กระปุกออมสินอัจฉริยะ\n";
String messageCoins10 = "เหรียญ 10: ";
messageCoins10 += String(i10);
messageCoins10 += " เหรียญ\n";
String messageCoins5 = "เหรียญ 5: ";
messageCoins5 += String(i5);
messageCoins5 += " เหรียญ\n";
String messageCoins2 = "เหรียญ 2: ";
messageCoins2 += String(i2);
messageCoins2 += " เหรียญ\n";
String messageCoins1 = "เหรียญ 1: ";
messageCoins1 += String(i1);
messageCoins1 += " เหรียญ\n";
String totalMessage = "รวมเงิน ";
totalMessage += String(a);
totalMessage += " บาท";
LINE.notify((message1 + messageCoins10 + messageCoins5 + messageCoins2 + messageCoins1 + totalMessage).c_str());
// Display on LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("Total");
lcd.setCursor(9, 0);
lcd.print("Money");
lcd.setCursor(3, 1);
lcd.print(a);
lcd.setCursor(10, 1);
lcd.print("Baht");
server.handleClient();
count = 0;
}
}
void doCounter() {
isCounter = true;
count++;
}
พอดีมันรับค่ามาแล้วแต่พอสักพัก ไลน์มันหยุดการแจ้งเตือน ครับ
สอบถามครับ อยากให้โค้ดทำงานได้
#include <LiquidCrystal_I2C.h>
#include <TridentTD_LineNotify.h>
#include <WiFiManager.h>
#define LINE_TOKEN "utaElHMnTZRVZFvKZSGAgUxlF7Fzlgwg0flppaKwUHX"
LiquidCrystal_I2C lcd(0x27,16,2);
int sensor = 5;
int i = 0;
int a = 0; // Total amount
int ten = 0;
int ten10 = 0; // 10-coin type
int five = 0;
int five5 = 0; // 5-coin type
int two = 0;
int two2 = 0; // 2-coin type
int one = 0;
int one1 = 0; // 1-coin type
int i10 = 0; // Counter for types
int i5 = 0;
int i2 = 0;
int i1 = 0;
//char LINE_TOKEN[43] = "Input Line notify Token";
bool shouldSaveConfig = false;
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;
}
ESP8266WebServer server(80);
void handleRoot() {
server.send(200, "text/plain", "เชื่อมต่อ...");
}
void ICACHE_RAM_ATTR doCounter();
void setup() {
Serial.begin(115200);
WiFiManager wifiManager;
Serial.println("Connecting...");
if (!wifiManager.startConfigPortal("All")) {
Serial.println("NO");
delay(3000);
ESP.reset();
delay(5000);
}
Serial.println("WiFi connected");
pinMode(sensor, INPUT);
attachInterrupt(digitalPinToInterrupt(sensor), doCounter, FALLING);
server.on("/", handleRoot);
server.begin();
lcd.begin();
lcd.backlight();
lcd.print("Project");
lcd.setCursor(0, 1);
lcd.print("Smart Piggybank");
}
boolean isCounter = false;
int count = 0;
void loop() {
if (isCounter == true) {
isCounter = false;
delay(500);
}
if (i != 1000 && count != 0 ) {
i = i + 1;
}
if (i == 1000) {
i = 0;
if (count == 10){
i10 = i10 + 1;
ten = i10 * 10;
ten10 = 10;
}
if (count == 5){
i5 = i5 + 1;
five = i5 * 5;
five5 = 5;
}
if (count == 2){
i2 = i2 + 1;
two = i2 * 2;
two2 = 2;
}
if (count == 1){
i1 = i1 + 1;
one = i1 * 1;
one1 = 1;
}
a = ten + five + two + one;
// Sending Line Notify
Serial.printf("\nWiFi connected\nIP : ");
Serial.println(WiFi.localIP());
LINE.setToken(LINE_TOKEN);
String message1 = "กระปุกออมสินอัจฉริยะ\n";
String messageCoins10 = "เหรียญ 10: ";
messageCoins10 += String(i10);
messageCoins10 += " เหรียญ\n";
String messageCoins5 = "เหรียญ 5: ";
messageCoins5 += String(i5);
messageCoins5 += " เหรียญ\n";
String messageCoins2 = "เหรียญ 2: ";
messageCoins2 += String(i2);
messageCoins2 += " เหรียญ\n";
String messageCoins1 = "เหรียญ 1: ";
messageCoins1 += String(i1);
messageCoins1 += " เหรียญ\n";
String totalMessage = "รวมเงิน ";
totalMessage += String(a);
totalMessage += " บาท";
LINE.notify((message1 + messageCoins10 + messageCoins5 + messageCoins2 + messageCoins1 + totalMessage).c_str());
// Display on LCD
lcd.begin();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("Total");
lcd.setCursor(9, 0);
lcd.print("Money");
lcd.setCursor(3, 1);
lcd.print(a);
lcd.setCursor(10, 1);
lcd.print("Baht");
server.handleClient();
count = 0;
}
}
void doCounter() {
isCounter = true;
count++;
}
พอดีมันรับค่ามาแล้วแต่พอสักพัก ไลน์มันหยุดการแจ้งเตือน ครับ