Ejemplo n.º 1
0
int main()
{
     // Initialise the micro:bit runtime.
    uBit.init();
	uBit.radio.enable();
	
	// Initialise the micro:bit listeners for radio datagrams and button events.
	uBit.messageBus.listen(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, onData);
	uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButton);
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButton);
	
	// Sets the group to an arbitrary number (59 in this case) to avoid interference 
	uBit.radio.setGroup(59);

    // Use the highest output put level on the radio, to increase range and reliability.
    uBit.radio.setTransmitPower(7);

    // Increase the receive buffer size on our serial port, to be at least the same size as
    // a packet. This guarantees correct parsing of packets.
    uBit.serial.setRxBufferSize(32);

    // Run a short animaiton at power up.
    uBit.display.animateAsync(radio, 500, 5, 0, 0);
	
	// Creates a new fiber that listens for incoming serial signals
	create_fiber(reader);
	
	// Get into powersaving sleep mode
	while(1)
        uBit.sleep(10000);
}
Ejemplo n.º 2
0
int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    uBit.messageBus.listen(MICROBIT_ID_RADIO, MICROBIT_RADIO_EVT_DATAGRAM, onData);
    uBit.radio.enable();

    while(1)
        uBit.sleep(1000);
}
Ejemplo n.º 3
0
void onButton(MicroBitEvent e)
{	
    if (e.source == MICROBIT_ID_BUTTON_A){
			
			displayQuizID();
			displayQuestionID();
			displayAlternatives();
		}

    if (e.source == MICROBIT_ID_BUTTON_B){
		
		uBit.serial.send("nxt;");
		uBit.display.print(">");
		uBit.sleep(500);
		uBit.display.clear();
	}
	
	uBit.sleep(20);
}
Ejemplo n.º 4
0
int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    // Setup a simple triangular waveform.
    MicroBitImage img("1 0 0 0 0 0 0 0 0 1\n0 1 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 0 1 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n");
     
    while(1)
        uBit.display.scroll(img, 80, -1);
}
Ejemplo n.º 5
0
int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();

    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
    
    startAdvertising();
    
    release_fiber();
}
Ejemplo n.º 6
0
int main() {
    // Initialise the micro:bit runtime.
    uBit.init();
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_A, MICROBIT_BUTTON_EVT_CLICK, onButtonA);
    uBit.messageBus.listen(MICROBIT_ID_BUTTON_B, MICROBIT_BUTTON_EVT_CLICK, onButtonB);
    setMode();
    // If main exits, there may still be other fibers running or registered event handlers etc.
    // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
    // sit in the idle task forever, in a power efficient sleep.
    release_fiber();
    return 0;
}
Ejemplo n.º 7
0
int main()
{
    // Initialise the micro:bit runtime.
    uBit.init();
    uBit.radio.enable();
        
        PacketBuffer b(4);
        b = 4;
        uBit.display.print(b);             
    while(1)
    {
        
        
        if (uBit.buttonA.isPressed())
            uBit.radio.datagram.send(b);

        else if (uBit.buttonB.isPressed())
            uBit.radio.datagram.send("B");

        uBit.sleep(100);
    }
}
Ejemplo n.º 8
0
void displayAlternatives(){
	uBit.display.print(alternatives);
	uBit.sleep(1000);
	uBit.display.clear();
}
Ejemplo n.º 9
0
void displayQuestionID(){
	uBit.display.print(questionID);
	uBit.sleep(1000);
	uBit.display.clear();
}
Ejemplo n.º 10
0
void displayQuizID(){
	uBit.display.print(quizID);
	uBit.sleep(1000);
	uBit.display.clear();
}
Ejemplo n.º 11
0
int main()
{    
    // Bring up soft reset button.
    resetButton.mode(PullUp);
    resetButton.fall(microbit_reset);

#if CONFIG_ENABLED(MICROBIT_DBG)

    // For diagnostics. Gives time to open the console window. :-) 
    for (int i=3; i>0; i--)
    {
        uBit.serial.printf("=== SUPERMAIN: Starting in %d ===\n", i);
        wait(1.0);
    }

    uBit.serial.printf("micro:bit runtime DAL version %s\n", MICROBIT_DAL_VERSION);

#endif    

    // Bring up our nested heap allocator.
    microbit_heap_init();

    // Bring up fiber scheduler
    scheduler_init();

    // Bring up random number generator, BLE, display and system timers.    
    uBit.init();

    // Provide time for all threaded initialisers to complete.
    uBit.sleep(100);

#if CONFIG_ENABLED(MICROBIT_BLE_PAIRING_MODE)
    // Test if we need to enter BLE pairing mode...
    int i=0;
    while (uBit.buttonA.isPressed() && uBit.buttonB.isPressed() && i<10)
    {
        uBit.sleep(100);
        i++;

        if (i == 10)
        {
            // Start the BLE stack, if it isn't already running.
            if (!uBit.ble)
            {
                uBit.bleManager.init(uBit.getName(), uBit.getSerial(), true);
                uBit.ble = uBit.bleManager.ble;
            }

            // Enter pairing mode, using the LED matrix for any necessary pairing operations
            uBit.bleManager.pairingMode(uBit.display);
        }
    }
#endif

#if CONFIG_ENABLED(MICROBIT_BLE_ENABLED)
    // Start the BLE stack, if it isn't already running.
    if (!uBit.ble)
    {
        uBit.bleManager.init(uBit.getName(), uBit.getSerial(), false);
        uBit.ble = uBit.bleManager.ble;
    }
#endif

    app_main();

    // If app_main exits, there may still be other fibers running, registered event handlers etc.
    // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
    // sit in the idle task forever, in a power efficient sleep.
    release_fiber();

    // We should never get here, but just in case.
    while(1);
}