Introduction: Guess/pick AttinyCard

Pick attiny card is a random number generator that represents guessing a card in a deck of cards or you could change the setup code to cut a deck of "cards" to see who goes first in a card game.

Step 1: Hardware

Attiny85
Arduino as ISP programmer
5v power supply
Shift register LCD

Tactile momentary switch
10kohm resistor

Step 2: Software

Sketch asks you to pick a card presumably from a deck of 52 cards. Press the button to stop the random sequence. Displays the number randomly picked out of 52 on first line. Card represented on second line.

#include <LiquidCrystal595.h>
LiquidCrystal595 lcd(0,1,2);

int val;                       //random card value
const int button = 4;                //button pin
int buttonState = 0;              

void setup() {
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("CHOOSE A CARD");
  //lcd.print("CUT ");
  lcd.setCursor(0,1);
  lcd.print("REMEMBER IT");
  //lcd.print("THE DECK");
  pinMode(button, INPUT); 
  delay(5000);
}

void loop() {
val = random(1,52);
buttonState = digitalRead(button);

if (buttonState == HIGH){
  lcd.clear();
  lcd.setCursor(6,0);
  lcd.print(val);
 
switch (val) {
    case 1:lcd.setCursor(4,1);
    lcd.print("ACE S");
      break;
    case 2:lcd.setCursor(4,1);
    lcd.print("2 S");
      break;
    case 3:lcd.setCursor(4,1);
    lcd.print("3 S");
      break;
    case 4:lcd.setCursor(4,1);
    lcd.print("4 S");
      break;
    case 5:lcd.setCursor(4,1);
    lcd.print("5 S");
      break;
    case 6:lcd.setCursor(4,1);
    lcd.print("6 S");
      break;
    case 7:lcd.setCursor(4,1);
    lcd.print("7 S");
      break;
    case 8:lcd.setCursor(4,1);
    lcd.print("8 S");
      break;
    case 9:lcd.setCursor(4,1);
    lcd.print("9 S");
      break;
    case 10:lcd.setCursor(4,1);
    lcd.print("10 S");
      break;
    case 11:lcd.setCursor(4,1);
    lcd.print("JACK S");
      break;
    case 12:lcd.setCursor(4,1);
    lcd.print("QUEEN S");
      break;
    case 13:lcd.setCursor(4,1);
    lcd.print("KING S");
      break;  
    case 14:lcd.setCursor(4,1);
    lcd.print("ACE D");
      break;
    case 15:lcd.setCursor(4,1);
    lcd.print("2 D");
      break;
    case 16:lcd.setCursor(4,1);
    lcd.print("3 D");
      break;
    case 17:lcd.setCursor(4,1);
    lcd.print("4 D");
      break;
    case 18:lcd.setCursor(4,1);
    lcd.print("5 D");
      break;
    case 19:lcd.setCursor(4,1);
    lcd.print("6 D");
      break;
    case 20:lcd.setCursor(4,1);
    lcd.print("7 D");
      break;
    case 21:lcd.setCursor(4,1);
    lcd.print("8 D");
      break;
    case 22:lcd.setCursor(4,1);
    lcd.print("9 D");
      break;
    case 23:lcd.setCursor(4,1);
    lcd.print("10 D");
      break;
    case 24:lcd.setCursor(4,1);
    lcd.print("JACK D");
      break;
    case 25:lcd.setCursor(4,1);
    lcd.print("QUEEN D");
      break;
    case 26:lcd.setCursor(4,1);
    lcd.print("KING D");
      break;
    case 27:lcd.setCursor(4,1);
    lcd.print("ACE C");
      break;
    case 28:lcd.setCursor(4,1);
    lcd.print("2 C");
      break;
    case 29:lcd.setCursor(4,1);
    lcd.print("3 CLUB");
      break;
    case 30:lcd.setCursor(4,1);
    lcd.print("4 C");
      break;
    case 31:lcd.setCursor(4,1);
    lcd.print("5 C");
      break;
    case 32:lcd.setCursor(4,1);
    lcd.print("6 C");
      break;
    case 33:lcd.setCursor(4,1);
    lcd.print("7 C");
      break;
    case 34:lcd.setCursor(4,1);
    lcd.print("8 C");
      break;
    case 35:lcd.setCursor(4,1);
    lcd.print("9 C");
      break;
    case 36:lcd.setCursor(4,1);
    lcd.print("10 C");
      break;
    case 37:lcd.setCursor(4,1);
    lcd.print("JACK C");
      break;
    case 38:lcd.setCursor(4,1);
    lcd.print("QUEN C");
      break;
    case 39:lcd.setCursor(4,1);
    lcd.print("KING C");
      break;
    case 40:lcd.setCursor(4,1);
    lcd.print("ACE H");
      break;
    case 41:lcd.setCursor(4,1);
    lcd.print("2 H");
      break;
    case 42:lcd.setCursor(4,1);
    lcd.print("3 H");
      break;
    case 43:lcd.setCursor(4,1);
    lcd.print("4 H");
      break;
    case 44:lcd.setCursor(4,1);
    lcd.print("5 H");
      break;
    case 45:lcd.setCursor(4,1);
    lcd.print("6 H");
      break;
    case 46:lcd.setCursor(4,1);
    lcd.print("7 H");
      break;
    case 47:lcd.setCursor(4,1);
    lcd.print("8 H");
      break;
    case 48:lcd.setCursor(4,1);
    lcd.print("9 H");
      break;
    case 49:lcd.setCursor(4,1);
    lcd.print("10 H");
      break;
    case 50:lcd.setCursor(4,1);
    lcd.print("JACK H");
      break;
    case 51:lcd.setCursor(4,1);
    lcd.print("QUEEN H");
      break;
    case 52:lcd.setCursor(4,1);
    lcd.print("KING H");
      break;
  }
 } 
}

Step 3: Results

This is my second instructable using my already made 5V power supply, Attiny programmer, and LCD shift register breadboarded circuits. This is a more practical real world use of a microcontroller. Very simple. A momentary button and resistor are connected to one of the pins of the Attiny85. A greeting first displays on the screen for about 5 seconds and then the random number generator starts. Pressing the button stops the random number generator and the selected value and the corresponding card is displayed on the LCD.

Here's a video on Instagram @kayohzee

Little card guessing game I wrote for #attiny #arduino

Little card guessing game I wrote for #attiny #arduino

A video posted by John Cosgrove II (@kayohzee) on Jun 21, 2015 at 11:24pm PDT

    Comments

    About This Instructable

    629views

    5favorites

    License:

    Bio: Electronic Technician, U.S. Navy veteran. Trying to keep up to date on the new tech.
    More by koz12:Guess/pick AttinyCardAttiny85-shiftlcd Direction Detection
    Add instructable to: