Created
April 12, 2024 10:29
-
-
Save maxpromer/70a0d375c0ae663fae41b78a4aebf23d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define SIG_PIN 4 // กำหนดขาที่ต้อ SIG | |
#define EN_PIN 16 // กำหนดขาที่ต่อ EN | |
bool count_update_flag = false; // ตัวแปรเก็บค่าว่า count อัพเดทแล้ว | |
void pulse_in_cb() { // เมื่อได้รับ Pulse | |
count_update_flag = true; | |
} | |
void setup() { | |
pinMode(SIG_PIN, INPUT); // กำหนดขา SIG เป็นอินพุต | |
attachInterrupt(digitalPinToInterrupt(SIG_PIN), pulse_in_cb, FALLING); // เปิดใช้อินเตอร์รัพท์ภายนอก | |
pinMode(EN_PIN, OUTPUT); // กำหนดขา EN เป็นอินพุต | |
digitalWrite(EN_PIN, HIGH); // สั่งให้ขา EN เป็นลอจิก 1 (HIGH) เพื่อให้รับเหรียญ | |
Serial.begin(115200); // ใช้ Serial ที่ความเร็ว 115200 | |
} | |
void loop() { | |
if (count_update_flag) { | |
Serial.println("Got coin !!!"); // แสดงข้อความใน Serial Monitor | |
delay(200); | |
count_update_flag = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment