Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Dawn DupriestBrayden Vos
Published © CC BY

Whack-a-Button

It's like Whack-a-Mole. Just try to stop playing - we dare you!

BeginnerFull instructions provided4 hours981
Whack-a-Button

Things used in this project

Hardware components

Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×3
SparkFun RedBoard
SparkFun RedBoard
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×3
Resistor 330 ohm
Resistor 330 ohm
×3
LED (generic)
LED (generic)
×3
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Wiring Diagram

LCD Screen, LED's and buttons.

Code

Code

Arduino
Copy and paste into Arduino IDE
long randNumber;

float num;
#include <LiquidCrystal.h>


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  
  lcd.begin(16, 2);
  lcd.print("hello, world!");
   pinMode(13, OUTPUT);
  //red led
  pinMode(7, OUTPUT);
  //green led
  pinMode(9, OUTPUT);
  //yellow led
  pinMode(8, INPUT);
  //RED button
  pinMode(0, INPUT);
  //blue button
  pinMode(6, INPUT);
  //green button
  randomSeed(analogRead(0));
  
}

void loop() {
  randNumber = random(3);

  if(randNumber == 1)
  {
    digitalWrite(7, HIGH);
    while(digitalRead(6) == HIGH)
    {
     
    }
    
    digitalWrite(7, LOW);
    num = num + 100;
    
  }

  if(randNumber == 0)
  {
    digitalWrite(13, HIGH);
    while(digitalRead(8) == HIGH)
    {
     
    }
  
    digitalWrite(13, LOW);
    num = num + 100;
    
  }

  if(randNumber == 2)
  {
    digitalWrite(9, HIGH);
    while(digitalRead(0 == HIGH))
    {
     
    }
   
    digitalWrite(7, LOW);
    num = num + 100;
    
  }
  lcd.setCursor(0, 1);
  lcd.print(num);
}

Credits

Dawn Dupriest

Dawn Dupriest

4 projects • 5 followers
Middle School Computer Science teacher, Feminist, Maker. 2012 Poudre School District Teacher of the Year. 2016 Allen Distinguished Educator.
Brayden Vos

Brayden Vos

0 projects • 1 follower
Thanks to Lucas Snyder.

Comments