Things used in this project

Hardware components:
Cutout cortado grande
Punch Through LightBlue Bean
Retain packaging material for easier creation Also an empty container or plastic Easter egg
×1
Software apps and online services:
Punch Through Bean Loader
Ide web
Arduino IDE

Code

egg tossArduino
This code uses the built in accelerometer to judge when the "egg" is broken. It ignores accerlation along the major axis because eggs are much stronger in that direction.
When it detects that the acceleration has reached the breakage threshold, the LED is turned on to indicate game over.

Initializations
Line 12 maxAccel - maximum acceleration detected along x & y (ignore z acceleration)
Line 13 glow - level to set the LED. Turn on the LED after it breaks
Line 16 Set the accleration range to +- 8g

Sensing
Line 22 Get the accelerometer reading
Lines 25-27 Determine the magnitude of accerlation not along z-axis (rms method)
Lines 29-32 Update breakage state

Display
Lines 34-35 Display breakage state and set update rate
/*
  This code mimics an egg toss game using the Bean's onboard accelerometer and
  LED. It only considers the X & Y acceleration components as eggs are much
  stronger along the central axis
*/

// define breakVAl for xy Accel that will "break" the egg
#define breakVal 100

AccelerationReading accel;
uint8_t maxAccel = 0;
uint8_t glow = 0;

void setup() {
  // Set accleration range to +- 8g
  Bean.setAccelerationRange(8);
}

// Always compare current accleration to max accelration.
// Alert on maximum level
void loop() {
  accel = Bean.getAcceleration();

  // Evaluate acceleration
  uint8_t xA = (abs(accel.xAxis)) / 2;
  uint8_t yA = (abs(accel.yAxis)) / 2;
  uint8_t xyA = sqrt(xA * xA + yA * yA);

  if ( xyA > maxAccel )
    maxAccel = xyA;
  if ( maxAccel > breakVal )
    glow = 110;

  Bean.setLed( glow, glow, glow);
  Bean.sleep(50);
}

Credits

Me
Carol Chesney

Mechanical engineer and teacher

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Grove LED Bar Controller with the Bean+
Easy
  • 824
  • 13

Protip

Learn the basics of using popular Grove components with the new LightBlue Bean+ to get started with building your own projects!

Hypnos Pendant
Easy
  • 1,811
  • 11

Full instructions

A wearable that promotes mindfully spending your time, which also helps trigger lucid dreams.

LightBlue Bean: Arduino Basics
Easy
  • 1,225
  • 15

Protip

This little Bluetooth board is ideal for wearable tech and tiny robots. Get started with these projects!

Getting Started with Bluetooth Low Energy (BLE)
Easy
  • 4,073
  • 18

Protip

In this tutorial, we'll learn how to set up BLE GATT services to make a thermometer using Intel's Arduino 101

Bluetooth RC
Easy
  • 958
  • 13

Work in progress

RC car controlled using BLE.

glowHacker LED Bike Lights
Easy
  • 1,771
  • 7

Full instructions

Turn your bicycle into a brilliant display of safety-enhancing splendor!

Add projectSign up / Login