The best tools to make your project dreams come true

Login or Signup
USD


By Maker.io Staff

Adafruit Circuit Playground - Bop It 2 Player Game!

A fun game in which I have been wanting to create for a while now, based on the popular kids game called Bop It. Bop It has a number of inputs which can be pulling a handle, twisting cranks, spin-able wheel and toggle a switch. The commands are issued through the speaker in the middle and every interaction creates more speed.

Bop it

Whilst I didn’t have some of the inputs nor was there a speaker on the Circuit Playground it has enough features for me to create my own variation and I even created a 2 player game, which gives the score in binary.

Interaction

I wanted the players to interact with the sensors on board the Circuit Playground, which will be indication by the colour of the LEDs around the board. The players would have to do one of the following actions to move on to the next one:

  • Green LED – Gyro Sensor (Z-axis)
  • Red LED – Temperature sensor
  • Blue LED – Sound sensor
  • Yellow LED – Light Sensor 

Scoring System

The score for each player is determined by the time it takes to complete 10 interactions to the nearest second. The player turn is decided by the slide switch on the Circuit Playground, left is player 1 and right is player two. When playing the game, after player 1 has their score displayed make sure you then switch the slide switch to the right position for player 2 to begin their turn. You can start the game with the left button.

The only way to display the score was either using the buzzer to or the LEDs around the board. At the end of each player turn the score is displayed using the binary format starting with the first LED next to the light sensor and moving around the board in an ant-clockwise direction.

Binary Score

At any point before or after the game you can see which player is winning by pressing and holding down the right button which will flash the left or right side of the LEDs. The left side of the LEDs will indicate that player 1 is winning and the right side will indicate that player 2 is winning, if all the LEDs flash then it is a draw.

Player Winner

At the end of both turns for player 1 and 2 you can reset the score back to zero by holding down the right button and then press the left. A successful reset will be shown by all LEDs lit up in multi-coloured pattern.

Reset Score

Copy Code
long randNumber;
int temp;
int val;
int number;
int score;
boolean state;
int light;
uint8_t pixeln = 0;
int sound;
int shake;
unsigned long lastmillis = 0;
boolean game;
const byte numPins = 7;
byte pins = {0, 1, 2, 3, 4, 5, 6, 7};


int player1 = 0;
int player2 = 0;
#include "Adafruit_CircuitPlayground.h"

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
CircuitPlayground.begin();
CircuitPlayground.clearPixels();
//timer();

}

