Blogger Themes

Search This Blog

www.embeddedstudy.com | Copyright © 2017 | All Rights Reserved | Nithin Pradeep . Theme images by Storman. Powered by Blogger.

Follow by Email

Popular KOZHI

Sponsor

Download

Blogger Tricks

FEATURED

What is an Embedded System?

An embedded system is a combination of hardware and software that is designed to carry out a certain task or tasks, meaning it has a s...

JOIN THE TEAM

Popular Posts

Wikipedia

Search results

Search This Blog

Social

More Links

Social

ad

ads

Monday, 9 October 2017

Mind Magic Game in Arduino - Birthday Finder

Hello Everyone....
In this Project i am going to show you ,How to make a simple magic game on Arduino(Nano or UNO).You can trick your friends using this project and be a star in front of them.



















Watch the video:


I have described in detail about the working of this project in this video
Watch it...

The Components Required:


​For doing this Project You essentially need components like
1 >> Arduino NANO or UNO.
2 >> HD44780 16x2 character LCD.
3 >>  4x4 keypad matrix.
4 >> Breadboard and jumper wires.











Arduino NANO-The Arduino Nano is a small, complete, and breadboard-friendly board based on the ATmega328; offers the same connectivity and specs of the UNO board in a smaller form factor.
The Arduino Nano is programmed using the Arduino Software (IDE), our Integrated Development Environment common to all our boards and running both online and offline.
HD44780 16x2 character LCD-The Hitachi HD44780 LCD controller is an alphanumeric dot matrix liquid crystal display (LCD) controller developed by Hitachi that was commonly used during the MCS-51 era. It was made commercially available around year 1987.The character set of the controller includes ASCII characters, Japanese Kana characters, and some symbols in two 28 character lines. Using an extension driver, the device can display up to 80 characters.
4x4 keypad matrix - 
{
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},   
  {'*','0','#','D'}   };
The pattern of key pad is as shown above.

The Connection Diagram:



The Code:

Or copy the code below:
/*

   Demonstrates the use a 16x2 LCD display and
  4x4 LCD display.  T

   The  Arduino circuit connection for LCD:

   * LCD RS  pin to analog pin A0

   * LCD  Enable pin to analog pin A1

   * LCD D4  pin to analog pin A2

   * LCD D5  pin to analog pin A3

   * LCD D6  pin to analog pin A4

   * LCD D7  pin to analog pin A5

   The  Arduino circuit connection for MAtrix Key Pad:

   * ROW1 pin  to digital pin 5

   * ROW2 pin  to digital pin 4

   * ROW3 pin  to digital pin 3

   * ROW4 pin  to digital pin 2

   * COLUMN1  pin to digital pin 6

   * COLUMN2  pin to digital pin 7

   * COLUMN3  pin to digital pin 8

   * COLUMN4  pin to digital pin 9

   */
   char month[12][10]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
   int stc=0,num1,age,mnt;
char str[10];
  // include the library code:
