Advertisement
CreadPag

Juego de pulsadores

Oct 11th, 2016
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. #include <LCD.h>
  2. #include <LiquidCrystal_I2C.h>
  3.     //By creadpag
  4.  
  5.     // initialize the library with the numbers of the interface pins
  6.  
  7.     LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  
  8.  
  9.     const int button1 = 7;
  10.  
  11.     const int button2 = 8;
  12.  
  13.     const int button3 = 9;
  14.  
  15.     const int button4 = 10;
  16.  
  17.  
  18.     int button1state = 0;
  19.  
  20.     int button2state = 0;
  21.  
  22.     int button3state = 0;
  23.  
  24.     int button4state = 0;
  25.  
  26.  
  27.     int check = 0;
  28.  
  29.  
  30.     int unlock_var = 0;
  31.  
  32.     int unlock_code = 100;
  33.  
  34.     int temp_num;
  35.  
  36.     int gate = 0;
  37.  
  38.  
  39.     void setup() {
  40.  
  41.      
  42.  
  43.       pinMode(button1, INPUT);
  44.  
  45.       pinMode(button2, INPUT);
  46.  
  47.       pinMode(button3, INPUT);
  48.  
  49.       pinMode(button4, INPUT);
  50.  
  51.       // set up the LCD's number of columns and rows:
  52.  
  53.       lcd.begin(16, 2);
  54.  
  55.       // Print a message to the LCD.
  56.  
  57.       lcd.print("System State:");
  58.  
  59.     }
  60.  
  61.  
  62.  
  63.     void loop(){
  64.  
  65.       // read the state of the pushbutton value:
  66.  
  67.       button1state = digitalRead(button1);
  68.  
  69.       button2state = digitalRead(button2);
  70.  
  71.       button3state = digitalRead(button3);
  72.  
  73.       button4state = digitalRead(button4);
  74.  
  75.      
  76.  
  77.     //  lcd.print("                   ");
  78.  
  79.     //  // check if the pushbutton is pressed.
  80.  
  81.     //  // if it is, the buttonState is HIGH:
  82.  
  83.     //  if (button1state == HIGH) {    
  84.  
  85.     //    // show "yes" message
  86.  
  87.     //    lcd.setCursor(0,1);
  88.  
  89.     //    lcd.print("Pressed");
  90.  
  91.     //  }
  92.  
  93.     //  else {
  94.  
  95.     //    // show "no" message
  96.  
  97.     //    lcd.setCursor(0,1);
  98.  
  99.     //    lcd.print("NOT Pressed");
  100.  
  101.     //  }
  102.  
  103.  
  104.  
  105.  
  106.          lcd.setCursor(0,1);
  107.  
  108.          lcd.print("Waiting...        ");
  109.  
  110.          
  111.  
  112.          if(button1state == HIGH)
  113.  
  114.          {
  115.  
  116.            unlock_var = 26;
  117.  
  118.            lcd.setCursor(0,1);
  119.  
  120.            lcd.print("Reading...");
  121.  
  122.            delay(500);
  123.  
  124.          }
  125.  
  126.          if(button2state == HIGH)
  127.  
  128.          {
  129.  
  130.            unlock_var = unlock_var*3;
  131.  
  132.            lcd.setCursor(0,1);
  133.  
  134.            lcd.print("Reading...");
  135.  
  136.            delay(500);
  137.  
  138.          }
  139.  
  140.          if(button3state == HIGH)
  141.  
  142.          {
  143.  
  144.            temp_num = unlock_var;
  145.  
  146.            temp_num = temp_num/2;
  147.  
  148.            temp_num = temp_num-17;
  149.  
  150.            unlock_var = unlock_var + temp_num;
  151.  
  152.            lcd.setCursor(0,1);
  153.  
  154.            lcd.print("Reading...");
  155.  
  156.            delay(500);
  157.  
  158.          }
  159.  
  160.          
  161.  
  162.         if(button4state == HIGH)
  163.  
  164.         {
  165.  
  166.           check = 1;
  167.  
  168.         }
  169.  
  170.        
  171.  
  172.        if(check == 1)
  173.  
  174.        {
  175.  
  176.             lcd.setCursor(0,1);
  177.  
  178.             lcd.print("Checking Code...");
  179.  
  180.             delay(1000);
  181.  
  182.            
  183.  
  184.            if(unlock_var == unlock_code)
  185.  
  186.            {
  187.  
  188.               lcd.setCursor(0,1);
  189.  
  190.               lcd.print("Access Granted    ");
  191.  
  192.               delay(10000); //unlock delay
  193.  
  194.               unlock_var = 0;
  195.  
  196.            }
  197.  
  198.            else
  199.  
  200.            {
  201.  
  202.              lcd.setCursor(0,1);
  203.  
  204.              lcd.print("Access Denied     ");
  205.  
  206.              delay(1500);
  207.  
  208.              unlock_var = 0;
  209.  
  210.              check = 0;
  211.  
  212.            }
  213.  
  214.          
  215.  
  216.        }
  217.  
  218.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement