Introduction: Steal the Bacon Game With Arduino

This is what you will need to make an Arduino powered steal the bacon game:

10x      LEDs
11x      330 Ohm Resistors
1x        10k Ohm Resistor
1x        Button
1x        Switch
1x        Buzzer
19x      Jumper Wires
1x        Breadboard or Perfboard
1x        Arduino Mega 2560 or Arduino Uno

This took me and my friend a few hours because we wrote the code ourselves. But, if you use the code below then it should only take you about 30 minutes to an hour.

This is the code I used:

#include "pitches.h"

int melody[] = {
  NOTE_C4, NOTE_C3, NOTE_C5};
 
//variable initialization/instantiation
int led11 = 4;
int led12 = 5;
int led13 = 6;
int led14 = 7;
int led21 = 8;
int led22 = 9;
int led23 = 10;
int led24 = 11;
int ledJackpot1 = 3;
int ledJackpot2 = 12;
int pushButtonPin = 2;
int pushSwitchPin = 40;
int buzzer = 42;
int buttonState;
long rand1;
long rand2;
long rand3;

//runs when reset is pressed, only once
void setup() {
pinMode(led11,OUTPUT);
pinMode(led12,OUTPUT);
pinMode(led13,OUTPUT);
pinMode(led14,OUTPUT);
pinMode(led21,OUTPUT);
pinMode(led22,OUTPUT);
pinMode(led23,OUTPUT);
pinMode(led24,OUTPUT);
pinMode(ledJackpot1,OUTPUT);
pinMode(ledJackpot2,OUTPUT);
pinMode(buzzer,OUTPUT);
pinMode(pushButtonPin, INPUT);
pinMode(pushSwitchPin, INPUT);
randomSeed(analogRead(0));
}

//the main function. runs infinitely or until quit by user
void loop()
{
  //get the state of the button
  buttonState = digitalRead(pushButtonPin);
  if(buttonState == HIGH){
   
    if (digitalRead(pushSwitchPin) == HIGH) {rand1 = random(1,10);} else {rand1 = random(1,5);} //new line
    //rand1 = random(1,10); this was our old line
   
    rand2 = random(1,5);
    switch(rand1){
      case 1: if( digitalRead(led11) == LOW ){digitalWrite(led11,HIGH);} else {alreadyOut(1);} break;
      case 2: if( digitalRead(led12) == LOW ){digitalWrite(led12,HIGH);} else {alreadyOut(1);} break;
      case 3: if( digitalRead(led13) == LOW ){digitalWrite(led13,HIGH);} else {alreadyOut(1);} break;
      case 4: if( digitalRead(led14) == LOW ){digitalWrite(led14,HIGH);} else {alreadyOut(1);} break;
      case 5: if( digitalRead(led11) == LOW ){digitalWrite(led11,HIGH);} else {alreadyOut(1);} break;
      case 6: if( digitalRead(led12) == LOW ){digitalWrite(led12,HIGH);} else {alreadyOut(1);} break;
      case 7: if( digitalRead(led13) == LOW ){digitalWrite(led13,HIGH);} else {alreadyOut(1);} break;
      case 8: if( digitalRead(led14) == LOW ){digitalWrite(led14,HIGH);} else {alreadyOut(1);} break;
      case 9: digitalWrite(led21,HIGH);
              digitalWrite(led22,HIGH);
              digitalWrite(led23,HIGH);
              digitalWrite(led24,HIGH);
              digitalWrite(led11,HIGH);
              digitalWrite(led12,HIGH);
              digitalWrite(led13,HIGH);
              digitalWrite(led14,HIGH);
              jackpot();
              break;
      default: break;
    }
   
    switch(rand2){
      case 1: if( digitalRead(led21) == LOW ){digitalWrite(led21,HIGH);} else {alreadyOut(2);} break;
      case 2: if( digitalRead(led22) == LOW ){digitalWrite(led22,HIGH);} else {alreadyOut(2);} break;
      case 3: if( digitalRead(led23) == LOW ){digitalWrite(led23,HIGH);} else {alreadyOut(2);} break;
      case 4: if( digitalRead(led24) == LOW ){digitalWrite(led24,HIGH);} else {alreadyOut(2);} break;
      default: break;
    }
   
    delay(300);
   
  }
 
}

//flashes green LEDs to signify jackpot
void jackpot()
{
  while(true){
  digitalWrite(ledJackpot1,HIGH);
  digitalWrite(ledJackpot2,LOW);
  tone(42, melody[0],125);
  delay(100);
  digitalWrite(ledJackpot1,LOW);
  digitalWrite(ledJackpot2,HIGH);
  tone(42, melody[1],125);
  delay(100);
  }
}