#include <Keypad.h>
#include <LiquidCrystal.h>
  LiquidCrystal lcd(A0,A1,A2,A3,A4,A5);
  const byte ROWS = 4; // Four rows
  const byte COLS = 4; // Four columns
  char keys[ROWS][COLS] = 
  { 
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
  };
  // Connect keypad ROW0, ROW1, ROW2 and ROW3 to
  byte rowPins[ROWS] = { 5, 4, 3, 2 };
  // Connect keypad COL0, COL1, COL2 and COL3 to
  byte colPins[COLS] = { 6, 7, 8, 9 }; 
 byte heart[8] = {
   0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

byte heart1[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00100,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

byte heart2[8] = {
  0b00000,
  0b00000,
  0b00100,
  0b01110,
  0b00100,
  0b00000,
  0b00000,
  0b00000
};
byte heart3[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b11111,
  0b01110,
  0b00100,
  0b00000,
  0b00000
};
byte heart4[8] = {
  0b00000,
  0b00000,
  0b01110,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};



  Keypad kpd = Keypad( makeKeymap(keys), rowPins,
  colPins, ROWS, COLS );

  void setup() 
  {
  lcd.begin(16, 2);
  lcd.createChar(0, heart1);
   lcd.createChar(1, heart2);
   lcd.createChar(2, heart3);
   lcd.createChar(3, heart4);
   lcd.createChar(4, heart);
  }


  void loop() 
  {
    char key= kpd.getKey();
   lcd.setCursor(0, 0);
   rst:
    lcd.print("MAGIC GAME!!!");
  lcd.setCursor(0, 1);
  lcd.print("PRESS * TO BEGIN");
  
if(key=='*')  
  { 
  here:
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("THINK A MONTH NO");
  lcd.setCursor(0, 1);
  lcd.print("jan:1,feb:2...");
  delay(5000);
  lcd.clear();
      while(1)
          {
            lcd.setCursor(0, 0);
            lcd.print("Think 1 age also");
            lcd.setCursor(0, 1);
            lcd.print("now press #");
            char key= kpd.getKey();
            if(key=='#')  
               { 
                bere:
                lcd.clear();
                lcd.print("now do some math");
                lcd.setCursor(0, 1);
                lcd.print("((num*2)+5)*50");
                delay(8000);
                lcd.clear();
                  while(1)
                  {
                  lcd.setCursor(0, 0);
                  lcd.print("add reslt to age");
                   lcd.setCursor(0, 1);
                  lcd.print("and press #");
                  char key= kpd.getKey();
                     if(key=='#')
                      {
                        jere:
                        lcd.clear();
                        while(1)
                        {
                          
                         static int num=0;
                          lcd.setCursor(0, 0);
                        lcd.print("enter that num:");
                        lcd.setCursor(8, 1);
                        lcd.print("&Press *");
                         char key= kpd.getKey();
                        if(key=='1' || key=='2' || key=='3' || key=='4' || key=='5' || key=='6' || key=='7' || key=='8' || key=='9' || key=='0' )
                        {
                           lcd.setCursor(stc, 1);
                        lcd.print(key);
                        stc++;
                        num=(num*10)+(key-48);
                        
                        }
      
                        if(key=='*')
                        {
                          stc=0;
                          lcd.clear();
                          lcd.setCursor(0, 0);
                        lcd.print("calculating");
                        for(int i=0,index=0;i<10;i=i+2)
                        {
                        lcd.setCursor(i, 1);
                        lcd.write(byte(index++));
                        delay(1500);
                        }
                        delay(1500);
                        lcd.clear();
                        lcd.print("Now I will read..");lcd.setCursor(0, 1);lcd.print("ur Mind & say..");delay(3000);lcd.clear();
                          num1=num-250;age=num1%100;mnt=num1/100;
                                  while(1)
                                  {
                                  lcd.setCursor(0, 0);
                                lcd.print("AGE=");lcd.setCursor(5, 0);lcd.print(String(age));lcd.print(" years");
                                lcd.setCursor(0, 1);
                                   lcd.print("MONTH=");
                                   if(mnt>0 && mnt<12)
                                  {
                                   lcd.setCursor(7, 1);lcd.print(String(month[mnt-1]));
                                  }
                                   else
                                            {
                                              lcd.clear();
                                             lcd.setCursor(5, 0);
                                             lcd.print("You Cheated");
                                             lcd.setCursor(6, 1);
                                              lcd.print("Bitch!!");delay(4000);
                                              goto here;
                                            }
                                   
                                                                       
                                    char key= kpd.getKey();
                                    if(key =='A')
                                    goto rst;
                                    else if(key=='B')
                                    {lcd.clear();num=0;stc=0;goto jere;}
                                   
                                  }      
                        }
                         if(key=='A')
                          goto here;
                          else if(key=='B')
                          {lcd.clear();stc=0;num=0;goto jere;}
                        }      
    }    
    else if(key=='A')
    goto here;
    else if(key=='B')
    goto bere;
    }
    
    }
      }
    }  

  }


The Code Explanation:

This code essentially works on a linear mathematical equation ..
in loop function i have written many hirarcheal while (1) loops for each stages.
I have also coded A to work as reset and B to go back to the previous step,

In the innermost loop of the code i have written the math logic
num=(num*10)+(key-48); -------means that each key press the ascii value is converted to the integer format and converting in to a final whole number until star key is pressed
and (num - 250) will give you age and birth month.To know that see the video.
ie num%100 = age, num/100 gives you the month.
That is it for the code
if you have any doubt feel free to contact me my mail id is nithinpradeep786@hotmail.com

Thank you,and visit my website daily for more of these kinds of projects and training

0 on: "Mind Magic Game in Arduino - Birthday Finder"