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
|
#include <Servo.h> //Needed to control servo
#include <LiquidCrystal.h>
#include <WString.h>
#include <TrueRandom.h>
#define POTPIN 3
#define SPEAKERPIN 5
#define BUTTONPIN 6
#define servon 3 //power to servo
#define LASTBUTTONSTATE HIGH
#define DEBOUNCEDELAY 50
#define NUMWORDS 42
#define button2 3 //button inside box
//define notes for buzzer
#define LOWNOTE 100
#define ALOW 440
#define CLOW 261
#define ELOW 329
#define FLOW 349
#define CHIGH 523
#define EHIGH 659
#define GHIGH 784
#define FSHIGH 740
#define AHIGH 880
void(* resetFunc) (void) = 0; //declare reset function @ address 0
const char* words[] = {"ab", "abb", "abbb", "abac", "abcd", "abcde",
"abcdes", "sadav", "fanon", "shintiyan", "avsdvas", "asdv", "nawab",
"avddv", "avdavs", "asdvasdv", "asdavae", "gamic", "avsad", "abvds",
"hygeia", "azygous", "bavin", "asdv", "asdvasdv", "bayadere",
"assegai", "homoousian", "pawky", "argrcvcvb", "abfdb", "adfbbadffg",
"hamose", "japanning", "canakin", "abfdbedh", "mazard", "abelectrolyze",
"agulpha", "amethodize", "hadji", "acequia"};
const char letterVal[] = "abcdefghijklmnopqrstuvwxyz";
char guessLetter;
char guessLast;
char guessed[25];
const char* secretWord;
int guessedCount = 1;
int wordSize;
int gotOne = 0;
int alreadyGuessed = 0;
int showAsterisk = 0;
int buttonState;
int hangman = 0;
int totalRight = 0;
long lastDebounceTime = 0;
Servo lock; //create a servo object called lock
int button2on; //integer for button inside box
LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);
String guessWord = String(42);
// hangman graphic characters
byte topleft[] = { 0x1F, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };
byte topright[] = { 0x1C, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte bottomleft[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x1F };
byte bottomright[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte head[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x00, 0x00, 0x00 };
byte topbody[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x04, 0x04, 0x04 };
byte bottombody[] = { 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte rightarm[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x05, 0x06, 0x04 };
byte leftarm[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x15, 0x0E, 0x04 };
byte rightleg[] = { 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00 };
byte leftleg[] = { 0x04, 0x04, 0x0A, 0x0A, 0x11, 0x00, 0x00, 0x00 };
byte leftarrow[] = { 0x10, 0x18, 0x1C, 0x1E, 0x1E, 0x1C, 0x18, 0x10 };
byte rightarrow[] = { 0x01, 0x03, 0x07, 0x0F, 0x0F, 0x07, 0x03, 0x01 };
void setup()
{
lock.write(160); //set lock servo to locked position before it is attatched to prevent servo from moving to 90 degrees on startup
lock.attach(4); // Connected to servo to control lock
Serial.begin(9600);
pinMode (POTPIN, INPUT);
pinMode (BUTTONPIN, INPUT);
pinMode (SPEAKERPIN, OUTPUT);
// pinMode (servon, OUTPUT);
pinMode (button2, INPUT);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Guess the word");
lcd.setCursor(1,1);
lcd.print("to get inside!");
delay(2000);
// pick a random word using analog 5 for random data
//randomSeed(analogRead(4));
newWord();
//draw the board
draw_board();
// digitalWrite(servon, HIGH);
lock.write(160);
delay(1000);
// digitalWrite(servon, LOW);
}
void newWord(){
//pick a random word from the list
int pick = TrueRandom.random(NUMWORDS);
const char* pickWord = words[pick];
guessWord = pickWord;
secretWord = guessWord.c_str();
wordSize = guessWord.length();
Serial.println(guessWord); // print the word to serial for cheaters like me ;) ...or for testing purposes.
}
|