Mudith L.Gracie Sanabria
Created November 17, 2022

Project 3: Hot Mushroom (Potato)

A unique version of "Hot Potato" made with Circuit Playground Express. DIG 3602 - Project 3: Sensory Intervention

Intermediate6 hours23
Project 3: Hot Mushroom (Potato)

Things used in this project

Hardware components

Circuit Playground Express
Adafruit Circuit Playground Express
×1
USB Li Ion Battery Charger
Adafruit USB Li Ion Battery Charger
×1

Hand tools and fabrication machines

Tape, Clear
Tape, Clear
Scissor, Electrician
Scissor, Electrician

Story

Read more

Custom parts and enclosures

Proof of Melody Playing and Stopping Video

To start playing you simply shake the board. The "game" will end when the lights are red again.

Game of Hot Potato Video

Cutting Cardboard to Create Mushroom Shape

Painting the Cardboard Pieces

Securing the Cap and Stem Together

Adding Tissue Paper to Secure Board

Humble Mario Mushroom

Final construction

Code

Adafruit | Hot Potato Code

Arduino
This code was borrowed from the free-to-use tutorial
:https://learn.adafruit.com/circuit-playground-hot-potato/hot-potato-code
///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Hot Potato
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>
#include "melody.h"

#define SHAKE_THRESHOLD     30    // Total acceleration threshold for shake detect

///////////////////////////////////////////////////////////////////////////////
float getTotalAccel() {
  // Compute total acceleration
  float X = 0;
  float Y = 0;
  float Z = 0;
  for (int i=0; i<10; i++) {
    X += CircuitPlayground.motionX();
    Y += CircuitPlayground.motionY();
    Z += CircuitPlayground.motionZ();
    delay(1);
  }
  X /= 10;
  Y /= 10;
  Z /= 10;

  return sqrt(X*X + Y*Y + Z*Z);
}

///////////////////////////////////////////////////////////////////////////////
void setup() {
  CircuitPlayground.begin();
  CircuitPlayground.setAccelRange(LIS3DH_RANGE_8_G);
  
  // Make it bright!
  CircuitPlayground.setBrightness(255);

  // Set the NeoPixels all red
  for (int p=0; p<10; p++) CircuitPlayground.setPixelColor(p, 0xFF0000);

  // Seed the random function with noise
  int seed = 0;
  
  seed += analogRead(12);
  seed += analogRead(7);
  seed += analogRead(9);
  seed += analogRead(10);
 
  randomSeed(seed);
}

///////////////////////////////////////////////////////////////////////////////
void loop() {
  // Wait for shaking
  while (getTotalAccel() < SHAKE_THRESHOLD) {
    // do nothing
  }

  // Game length
  int gameLength = random(numberOfNotes,6*numberOfNotes);

  // Game play with melody
  int noteToPlay = 0;
  for (int gameStep=0; gameStep<gameLength; gameStep++) {

    // Add some flare using the NeoPixels
    for (int p=0; p<10; p++) CircuitPlayground.setPixelColor(p, 0x000000);
    CircuitPlayground.setPixelColor(random(0,10), random(256),random(256),random(256)); 
    
    // Play the note
    int noteDuration = 1000 / tempo[noteToPlay];
    CircuitPlayground.playTone(melody[noteToPlay], noteDuration);
    
    // Increment and check the note counter
    noteToPlay++;
    if (noteToPlay >= numberOfNotes) noteToPlay = 0;
  }

  //
  // GAME OVER
  //
  
  // Set the NeoPixels all red
  for (int p=0; p<10; p++) CircuitPlayground.setPixelColor(p, 0xFF0000);

  // Delay a bit so can't just reset with a shake
  delay(2000);
}

Hot Potato

C/C++
There are three main functions present.
1) Shaking to Start: Using the accelerator it will detect if the board is shaken so that the NeoPixels change colors and the melody starts playing.
2) The Game: The script references melody.h and pitches.h. Every time the board plays a pitch, a NeoPixel will flash on. It will do this for every note it plays but only once NeoPixel at a time.
2) Looping the Song: The board will play the melody by calculating how the number of notes referenced.
///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Hot Potato
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>
#include "melody.h"

#define SHAKE_THRESHOLD     30    // Total acceleration threshold for shake detect

///////////////////////////////////////////////////////////////////////////////
float getTotalAccel() {
  // Compute total acceleration
  float X = 0;
  float Y = 0;
  float Z = 0;
  for (int i=0; i<10; i++) {
    X += CircuitPlayground.motionX();
    Y += CircuitPlayground.motionY();
    Z += CircuitPlayground.motionZ();
    delay(1);
  }
  X /= 10;
  Y /= 10;
  Z /= 10;

  return sqrt(X*X + Y*Y + Z*Z);
}

///////////////////////////////////////////////////////////////////////////////
void setup() {
  CircuitPlayground.begin();
  CircuitPlayground.setAccelRange(LIS3DH_RANGE_8_G);
  
  // Make it bright!
  CircuitPlayground.setBrightness(255);

  // Set the NeoPixels all red
  for (int p=0; p<10; p++) CircuitPlayground.setPixelColor(p, 0xFF0000);

  // Seed the random function with noise
  int seed = 0;
  
  seed += analogRead(12);
  seed += analogRead(7);
  seed += analogRead(9);
  seed += analogRead(10);
 
  randomSeed(seed);
}

///////////////////////////////////////////////////////////////////////////////
void loop() {
  // Wait for shaking
  while (getTotalAccel() < SHAKE_THRESHOLD) {
    // do nothing
  }

  // Game length
  int gameLength = random(numberOfNotes,1*numberOfNotes);

  // Game play with melody
  int noteToPlay = 0;
  for (int gameStep=0; gameStep<gameLength; gameStep++) {

    // Add some flare using the NeoPixels
    for (int p=0; p<10; p++) CircuitPlayground.setPixelColor(p, 0x000000);
    CircuitPlayground.setPixelColor(random(0,10), random(256),random(256),random(256)); 
    
    // Play the note
    int noteDuration = 1000 / tempo[noteToPlay];
    CircuitPlayground.playTone(melody[noteToPlay], noteDuration);
    
    // Increment and check the note counter
    noteToPlay++;
    if (noteToPlay >= numberOfNotes) noteToPlay = 0;
  }

  //
  // GAME OVER
  //
  
  // Set the NeoPixels all red
  for (int p=0; p<10; p++) CircuitPlayground.setPixelColor(p, 0xFF0000);

  // Delay a bit so can't just reset with a shake
  delay(2000);
}

Credits

Mudith L.
4 projects • 1 follower
Contact
Gracie Sanabria
4 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.