Code Monkey home page Code Monkey logo

bitcommander's Introduction

Makecode Extension for 4tronix BitCommander

This library provides a Microsoft Makecode extension for 4tronix Bit:Commander, see https://4tronix.co.uk/bitcommander/.

Reading the buttons

There are 5 buttons that can be checked: Red, Yellow, Green and Blue on the left and the Joystick on the right can be pressed as well If the button is pressed it will return a '1'. If it isn't pressed, then it returns a '0' The following code checks the Green button and does something if it is pressed

// Check Green button
if (bitcommander.readButton(BCButtons.Green) == 1) {
    ... do something ...
}

Reading the position of the Dial

When writing code, be aware that the Dial control input is shared with the speaker output and so the input range is limited to around 0 - 850 instead of the normal 0 - 1023. Use the readDial block to get the value (0 to ~850) into a variable, or test the value directly

// Read the Dial value into the myDial variable
myDial = bitcommander.readDial()
if (myDial > 500) {
   ... do something ...
}

or this is equivalent:

if (bitcommander.readDial() > 500) {
   ... do something ...
}

Reading the position of the Joystick

Both the X and Y axes of the joystick have a range 0 to 1023. Specify the axis as part of the function call. Use the readJoystick block to get the value.

// Read the Joystick X axis value in to the xAxis variable
xAxis = bitcommander.readJoystick(BCJoystick.X)

Playing music

There is a small speaker on Bit:Commander wired to Pin 0, which is the default for playing music files. Use the standard Music blocks for this:

// Play The Entertainer music clip
music.beginMelody(music.builtInMelody(Melodies.Entertainer), MelodyOptions.Once)

Fireled helpers

The Bit:Commander has 6 Fireleds The default update mode is automatic so LEDs will be updated immediately after changes

// Set all leds to Red
bitcommander.bitcommander.setLedColor(0xff0000);

// Clear all leds
bitcommander.ledClear();

// Set Fireled at position 1 to Green
bitcommander.setPixelColor(0, 0x00ff00);

// Show rainbow across all Fireleds (Red..Violet)
bitcommander.ledRainbow();

// Show led rainbow and shift
bitcommander.ledRainbow();
bitcommander.ledhift();

// Show led rainbow and rotate
bitcommander.ledRainbow();
bitcommander.ledRotate();

// Set brightness of leds
bitcommander.ledBrightness(100);

Supported targets

  • for PXT/microbit

License

MIT

bitcommander's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.