Repository navigation
Expand file tree
/
Copy pathmain.ino
More file actions
65 lines (51 loc) · 1.59 KB
/
Copy pathmain.ino
File metadata and controls
65 lines (51 loc) · 1.59 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// --- Define Buzzer Pin (MUST use a PWM pin, like 9, for volume control) ---
const int BUZZER_PIN = 9;
void setup() {
Serial.begin(9600);
// Initialize the LCD
lcd.init();
lcd.backlight();
// Set buzzer pin mode
pinMode(BUZZER_PIN, OUTPUT);
// Print initial message
lcd.setCursor(0, 0);
lcd.print("Server Ready!");
}
void loop() {
if (Serial.available() > 0) {
// Read the string until newline character '\n'
String receivedText = Serial.readStringUntil('\n');
int separatorIndex = receivedText.indexOf('|');
lcd.clear(); // Clear old display
if (separatorIndex != -1) {
String line1 = receivedText.substring(0, separatorIndex);
String line2 = receivedText.substring(separatorIndex + 1);
lcd.setCursor(0, 0);
lcd.print(line1);
lcd.setCursor(0, 1);
lcd.print(line2);
} else {
// Fallback if no '|' is found
lcd.setCursor(0, 0);
lcd.print(receivedText);
}
// Call the function to trigger the buzzer
beepTwice();
}
}
// --- Function to make the buzzer beep twice at low volume ---
void beepTwice() {
for (int i = 0; i < 2; i++) {
// analogWrite(pin, value). Value is 0 to 255.
// 5 is very quiet. Change to 10 or 20 if it's too quiet.
analogWrite(BUZZER_PIN, 10);
delay(100);
// Turn off buzzer
analogWrite(BUZZER_PIN, 0);
delay(100);
}
}