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
4 projects • 6 followers
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

Add projectSign up / Login