void loop() {
if (digitalRead(4) == HIGH && digitalRead(19) == LOW){
Serial.println("Button Pressed");
lastmillis = millis();

for (int i=0; i < 10; i ){
randNumber = random(4);
//Serial.println("Loop");


switch (randNumber){
//Serial.println("Switch");
case 0:
while (pixeln < 10){
CircuitPlayground.setPixelColor(pixeln , 255,0,0);
CircuitPlayground.strip.show();
}
pixeln = 0;
state = true;
temp = analogRead(A0);
//Serial.println(temp);
while (state == true) {
val = analogRead(A0);
number = val - temp;
if (number > 10){
score ;
state = false;
//Serial.println("Temperature");
delay(500);
}

}
break;
case 1:
while (pixeln < 10){
CircuitPlayground.setPixelColor(pixeln , 127,127,0);
CircuitPlayground.strip.show();
}
pixeln = 0;
state = true;
light = analogRead(A5);
//Serial.println(light);
while (state == true) {
val = analogRead(A5);
number = light - val;
if (number > 20){
score ;
state = false;
//Serial.println(number);
delay(500);
}

}
break;
case 2:
while (pixeln < 10){
CircuitPlayground.setPixelColor(pixeln , 0,0,255);
CircuitPlayground.strip.show();
}
pixeln = 0;
state = true;
sound = analogRead(A4);
//Serial.println(sound);
while (state == true) {
val = analogRead(A4);
number = val - sound;
if (number > 50){
score ;
state = false;
//Serial.println(number);
delay(500);
}

}
break;
case 3:
while (pixeln < 10){
CircuitPlayground.setPixelColor(pixeln , 0,255,0);
CircuitPlayground.strip.show();

}
pixeln = 0;

val = CircuitPlayground.motionZ();
//Serial.println(val);
state = true;
while (state == true) {
shake = CircuitPlayground.motionZ();
number = val - shake;
//Serial.println(number);
if (number > 15 or number < -15){
score ;
state = false;
//Serial.println("shake");
delay(500);
}

}
break;
case 4:
CircuitPlayground.clearPixels();
CircuitPlayground.setPixelColor(0, 0,255,0);
CircuitPlayground.setPixelColor(1, 0,255,0);
CircuitPlayground.strip.show();
delay(3000);

break;
case 5:
CircuitPlayground.clearPixels();
CircuitPlayground.setPixelColor(3, 255,0,0);
CircuitPlayground.setPixelColor(4, 255,0,0);
CircuitPlayground.strip.show();
delay(3000);
break;
case 6:
CircuitPlayground.clearPixels();
CircuitPlayground.setPixelColor(5, 127,0,255);
CircuitPlayground.setPixelColor(6, 127,0,255);
CircuitPlayground.strip.show();
delay(3000);
break;
case 7:
CircuitPlayground.clearPixels();
CircuitPlayground.setPixelColor(8, 255,128,0);
CircuitPlayground.setPixelColor(9, 255,128,0);
CircuitPlayground.strip.show();
delay(3000);

}
}
if (CircuitPlayground.slideSwitch()) {
player1 = (millis() - lastmillis) / 1000;
Serial.println(player1);
CircuitPlayground.clearPixels();
byte num = player1;
for (byte i=0; i < numPins; i ){
byte state = bitRead(num, i);
if (state == 1){
CircuitPlayground.setPixelColor(pinsi, 255,255,255);
CircuitPlayground.strip.show();
}

}
} else {
player2 = (millis() - lastmillis) /1000;

Serial.println(player2);
CircuitPlayground.clearPixels();
byte num = player2;
for (byte i=0; i < numPins; i ){
byte state = bitRead(num, i);
if (state == 1){
CircuitPlayground.setPixelColor(pinsi, 255,255,255);
CircuitPlayground.strip.show();
}
}}
CircuitPlayground.playTone(330, 500);
}
while (digitalRead(19) == HIGH && digitalRead(4) == LOW){
if (player1 < player2){
CircuitPlayground.clearPixels();
delay(250);
for (int i =0; i < 5; i ){
CircuitPlayground.setPixelColor(i, 255,255,255);
CircuitPlayground.strip.show();
}
delay(250);
CircuitPlayground.clearPixels();
}
else if (player1 > player2){
CircuitPlayground.clearPixels();
delay(250);
for (int i =5; i < 10; i ){
CircuitPlayground.setPixelColor(i, 255,255,255);
CircuitPlayground.strip.show();
}
delay(250);
CircuitPlayground.clearPixels();
}
else {
CircuitPlayground.clearPixels();
delay(250);
for (int i =0; i < 10; i ){
CircuitPlayground.setPixelColor(i, 255,255,255);
CircuitPlayground.strip.show();
}
delay(250);
CircuitPlayground.clearPixels();
}
}
if (digitalRead(19) == HIGH && digitalRead(4) == HIGH){
player1 = 0;
player2 = 0;
for (int a =0; a < 10; a ){
CircuitPlayground.clearPixels();
delay(100);
for (int i =0; i < 10; i ){
CircuitPlayground.setPixelColor(i, CircuitPlayground.colorWheel(25 * i));
CircuitPlayground.strip.show();
}
delay(100);
CircuitPlayground.clearPixels();
}

}


}

Upload the code to your Circuit Playground and have fun playing this simple game. You can also take it further by adding more sensors in to the mix by connecting them to the input pins on the board. You could even add some capacitive touch objects; the possibilities of interactions are endless.

 

 

Key Parts and Components

Add all Digi-Key Parts to Cart
  • 1528-1640-ND