-
Notifications
You must be signed in to change notification settings - Fork 0
/
vibrationLCD
33 lines (27 loc) · 933 Bytes
/
vibrationLCD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int vib_pin = 7;
int score = 0; // Initialize the score variable
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(vib_pin, INPUT);
Serial.begin(9600);
lcd.begin();
lcd.backlight();
}
void loop() {
int val = digitalRead(vib_pin);
if (val == HIGH) { // If vibration is sensed
score += 10; // Increase the score by 10
displayScore(); // Update the score on the LCD
delay(2000); // Add a delay to avoid multiple increments for a single vibration
}
}
void displayScore() {
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 1); // Set the cursor to the first column of the second row
lcd.print("Score: "); // Print "Score: " on the LCD
lcd.print(score); // Print the current score on the LCD
Serial.print("Score: "); // Print "Score: " on the Serial monitor
Serial.println(score); // Print the current score on the Serial monitor
}