My original goal for this project was to create a simple little riddle game where the player has to input the solution to win. If they made an incorrect input their life points would decrease by one. However, since I couldn't get the keypad to only return an incorrect result if something was pressed, I instead made a program that killed my computer (narratively). You can see what I was originally trying to accomplish at the bottom of my preview code.
Simply follow the instruction on the LCD screen to destroy your computer (narratively).
Materials:
1 - Arduino UNO
1- LCD
1 - Keypad
1- 10k potentiometer
23- Jumper wires
![]() |
Photo 1 |
![]() |
Photo 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the library code: | |
#include <LiquidCrystal.h> | |
#include <Keypad.h> | |
const byte ROWS = 4; //four rows | |
const byte COLS = 4; //four columns | |
//define the cymbols on the buttons of the keypads | |
char hexaKeys[ROWS][COLS] = { | |
{'1','2','3','A'}, | |
{'4','5','6','B'}, | |
{'7','8','9','C'}, | |
{'*','0','#','D'} | |
}; | |
byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad | |
byte colPins[COLS] = {A0, A1, A2, A3}; //connect to the column pinouts of the keypad | |
//initialize an instance of class NewKeypad | |
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); | |
// initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); | |
byte customChar[] = { | |
B11011, | |
B10101, | |
B10001, | |
B01010, | |
B00100, | |
B00000, | |
B00000, | |
B00000 | |
}; | |
int tries = 3; | |
void setup() { | |
Serial.begin(9600); | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
lcd.createChar(0, customChar); | |
// Print a message to the LCD. | |
lcd.print("Solve to enter"); | |
delay(1000); | |
// set the cursor to column 0, line 1 | |
// (note: line 1 is the second row, since counting begins with 0): | |
lcd.setCursor(0,0); | |
lcd.print("Press 1"); | |
lcd.setCursor(0,1); | |
lcd.print("Com Health"); | |
lcd.setCursor(11,1); | |
lcd.write(byte(0)); | |
delay(5000); | |
} | |
void loop() { | |
lcd.setCursor(12,1); | |
lcd.print(tries); | |
int customKey = customKeypad.getKey(); | |
if (customKey){ | |
Serial.println(customKey); | |
} | |
if(customKey == 49){ | |
//lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("Do you tire "); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("of your "); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("computer?"); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("Press 2 "); | |
} | |
if(customKey == 50){ | |
lcd.setCursor(0,0); | |
lcd.print("Destroy it now"); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("press 3......."); | |
} | |
if(customKey == 51){ | |
tries = tries - 1; | |
lcd.setCursor(0,0); | |
lcd.print("Destroying..."); | |
} | |
if(tries == 0){ | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("The computer is"); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("dead, "); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("long live "); | |
delay(2000); | |
lcd.setCursor(0,0); | |
lcd.print("the computer "); | |
delay(2000); | |
} | |
//failed wrong input | |
/*if(customKey != 52) { | |
tries = tries - 1; | |
lcd.setCursor(13,1); | |
lcd.print(tries); | |
}*/ | |
//failed timer | |
/* while (x > 0){ | |
if (customKey){ | |
Serial.println(customKey); | |
} | |
lcd.setCursor(0,1); | |
lcd.print(x); | |
x = x -1; | |
delay(1000); | |
if (x == 0){ | |
lcd.setCursor(0,1); | |
lcd.print("Game Over."); | |
for(;;); | |
} | |
}*/ | |
// print the number of seconds since reset: | |
//lcd.print(millis() / 1000); | |
} |
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.