Created
November 13, 2011 15:13
-
-
Save shuhei/1362207 to your computer and use it in GitHub Desktop.
Rock, Paper, Scissors with Arduino, tact switch and LCD Shield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
int buttonPin = 7; | |
boolean pressedBefore = false; | |
boolean standby = true; | |
// Pin numbers connected to LCD's RS, E, DB4, DB5, DB6 and DB7 | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
void setup() { | |
pinMode(buttonPin, INPUT); | |
// 16 columns and 2 rows | |
lcd.begin(16, 2); | |
lcd.print("Let's Janken!"); | |
randomSeed(micros()); | |
} | |
void loop() { | |
if (digitalRead(buttonPin) > 0) { | |
if (pressedBefore == false) { | |
standby = false; | |
} | |
pressedBefore = true; | |
} else { | |
pressedBefore = false; | |
} | |
lcd.setCursor(0, 1); | |
if (standby) { | |
// Stand by | |
lcd.print("Press button."); | |
} else { | |
// Count down | |
lcd.setCursor(0, 1); | |
lcd.print("3... "); | |
delay(1000); | |
lcd.setCursor(0, 1); | |
lcd.print("2... "); | |
delay(1000); | |
lcd.setCursor(0, 1); | |
lcd.print("1... "); | |
delay(1000); | |
// Janken! | |
lcd.setCursor(0, 1); | |
switch(random(0, 2)) { | |
case 0: | |
lcd.print("Gu! "); | |
break; | |
case 1: | |
lcd.print("Choki!"); | |
break; | |
case 2: | |
lcd.print("Pa! "); | |
break; | |
} | |
delay(5000); | |
standby = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment