-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpet.ino
105 lines (91 loc) · 2.23 KB
/
vpet.ino
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <LiquidCrystal.h>
// Function declarations
void drawPet(int expression);
void timePetMovements(unsigned long currentTime);
void scoreDown(unsigned long currentTime);
void buttonListener();
void drawDividerAt(int lcdRow, int lcdCol);
void drawScoreAt(int lcdRow, int lcdCol, int score);
void resetScore();
#define RIGHT_EYE 0
#define LEFT_EYE 1
#define SMILE 2
#define FROWNING 3
#define SMOKE 4
#define HEART 5
#define DIVIDER 6
LiquidCrystal lcd(0, 1, 8, 9, 10, 11);
const int buttonPin = 2;
const int vapePin = 3;
int buttonState = HIGH;
int vapeState = LOW;
int buttonPress = 0;
int score = 0;
int onHomeScreen = true;
unsigned long prevMove = 0;
unsigned long moveDelay = 900;
int timesMoved = 0;
void setup() {
unsigned long currentTime = millis();
pinMode(buttonPin, INPUT_PULLUP);
pinMode(vapePin, INPUT_PULLUP);
lcd.begin(16, 2);
drawDividerAt(1, 3);
drawDividerAt(0, 3);
drawScoreAt(0, 0, score);
scoreMove(currentTime);
drawPet(SMILE);
timePetMovements(currentTime);
// Initial pet display
}
void loop() {
unsigned long currentTime = millis();
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
buttonPress++;
if (onHomeScreen) {
lcd.clear();
drawDividerAt(1, 3);
drawDividerAt(0, 3);
drawScoreAt(0, 0, score);
drawPet(SMILE);
timePetMovements(currentTime);
scoreMove(currentTime);
} else {
lcd.clear();
lcd.print("Vape Pet");
lcd.setCursor(0, 1);
lcd.print("vape to feed me!!");
lcd.clear();
drawPet(SMILE);
timePetMovements(currentTime);
scoreMove(currentTime);
}
onHomeScreen = !onHomeScreen;
delay(500);
}
buttonListener(); // Call the button listener function
if (buttonPress > 0) {
drawPet(SMOKE);
digitalWrite(vapePin, HIGH);
delay(500);
digitalWrite(vapePin, LOW);
drawPet(SMILE);
score++;
drawScoreAt(0, 0, score);
timePetMovements(currentTime);
scoreMove(currentTime);
if (score >= 3) {
lcd.print("WHOAA..");
lcd.clear();
}
}
if (onHomeScreen) {
timePetMovements(currentTime);
scoreMove(000);
drawDividerAt(1, 3);
drawDividerAt(0, 3);
drawScoreAt(0, 0, score);
// Decrease score over time
}
}