I will email you about this once I have checked one or two things.
In order to use the Espruino firmware, the android device must NOT be paired with the micro:bit.
If you have already paired it, you need to go into the android device bluetooth settings and forget it.
Please feel free to improve it.
The code below works for me with the Espruino version linked from
microbit-js.org
Does it work for you?
app.LoadPlugin( "MicroBit" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
btn = app.CreateButton( "Smile" );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
app.AddLayout( lay );
microbit = app.CreateMicroBit();
microbit.Scan();
}
function btn_OnTouch()
{
microbit.Reset();
setTimeout(smile,500);
}
function smile()
{
microbit.SetLEDs( "0111010001001000010010001" );
}
Tried both espruino_1v89_microbit.hex and espruino_1v85_microbit.hex on both micro bit units.
Re-installed the micro bit plugin.
var debugMode = true;
var motorSpeed = 0;var motorScale = 0.175;var motorPWMoffset = 0.3;var motorPWMFreq = 1500;
var portLamp = D1;var portMotor = D0;var portBtnMotorDown = D8;var portBtnMotorUp = D12;var portBtnLamp = D16;var isLampBlinking = false;
var lampIntervalOn, lampIntervalOff = 0;var watchMotorDown, watchMotorUp, watchLamp = 0;
function debug( txt ) { if (debugMode) console.log( txt );}
function onMotorUp(e) { debug("onMotorUp"); if (motorSpeed < 4) { motorSpeed++; debug(motorSpeed); var realSpeed = motorPWMoffset + motorSpeed * motorScale; if (realSpeed > 1) realSpeed = 1; analogWrite(portMotor, realSpeed, {freq: motorPWMFreq}); }}
function onMotorDown(e) { debug("onMotorDown"); if (motorSpeed > 0) { motorSpeed--; debug(motorSpeed); var realSpeed = motorPWMoffset + motorSpeed * motorScale; if (motorSpeed === 0) realSpeed = 0; analogWrite(portMotor, realSpeed, {freq: motorPWMFreq}); }}
function lampBlink(enable) { debug("lampBlink: "+enable); if (enable) { if (lampIntervalOn) clearInterval(lampIntervalOn); if (lampIntervalOff) clearInterval(lampIntervalOff); digitalWrite(portLamp, 0); lampIntervalOn = setInterval("digitalWrite(portLamp, 1);", 1000); lampIntervalOff = setInterval("digitalWrite(portLamp, 0);", 2000); } else { if (lampIntervalOn) clearInterval(lampIntervalOn); if (lampIntervalOff) clearInterval(lampIntervalOff); lampIntervalOn = lampIntervalOff = 0; digitalWrite(portLamp, 0); } isLampBlinking = !isLampBlinking;}
function onLamp(e) { debug("onLamp"); lampBlink(!isLampBlinking);}
function onInit() { debug("onInit"); var btnOptions = { repeat:true, edge:'rising', debounce:20 };
pinMode(portBtnMotorDown, 'input_pulldown'); pinMode(portBtnMotorUp, 'input_pulldown'); pinMode(portBtnLamp, 'input_pulldown');
watchMotorDown = setWatch(onMotorDown, portBtnMotorDown, btnOptions); watchMotorUp = setWatch(onMotorUp, portBtnMotorUp, btnOptions);
watchLamp = setWatch(onLamp, portBtnLamp, btnOptions);}
onInit();