createButton()

Category:Maker

A command to create a new button object that can be programmed in the same way as the blocks in the Circuit drawer. The var myButton = createButton() command creates a new button object named myButton that you can use in onBoardEvent() blocks, just like buttonL and buttonR. Remember to pass in a pin parameter so the board knows where the button is connected.

Examples

// Create a button attached to a pin
var myButton = createButton(5);

// Buzz when the button goes down
onBoardEvent(myButton, "down", function() {
  buzzer.note("G4", 100);
});

Syntax

var myButton = createButton(pin);

Parameters

NameTypeRequired?Description
Pin number The number of the pin your LED is connected to. This is usually printed on your board, but can also be found in your board's documentation.

Returns

New button object

Tips

  • You'll need to work in text mode to use this block. You can still drag out blocks that you're familiar with from the Circuit drawer, you'll just need to change the name of the object.
  • You can create new button objects on pin 0, 2, 3, 6, and 12.

Found a bug in the documentation? Let us know at documentation@code.org