Back

Here is how you code events for the Jewelbots' Magic Button

There are a few Magic Button functions that allow you to change the effect of a button press on your Jewelbots. You can use these with the LEDs and buzzer to make very cool effects on your Jewelbots that get triggered by pressing the button.

COMPONENT INTIALIZATION

// To use the Magic Button in Arduino, // use the following functions to define what happens void button_press(void){ // Define what happens when the Magic Button is pressed quickly // (when the Jewelbot is not plugged into power) } void button_press_long(void) { // Define what happens when the Magic Button is held for 2 seconds // (when the Jewelbot is not plugged into power) } void charging_button_press(void) { // Define what happens when the Magic Button is pressed quickly // (when the Jewelbot is plugged into power) }

You can use the function below independently and add LEDs, LED Animations, or Buzzers inside.

The function is called an event, because it is triggered by an interaction on the device. Events are ways you can trigger things to happen after you do something else, in this case after pressing the button.

API

button_press(void)

This function happens when you hit your button one time.

void button_press(void){ LED led; led.turn_on_single(NW, GREEN); }

button_press_long(void)

This function happens when you press the Magic Button and hold it for a moment.

void button_press_long(void){ LED led; led.turn_on_single(SE, YELLOW); }

charging_button_press(void)

This function happens when you press the Magic Button when the device is plugged in.

void charging_button_press(void){ LED led; led. led.turn_on_single(NW, BLUE); }