Untitled
unknown
c_cpp
2 years ago
1.3 kB
6
Indexable
// Alat Penghitung Barang Otomatis menggunakan Sensor Inframerah berbasis Arduino UNO // Mayomi Shafa Feliza 220536610096 // Najwa Afif Nugraha 220536609096 // Senja Kurniawan 220536601054 #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); int IRPin = 2; int buzzerPin = 3; int buttonPin = 4; int n = 0; int oldValue = 1; void setup() { // put your setup code here, to run once: lcd.init(); lcd.backlight(); pinMode(IRPin, INPUT); pinMode(buttonPin, INPUT_PULLUP); pinMode(buzzerPin, OUTPUT); } void loop() { // put your main code here, to run repeatedly: lcd.setCursor(0, 0); lcd.print("Jumlah Barang: "); if (digitalRead(IRPin) == 0 && oldValue == 1) { oldValue = 0; Count(); } else if (digitalRead(IRPin) == 1 && oldValue == 0) { oldValue = 1; } if (digitalRead(buttonPin) == 0) { Reset(); } delay(10); } void Count() { n = n + 1; lcd.clear(); lcd.setCursor(0, 1); lcd.print(n); digitalWrite(buzzerPin, HIGH); delay(100); digitalWrite(buzzerPin, LOW); } void Reset() { n = 0; lcd.clear(); lcd.setCursor(0, 1); lcd.print(n); lcd.setCursor(0, 0); lcd.print("RESET"); digitalWrite(buzzerPin, HIGH); delay(500); digitalWrite(buzzerPin, LOW); }
Editor is loading...
Leave a Comment