arduinoardent
Published

The Yes Or No Game

This is a Program where I display a Yes Or No Question with the help of my LCD and Asking the User to answer with help of Buttons.

IntermediateFull instructions provided875
The Yes Or No Game

Things used in this project

Hardware components

Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
You can have an LCD with a I2C board to make it easier to wire up
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Switch Actuator, Head for spring return push-button
Switch Actuator, Head for spring return push-button
×3
Arduino UNO
Arduino UNO
×1
Jumper wires (generic)
Jumper wires (generic)
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1

Story

Read more

Custom parts and enclosures

Lego LCD stand

This is a Lego stand which is covered with Bubble Wrap blocks inside to protect my LCD from any damage.

Schematics

Circuit Diagram

I made it using Fritzing and it was very useful

Code

Circuit Code

Arduino
I wrote this code on my own spending more than 3 hours . If you want to support me then you can go to youtube and Subscribe to my channel
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <string.h>
//defining the Pins
#define LeftButton      10
#define RightButton     8
#define EnterButton     9
#define RGB_R           5
#define RGB_G           6
#define RGB_B           7
//defining the variables for necesary calculation
int timemovedRight = 0;
int timemovedLeft = 0;
int RightButVal;
int LeftButVal;
int EnterButVal;
int Previousmove ;

LiquidCrystal_I2C lcd(0x27,16,2);
//Making a sub program because of an error in my LCD Library    Remove this if you want to
void lcdPrintln1(char *str)
{ 
  int i = 0;
  for(i=0;i<16;i++)
  {
    lcd.setCursor(i,0);
    lcd.print(str[i]);
  }
}
//Making a sub program because of an error in my LCD Library    Remove this if you want to
void lcdPrintln2(char *str)
{
  int i = 0;
  for(i=0;i<16;i++)
  {
    lcd.setCursor(i,1);
    lcd.print(str[i]);
  }
}
//Making a custom arrow poiner charachter
byte ArrowMark[8] = {
  0b00000,
  0b01100,
  0b01110,
  0b01111,
  0b01111,
  0b01110,
  0b01100,
  0b00000
};
//Making a custom charachter to turn off all the respective LEDS at a ceratin point
byte Deletion[8] ={
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

void setup()
{
  Serial.begin(9600);
  lcd.init();                      // initialize the lcd 
  lcd.createChar(0,ArrowMark);     //Defining the Char
  lcd.createChar(1,Deletion);
  lcd.backlight();
  lcdPrintln1("Like This Video?");//Make this into 'lcd.print("Like This Video?");' if you want to
  lcdPrintln2("   Yes       No ");//Make this into 'lcd.print("   Yes       No ");' if you want to
  lcd.home();
  lcd.setCursor(1,1);
  lcd.write(0); 
}
//Making a Sub program for my RGB 
void RGBCol(int R,int G,int B){
  analogWrite(RGB_R,R);
  analogWrite(RGB_G,G);
  analogWrite(RGB_B,B);
}

//all of the calculations happens below
void loop()
{
  RightButVal = digitalRead(RightButton); 
  LeftButVal = digitalRead(LeftButton);
  EnterButVal = digitalRead(EnterButton);
  if(RightButVal == 0 && Previousmove != 1){
    lcd.home();
    lcd.setCursor(1,1);
    lcd. write(1);
    lcd.setCursor(10,1);
    lcd.write(0);
    timemovedRight +=1;
    Previousmove = 1;
  }
  if(LeftButVal == 0 && Previousmove != 0){
    lcd.home();
    lcd.setCursor(10,1);
    lcd. write(1);
    lcd.setCursor(1,1);
    lcd.write(0);
    timemovedLeft +=1;
    Previousmove = 0;
  }
  if(EnterButVal == 0){
    if(timemovedRight - timemovedLeft == 0){
      Serial.println("Yes");
      RGBCol(0,100,0);
    }
    else{
      Serial.println("No");
      RGBCol(100,0,0);   
    }
  }
    
}

Credits

arduinoardent
1 project • 0 followers

Comments