/* This program was adapted from electronicsbug.wordpress.com
I could not find the Random number library as suggested in this code so I utilized the Arduino C++ Random function in its place. Also added in was Ratary Encoder and LCD modules
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5); // (RS,E, D4, D5, D6, D7) int computerNumber; int lastGuess; boolean inGame;
void setup() { Serial.begin(9600); lcd.begin(16, 2); pinMode(ENC_A, INPUT); digitalWrite(ENC_A, HIGH); pinMode(ENC_B, INPUT); digitalWrite(ENC_B, HIGH); inGame = false; digitalWrite(6,HIGH); // Set pin 6 HIGH for press of rotary encoder }
void loop () {
while(!inGame) { Serial.println("Guessing Game"); Serial.println("The computer has picked a number between 1 and 100"); lcd.setCursor(0, 0); lcd.print("The computer has picked a number between 1 and 100"); Serial.println("Send anything to start the game"); lcd.setCursor(0, 1); lcd.print("Send anything to start the game"); randomSeed(analogRead(0)); while(digitalRead(6) == HIGH) { } // Wait for user to enter somehting in serial
computerNumber = random(0, 99)+1 ; // Get random number here delay(300); inGame = true;
}
while(inGame) { while(Serial.available() > 0) { delay(100); Serial.read (); // read value from serial
} Serial.println("Please enter a guess..."); while(digitalRead(6) == HIGH) {
static uint8_t counter = 0; //this variable will be changed by encoder input int8_t tmpdata; /**/ tmpdata = read_encoder();