logo

Getting Started

Using TypeScript Using C++

There are a number of ways to get started with JACDAC, the simplest at the moment is to use MakeCode TypeScript.

TypeScript using MakeCode

Microsoft MakeCode is a web-based programming editor for microcontrollers. Microsoft Makecode use the Control Layer from jacdac-ts and is combined the physical layer from codal-core. This allows the sharing of service code between web-based and microcontroller jacdac development.

To build a JACDAC project using MakeCode go to the JACDAC samples page.

1) Pick a sample project

2) Hit the edit button

3) View the code, hit download, and transfer to the microcontroller via UF2.

4) (optional) Change to a different board.

C++ using CODAL

CODAL is an is an evolution of the abstraction layer used for the BBC micro:bit. CODAL powers MakeCode giving users the semantic power of Javascript with the speed of C++.

CODAL can be used independently of MakeCode for easier C++ based microcontroller development. To install the toolchains required by CODAL please go here.

Once installed, pick a target and replace main.cpp with any of the following samples

MessageBus

This example uses the Brainpad Arcade. Devices listen to events emitted on the JACDAC bus by the MessageBus service. Each device listens to APP_ID 9008 and displays the upButton state using an LED.

#include "BrainPad.h"
#include "JDMessageBusService.h"

BrainPad bp;
JDMessageBusService serialBus;

#define APP_ID 9008

void message_bus_evt(Event e)
{
    if (e.value == DEVICE_BUTTON_EVT_DOWN)
    {
        bp.io.ledGreen.setDigitalValue(1);
    }
    if (e.value == DEVICE_BUTTON_EVT_UP)
    {
        bp.io.ledGreen.setDigitalValue(0);
    }
}

void button_event(Event e)
{
    if (e.value == DEVICE_BUTTON_EVT_DOWN)
    {
        Event(APP_ID, e.value);
    }
    if (e.value == DEVICE_BUTTON_EVT_UP)
    {
        Event(APP_ID, e.value);
    }
}

int main()
{
    bp.init();
    int state = 1;
    bp.messageBus.listen(bp.buttonUp.id, DEVICE_ID_ANY, button_event);
    bp.messageBus.listen(APP_ID, DEVICE_ID_ANY, message_bus_evt);
    serialBus.listen(APP_ID, DEVICE_ID_ANY);
    bp.jacdac.add(serialBus);
    bp.jacdac.start();

    while(1)
    {
        bp.io.ledRed.setDigitalValue(state);
        fiber_sleep(500);
        state = !state;
    }
}

Accelerometer

In this example there is a Client accelerometer service running on a Brainpad Arcade, receiving data from a Host accelerometer service running on a Circuit Playground Express.

Host

#include "CircuitPlayground.h"
#include "JDAccelerometerService.h"

CircuitPlayground cplay;
JDAccelerometerService accelerometer(cplay.accelerometer);

int state = 0;

int main()
{
    cplay.jacdac.add(accelerometer);
    cplay.jacdac.start();

    while(1)
    {
        cplay.io.led.setDigitalValue(state);
        fiber_sleep(500);
        state = !state;
    }
}

Client

#include "BrainPad.h"
#include "JDAccelerometerService.h"

BrainPad bp;
JDAccelerometerService accelerometer;

int main()
{
    bp.init();
    bp.jacdac.add(accelerometer);
    bp.jacdac.start();

    while(1)
    {
        bp.io.ledRed.setDigitalValue(state);
        DMESG("x %d y %d z %d", accelerometer.x, accelerometer.y, accelerometer.z);
        fiber_sleep(500);
        state = !state;
    }
}

Supported microcontrollers

Here is a working list of the microcontrollers that support JACDAC (microntrollers may be added or removed at any point):