-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbopit.ino
172 lines (138 loc) · 4.26 KB
/
bopit.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define BUTTON_COUNT 3
#define BUTTON_PIN_START 12
#define GREEN_LED_PIN 13
#define RED_LED_PIN 14
LiquidCrystal_I2C lcdOne(0x27, 16, 2); // Initialize LCD object - Assuming 16x2 display
bool micState = false;
bool lcdOn = false; // Variable to track the state of the LCD
bool gameStarted = false;
int randomButton; // Variable to store the randomly selected button
unsigned long gameStartTime; // Variable to store the time when the game started
bool correctButtonPressed = false; // Flag to track if the correct button was pressed
bool game3States = false;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
void setup() {
// Initialize random number generator with seed
randomSeed(analogRead(0));
// LCD setup
lcdOne.init(); // Initialize the LCD with the I2C interface
//Digital Inputs
pinMode(0, INPUT_PULLUP); // OFF/ON button
pinMode(1, INPUT_PULLUP); // "New Game" button
//Success/failure LEDs
pinMode(18, OUTPUT);//Success led
pinMode(19, OUTPUT); //Failure led
//Mic input
pinMode(17, INPUT); //Read input from microphone (Digital)
}
void loop() {
//OFF/ON BUTTON//////////////////////
// If the button is pressed (buttonState is LOW) and the LCD is currently off
if (digitalRead(0) == LOW && !lcdOn) {
// Turn on the LCD backlight
lcdOne.backlight();
// Clear the LCD screen
lcdOne.clear();
// Set cursor to the beginning of the first line
lcdOne.setCursor(0, 0);
// Print "Press Button for" on the first line
lcdOne.print("Press Button for");
// Set cursor to the beginning of the second line
lcdOne.setCursor(0, 1);
// Print "New Game" on the second line
lcdOne.print("New Game");
lcdOn = true; // Set the LCD state to on
gameStarted = true;
}
// If the button is pressed (buttonState is LOW) and the LCD is currently on
else if (digitalRead(0) == LOW && lcdOn) {
// Turn off the LCD backlight
lcdOne.noBacklight();
// Clear the LCD screen
lcdOne.clear();
// Set cursor to the beginning of the first line
lcdOne.setCursor(0, 0);
// Print "System Off" on the first line
lcdOne.print("System Off");
lcdOn = false; // Set the LCD state to off
gameStarted = false;
}
delay(100); // Add a small delay to avoid overwhelming the loop
//NEW GAME BUTTON//////////////////////////////// (later)
if (gameStarted) {
if (digitalRead(1) == LOW) {
// Clear the LCD screen
lcdOne.clear();
lcdOne.print("Ready, Set, Go!");
randomGame();
//startGame();
}
}
}
//Function for Sing it!
bool singItCommand() {
if (digitalRead(17) == HIGH) {
return true; // Microphone input detected
} else {
return false; // No microphone input
}
}
void randomGame() {
lcdOne.clear();
bool gameOver = false;
while (!gameOver) {
int randomNum = random(1, 4); // Generate a random number between 1 and 3
// Print the game number on the LCD
lcdOne.setCursor(0, 0);
lcdOne.clear();
lcdOne.print("Game ");
lcdOne.print(randomNum);
// Call the respective game function based on the random number
switch(randomNum) {
case 1:
// Call game function 1 and set gameOver based on game result
// gameOver = game1();
break;
case 2:
// Call game function 2 and set gameOver based on game result
// gameOver = game2();
break;
case 3:
// Call game function 3 and set gameOver based on game result
gameOver = game3();
break;
default:
// Handle unexpected case
break;
}
delay(2000); // Add a delay before selecting the next game
}
// Once the game loop exits, display a message or perform any necessary cleanup
lcdOne.clear();
lcdOne.print("Game Over!");
//Add score as well
}
//Play it!
bool game1(){
}
//Whammy it!
bool game2(){
}
//Sing it!
bool game3() {
// put your main code here, to run repeatedly:
micState = singItCommand(); //Assign Boolean value according to function
if(micState == 1){ //Light LED based on success or failure
digitalWrite(12, HIGH);
}
else{
digitalWrite(13, HIGH);
}
delay(1000); //Wait before accepting more input
}