Xose Pérez
Published © GPL3+

Playing Slow Catch With The Bean

Technology and kids does not necessarily mean tablets and video games. A Lightblue Bean wearable is a small tech addition to good old games.

BeginnerFull instructions provided1 hour183
Playing Slow Catch With The Bean

Things used in this project

Hardware components

LightBlue Bean
Punch Through LightBlue Bean
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
Coin Cell Battery CR2032
Coin Cell Battery CR2032
×1
Buzzer
Buzzer
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

PlatformIO

Story

Read more

Schematics

Slow Catch Schematic

Code

Slow Catch

C/C++
#define BUZZER_PIN            0
#define ACCELERATION_RANGE    2
#define ACCELERATION_BASE     (512/ACCELERATION_RANGE)
 
#define SENSITIVITY           0.15
#define STOP_TONE             100
#define STOP_TONE_DURATION    1000
#define STOP_DURATION         2000
#define RESUME_TONE           400
#define RESUME_TONE_DURATION  250
#define CHECK_DELAY           50
 
void beep(int note, int duration) {
    if (note==0) {
        Bean.sleep(duration);
    } else {
        tone(BUZZER_PIN, note, duration);
        delay(duration);
        noTone(BUZZER_PIN);
    }
}
 
float getAccelerationModule()  {
    float x = (float) Bean.getAccelerationX();
    float y = (float) Bean.getAccelerationY();
    float z = (float) Bean.getAccelerationZ();
    float g = sqrt(x*x+y*y+z*z) / ACCELERATION_BASE;
    return g;
}
 
void setup() {
    pinMode(BUZZER_PIN, OUTPUT);
    uint8_t mode = Bean.getAccelerometerPowerMode();
    if (mode != VALUE_LOW_POWER_10MS) {
        Bean.setAccelerometerPowerMode(VALUE_LOW_POWER_10MS);
    }
    Bean.setAccelerationRange(ACCELERATION_RANGE);
    Bean.setLed(0, 0, 0);
}
 
void loop() {
    float g = getAccelerationModule();
    if (abs(g-1) > SENSITIVITY) {
        Bean.setLed(255, 0, 0);
        beep(STOP_TONE, STOP_TONE_DURATION);
        Bean.sleep(STOP_DURATION);
        beep(RESUME_TONE, RESUME_TONE_DURATION);
        Bean.setLed(0, 0, 0);
    }
    Bean.sleep(CHECK_DELAY);
}

Credits

Xose Pérez

Xose Pérez

2 projects • 4 followers

Comments

Add projectSign up / Login