void alreadyOut(int team)
{
  if(team == 1)
{
int nop = 4;
  if(digitalRead(led11) == HIGH)
    nop-=1;
  if(digitalRead(led12) == HIGH)
    nop-=1;
  if(digitalRead(led13) == HIGH)
    nop-=1;
  if(digitalRead(led14) == HIGH)
    nop-=1;
   
  switch(nop){
    case 0: if (digitalRead(pushSwitchPin) == HIGH) {jackpot();} else {break;}
    case 1: digitalWrite(led11,HIGH);
            digitalWrite(led12,HIGH);
            digitalWrite(led13,HIGH);
            digitalWrite(led14,HIGH);
            break;
    case 2: rand3 = random(1,3);
            if(digitalRead(led11) == HIGH)
            {
              if(digitalRead(led12) == HIGH)
              {
                if(rand3 == 1){
                  digitalWrite(led13,HIGH); }
                else{
                  digitalWrite(led14,HIGH); }
              }
              if(digitalRead(led13) == HIGH)
              {
                if(rand3 == 1){
                  digitalWrite(led12,HIGH); }
                else{
                  digitalWrite(led14,HIGH); }
              }
              if(digitalRead(led14) == HIGH)
              {
                if(rand3 == 1){
                  digitalWrite(led12,HIGH); }
                else{
                  digitalWrite(led13,HIGH); }
              }
            }
            if(digitalRead(led12) == HIGH)
            {
              if(digitalRead(led13) == HIGH)
              {
                if(rand3 == 1){
                  digitalWrite(led11,HIGH); }
                else{
                  digitalWrite(led14,HIGH); }
              }
              if(digitalRead(led14) == HIGH)
              {
                if(rand3 == 1){
                  digitalWrite(led11,HIGH); }
                else{
                  digitalWrite(led13,HIGH); }
              }
            }
            break;
    case 3: rand3 = random(1,4);
          if(digitalRead(led11) == HIGH)
            {
            if(rand3 == 1){
              digitalWrite(led12,HIGH); }
            if(rand3 == 2){
              digitalWrite(led13,HIGH);  }
            if(rand3 == 3){
              digitalWrite(led14,HIGH);}
            }
           if(digitalRead(led12) == HIGH)
            {
            if(rand3 == 1){
              digitalWrite(led11,HIGH); }
            if(rand3 == 2){
              digitalWrite(led13,HIGH); }
            if(rand3 == 3){
              digitalWrite(led14,HIGH);}
            }
            if(digitalRead(led13) == HIGH)
            {
            if(rand3 == 1){
              digitalWrite(led11,HIGH); }
            if(rand3 == 2){
              digitalWrite(led12,HIGH);  }
            if(rand3 == 3){
              digitalWrite(led14,HIGH); }
            }
            if(digitalRead(led14) == HIGH)
            {
            if(rand3 == 1){
              digitalWrite(led11,HIGH); }
            if(rand3 == 2){
              digitalWrite(led12,HIGH);  }
            if(rand3 == 3){
              digitalWrite(led13,HIGH); }
            }
            break;
  }
} else
{
// team 2
int nop = 4;
  if(digitalRead(led21) == HIGH)
    nop-=1;
  if(digitalRead(led22) == HIGH)
    nop-=1;
  if(digitalRead(led23) == HIGH)
    nop-=1;
  if(digitalRead(led24) == HIGH)
    nop-=1;
   
  switch(nop){
    case 0: if (digitalRead(pushSwitchPin) == HIGH) {jackpot();} else {break;}
    case 1: digitalWrite(led21,HIGH);
            digitalWrite(led22,HIGH);
            digitalWrite(led23,HIGH);
            digitalWrite(led24,HIGH);
            break;
    case 2: rand3 = random(1,3);
            if(digitalRead(led21) == HIGH)
            {
              if(digitalRead(led22) == HIGH)
              {
                if(rand3 == 1)
                  digitalWrite(led23,HIGH);
                else
                  digitalWrite(led24,HIGH);
              }
              if(digitalRead(led23) == HIGH)
              {
                if(rand3 == 1)
                  digitalWrite(led22,HIGH);
                else
                  digitalWrite(led24,HIGH);
              }
              if(digitalRead(led24) == HIGH)
              {
                if(rand3 == 1)
                  digitalWrite(led22,HIGH);
                else
                  digitalWrite(led23,HIGH);
              }
            }
            if(digitalRead(led22) == HIGH)
            {
              if(digitalRead(led23) == HIGH)
              {
                if(rand3 == 1)
                  digitalWrite(led21,HIGH);
                else
                  digitalWrite(led24,HIGH);
              }
              if(digitalRead(led24) == HIGH)
              {
                if(rand3 == 1)
                  digitalWrite(led21,HIGH);
                else
                  digitalWrite(led23,HIGH);
              }
            }
            break;
    case 3: rand3 = random(1,4);
          if(digitalRead(led21) == HIGH)
            {
            if(rand3 == 1)
              digitalWrite(led22,HIGH);
            if(rand3 == 2)
              digitalWrite(led23,HIGH); 
            if(rand3 == 3)
              digitalWrite(led24,HIGH);
            }
           if(digitalRead(led22) == HIGH)
            {
            if(rand3 == 1)
              digitalWrite(led21,HIGH);
            if(rand3 == 2)
              digitalWrite(led23,HIGH) ;
            if(rand3 == 3)
              digitalWrite(led24,HIGH);
            }
            if(digitalRead(led23) == HIGH)
            {
            if(rand3 == 1)
              digitalWrite(led21,HIGH);
            if(rand3 == 2)
              digitalWrite(led22,HIGH) ;
            if(rand3 == 3)
              digitalWrite(led24,HIGH);
            }
            if(digitalRead(led24) == HIGH)
            {
            if(rand3 == 1)
              digitalWrite(led21,HIGH);
            if(rand3 == 2)
              digitalWrite(led22,HIGH)  ;
            if(rand3 == 3)
              digitalWrite(led23,HIGH);
            }
            break;
  }
}
}

Comments

author
JSTArollin (author)2013-06-04

So steal the bacon works by two teams lining up a certain distance from the bacon (usually a towel) each person is then assigned a number. When your number is called you run, grab the bacon, and try to get back to your side before anyone from the other team can tag you. This device selects a random number for each team by lighting up an LED that corresponds to the players number. The green LEDs flash and alarm goes off when there is a jackpot which means everybody runs for it.

author
WWC (author)2013-06-02

How do you play the game?

About This Instructable

1,001views

7favorites

License:

More by JSTArollin:T-Shirt Wall ArtSteal the Bacon Game with Arduino6 LED Pendulum with Arduino
Add instructable to: