Week 9: NEVER HAVE I EVER with Arduino

Concept:

For this assignment, I wanted to create a basic version of “Never have I ever” game. The rules of this game are simple, usually there’s a narrator who says something and if any of the player has done that they say, “I have”. I wanted to create this game on Arduino using the LCD screen, the switch button, and the red led. Instead of the narrator, I wanted to display a text on the lcd screen and if the player has done that thing, they press the switch that will light up the led to show the other players. In short, pressing the button is equivalent to saying, “I HAVE” in the real game. For this reason, I went on internet and tried to understand the working of the LCD screen that comes with Arduino UNO and linked it with the switch to control the texts that were displayed on the screen. I was able to create a basic version of this game with just one prompt as I was struggling to reset the cursor placement on the screen. There’s a welcome message that is displayed and is shown until the user presses the switch. Then the first prompt is there, and the user can press the switch to indicate that he/she has done that.

Schematic:
COde:

 

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
int redLEDPin = 8;
int trueSwitch = A1;

String welcome = "Welcome Players! The rules of the game are simple: Press RED button if you have! Press RED button to Proceed";
int leng = welcome.length();
char myText[50] = "Never have I ever got on the wrong train or bus?";
bool StartGame = false;
int promptcount = 0;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 1);
  pinMode(redLEDPin, OUTPUT);
  pinMode(trueSwitch, INPUT);
}

void loop() {

  // set the cursor to (0,0):
  
 

  lcd.setCursor(0, 0);

  // print from 0 to 9:
  // lcd.autoscroll();
  for (int thisChar = 0; thisChar < leng; thisChar++) {
    int truePos = digitalRead(trueSwitch);
    if (truePos == HIGH){
        digitalWrite(redLEDPin, HIGH);
        delay(600);
        StartGame = true; 
        digitalWrite(redLEDPin, LOW);
        break;  
      } 

    lcd.print(welcome[thisChar]);

    if (thisChar == 15){
      lcd.autoscroll();
    }

    delay(200);

  }
  lcd.clear();
  lcd.noAutoscroll();
  delay(2000);
  

  

  // set the cursor to (16,1):

  
  // clear screen for the next loop:

  while (StartGame){
    
 
    lcd.clear();

    lcd.setCursor(0, 0);

    // print from 0 to 9:
    // lcd.autoscroll();
    for (int thisChar = 0; thisChar < 50; thisChar++) {
      int truePos = digitalRead(trueSwitch);
      if (truePos == HIGH){
        digitalWrite(redLEDPin, HIGH);
        promptcount++;
        delay(300);   
      } 
      lcd.print(myText[thisChar]);
      if (thisChar == 15){
        lcd.autoscroll();
      }

      delay(300);

      digitalWrite(redLEDPin, LOW);

    }

    // set the cursor to (16,1):

  
    // clear screen for the next loop:

  
    lcd.noAutoscroll();
    lcd.clear();
  }
}

 

 

Video:

Future Improvements:

As I mentioned earlier, I couldn’t add more than one prompt to this project. For future, I would like to create an array of different prompts that switches as soon as the user presses the switch. Moreover, to make the game more interesting I would like to add more switches with more LEDs to involve more than one player in the game.

Leave a Reply