Coder Social home page Coder Social logo

microsoft / pxt-microbit Goto Github PK

View Code? Open in Web Editor NEW
695.0 64.0 574.0 317.79 MB

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode

Home Page: https://makecode.microbit.org

License: Other

TypeScript 62.56% C++ 14.55% HTML 0.90% CSS 0.10% JavaScript 16.47% Smalltalk 0.25% C# 2.08% Shell 0.10% Objective-C 1.39% C 0.01% Rich Text Format 0.01% Assembly 0.51% Less 1.07%
typescript blockly microbit makecode pxt code editor education

pxt-microbit's Introduction

micro:bit target for PXT

Build Status pxt-testghpkgs

pxt-microbit is a Microsoft Programming Experience Toolkit (PXT) target that allows you to program a BBC micro:bit.

Issue tracking

Please add an issue if you discover an (unreported) bug.

Developing new extensions

Authoring and testing of new extensions can be done directly from the web editor. See our documentation on how to get started. If you want to run the editor locally, keep reading.

Local server setup

The local server lets you to run the editor and serve the documentation from your own computer. It is meant for a single developer used and not designed to serve the editor to a large amount of users.

  1. Install Node.js 8.9.4 or higher.
  2. Clone this repository.
git clone https://github.com/microsoft/pxt-microbit
cd pxt-microbit
  1. Install the PXT command line (add sudo for Mac/Linux shells).
npm install -g pxt
  1. Install the pxt-microbit dependencies.
npm install

Go to the Running section.

Developer Setup

This is the typical setup used by the MakeCode team to work on the microbit.

  1. Install Node.js 8.9.4 or higher.
  2. Install Docker if you plan to build .cpp files.
  3. Clone the pxt repository.
git clone https://github.com/microsoft/pxt
cd pxt
  1. Install the dependencies of pxt and build it
npm install
npm run build
cd ..
  1. Clone the pxt-common-packages repository
git clone https://github.com/microsoft/pxt-common-packages
cd pxt-common-packages
npm install
  1. Link pxt-common-packages to pxt
npm link ../pxt
cd ..
  1. Clone this repository.
git clone https://github.com/microsoft/pxt-microbit
cd pxt-microbit
  1. Install the PXT command line (add sudo for Mac/Linux shells).
npm install -g pxt
  1. Install the pxt-microbit dependencies.
npm install
  1. Link pxt-microbit back to base pxt repo (add sudo for Mac/Linux shells). This step is only required if you intend to make changes to pxt and/or pxt-common-packages repos. If all you want is serve a local Makecode, you can skip this step.
npm link ../pxt
npm link ../pxt-common-packages

Note the above command assumes the folder structure of

       makecode
          |
  ----------------------------------
  |       |                        |
 pxt      pxt-common-packages  pxt-microbit

Running

Run this command from inside pxt-microbit to open a local web server

pxt serve

If the local server opens in the wrong browser, make sure to copy the URL containing the local token. Otherwise, the editor will not be able to load the projects.

If you need to modify the .cpp files (and have installed yotta), enable yotta compilation using the --localbuild flag:

pxt serve --local

If you want to speed up the build, you can use the rebundle option, which skips building and simply refreshes the target information

pxt serve --rebundle

Cleaning

Sometimes, your built folder might be in a bad state, clean it and try again.

pxt clean

Building with CODAL locally

The following commands force a local build using CODAL.

pxt buildtarget --local

To disable docker, run

export PXT_NODOCKER=1

If you are also modifiying CODAL, consider running pxt clean to ensure the proper branch is picked up.

Modifying DAL/CODAL locally

  • follow instructions above until pxt serve
  • open editor on localhost and create a project
  • do export PXT_FORCE_LOCAL=1 PXT_RUNTIME_DEV=1 PXT_ASMDEBUG=1; you can add PXT_NODOCKER=1; pxt help has help on these
  • find project folder under pxt-microbit/projects, typically pxt-microbit/projects/Untitled-42
  • if you're going to modify .cpp files in PXT, replace "core": "*" in pxt.json with "core": "file:../../libs/core"; similarly "radio": "file:../../libs/radio" and "microphone": "file:../../libs/microphone"
  • you can edit main.ts to change the PXT side of the program; you can also edit it from the localhost editor; note that Download in the localhost editor will produce different binary than command line, as it builds in the cloud and uses tagged version of CODAL
  • in that folder run pxt build - this will clone codal somewhere under built/ (depends on build engine and docker)
  • there can be an issue with exporting the variables i.e. PXT_FORCE, so including them in the build command can help solve issues sudo PXT_NODOCKER=1 PXT_ASMDEBUG=1 PXT_RUNTIME_DEV=1 PXT_DEBUG=1 PXT_FORCE_LOCAL=1 PXT_COMPILE_SWITCHES=csv---mbcodal pxt build
  • if the target is not building, delete files in hexcache found in pxt-microbit/built/hexcache to force local build
  • the built hex can be found in pxt-microbit/projects/<your project name>/built named binary.hex
  • similarly, you can run pxt deploy (or just pxt which is the same) - it will build and copy to MICROBIT drive
  • assuming the build folder is under built/codal, go to built/codal/libraries and run code *
  • in git tab, checkout appropriate branches (they are all in detached head state to the way we tag releases)
  • modify files, run pxt, see effects
  • you can also run pxt gdb to debug; this requires openocd
  • other commands using openocd are pxt dmesg which dumps DMESG(...) buffer and pxt heap which can be used to visualize PXT heap (and CODAL's one to some extent)

Updating dal.d.ts

cd libs/blocksprj
rm -rf built
PXT_FORCE_LOCAL=1 PXT_COMPILE_SWITCHES=csv---mbcodal pxt build
PXT_FORCE_LOCAL=1 PXT_COMPILE_SWITCHES=csv---mbcodal pxt builddaldts
mv dal.d.ts ../core

Updates

Make sure to pull changes from all repos regularly. More instructions are at https://github.com/Microsoft/pxt#running-a-target-from-localhost

Update playlists in markdown

To add a new playlist, add an entry in /playlists.json, and regenerate the markdown (see paragraph below). You'll now have a new markdown gallery file listing the videos which you can reference in /targetconfig.json.

Get a Google API key and store it in the GOOGLE_API_KEY environment variables (turn on data from the app).

pxt downloadplaylists

Repos

The pxt-microbit target depends on several other repos. The main ones are:

History

See the MakeCode blog.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

MICROSOFT, the Microsoft Logo, and MAKECODE are registered trademarks of Microsoft Corporation. They can only be used for the purposes described in and in accordance with Microsoft’s Trademark and Brand guidelines published at https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general.aspx. If the use is not covered in Microsoft’s published guidelines or you are not sure, please consult your legal counsel or MakeCode team ([email protected]).

pxt-microbit's People

Contributors

abchatra avatar anzhou5 avatar aznhassan avatar bluetooth-martin avatar darzu avatar eanders-ms avatar ganicke avatar gbaman avatar gingemonster avatar guillaumejenkins avatar jaustin avatar johnvidler avatar jwunderl avatar kimprice avatar martinwork avatar mebrauns avatar microbit-carlos avatar microbit-mark avatar microsoftsam avatar mmoskal avatar nielsswinkels avatar pelikhan avatar riknoll avatar samelhusseini avatar shakao avatar srietkerk avatar tballmsft avatar thomasdenney avatar thsparks avatar tinfoilhatter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-microbit's Issues

WIN10 APP - Show Code

When you set variable in blocks, then click show Code... the variable is automatically set as null

let item = null;
item = 0;

Excel - Charting

Why is serial only present in an isolated example of on radio received?

Serial is present on data received in this example

basic.forever(() => {
    radio.sendNumber(input.acceleration(Dimension.X))
})
radio.onDataReceived(() => {
    led.plotBarGraph(radio.receiveNumber(), 1023)
})

Serial is not present on data received in this example. Why is this the case?

let jumps = 0
basic.forever(() => {
    let acc = input.acceleration(Dimension.Y)
    if (acc > 2000) {
        jumps = jumps + 1;
        radio.sendNumber(jumps)
        basic.showLeds(`
            . . . . .
            . # . # .
            . . # . .
            # . . . #
            . # # # .
            `)
        basic.clearScreen()
    }
})
input.onButtonPressed(Button.A, () => {
    basic.showNumber(jumps)
})
input.onButtonPressed(Button.AB, () => {
    let jumps = 0
    basic.showNumber(jumps)
})
radio.onDataReceived(() => {
    basic.showNumber(radio.receiveNumber())
    led.stopAnimation()
})

music blocks - blocks to JS

music blocks - blocks to JS

1 in reference to the light beatbox lesson

http://localhost:3232/lessons/light-beatbox/activity

2 enter this code with blocks

let light = 0;
input.onButtonPressed(Button.A, () => {
    music.rest(music.beat(BeatFraction.Sixteenth));
    light = input.lightLevel();
    if (light < 25) {
        music.ringTone(music.noteFrequency(Note.C));
    }
    else {
        music.ringTone(music.noteFrequency(Note.A));
    }
});

3 press convert.

4 i would expect the code to be equal to the following when using ringTone using JS without Blocks

input.onButtonPressed(Button.A, () => {
    music.rest(BeatFraction.Sixteenth)
    let light = input.lightLevel()
    if (light < 25) {
        music.ringTone(Note.C)
    }
    else {
        music.ringTone(Note.C);
    }
})

4 however, the conversion is not 1:1. Am i missing something when using music with JS vs using music with blocks ?

create sprites does not work..

1 open KSF, click JS

2 type this code

let hero = game.createSprite(2, 2)
let food = game.createSprite(4, 4)
let ghost = game.createSprite(0, 0)

3 would expect for these sprites to appears on the simulator.

4 the error is shown in blocks too.. see example below

image

4 nothing appears when pressing run

data on plot bar graph...

expectation: You could receive data from a single micro:bit

  1. open KSF, go to JS...

2 enter this code

basic.forever(() => {
    led.plotBarGraph(input.acceleration(Dimension.X), 1023);
});

3 it would be ideal to receive Excel data from a single micro:bit using acceleration, it doesn not appear possible.

firefox browser issues - deleting blocks

firefox browser issues - deleting blocks

repro go to this version of firefox
firefox version

  1. open ksf, blocks.

2 add these blocks

blocks not deleting

3 expect to be able to delete these blocks, they are stuck in the drawers

semi colon (syntax) appears optional...

is this intentional ?

1 open JS

  1. type code - error free
let hero = game.createSprite(2, 2);
let food = game.createSprite(4, 4);
let ghost = game.createSprite(0, 0);
ghost.change(LedSpriteProperty.Blink, 100);

  1. type code - error free
let hero = game.createSprite(2, 2)
let food = game.createSprite(4, 4)
let ghost = game.createSprite(0, 0)
ghost.change(LedSpriteProperty.Blink, 100)

firefox issue - browser specific

go to either of these browsers: firefox or IE

  1. IE. 11.0.9600.38204
  2. FireFox

firefox version

3 go to codemicrobit.com/latest

  1. drawers/tabs are removed, users only sees first 4 drawers on the block editor

show code - not supported

show code: not supported in all browsers

1 open browser (MS Edge)

2 enter this code in blocks

basic.showNumber(7)

3 click on show code

image

4 this feature does not work in Edge

game library blocks - issues

open js, enter code

 let ghost = 0;
 let food = 0;
 let hero = 0;
hero = game.createSprite(2, 2);
food = game.createSprite(4, 4);
ghost = game.createSprite(0, 0);


an issue occurs on latest

image

localhost - not able to open in Edge

Repo.

1 Go through steps to open localhost

2 Chrome opens by default

3 copy/paste localhost URL to Edge


http://localhost:3232/index.html#

4 Edge is constantly saying loading... but never finishes loading

image

code not rendering... catch the egg game

the code works in the simulator, but not rendering

open KSF, enter this in JS

let basketX = 2
let eggX = 2
let eggY = 0
basic.forever(() => {
    led.unplot(basketX, 4)
    led.unplot(eggX, eggY)
    eggY = eggY + 1
    led.plot(eggX, eggY)
    basic.pause(300)
    let accX = input.acceleration(Dimension.X)
    basketX = 2 + Math.min(2, Math.max(-2, accX / 200))
    led.plot(basketX, 4)
    if (eggY > 4) {
        eggY = -1
        eggX = Math.random(5)
    }
    basic.pause(300)
})

here is the lesson

http://localhost:3232/lessons/catch-the-egg-game/activity

Turbine Presentation

the code is working in microbit.co.uk, not in codemicrobit.com

repro:

import code to microbit.co.uk

https://www.microbit.co.uk/jvkblk

import code to codemicrobit.com

https://codemicrobit.com/tgukzgtdzg

 let higherLimit = null;
 let voltage = null;
 let high_voltage = null;
input.onButtonPressed(Button.A, () => {
    basic.showNumber(high_voltage);
    basic.pause(2000);
});
high_voltage = 0;
higherLimit = 1024;
basic.forever(() => {
    voltage = pins.analogReadPin(AnalogPin.P0);
    if (voltage > high_voltage) {
        high_voltage = voltage;
    }
    else {
        led.plotBarGraph(voltage, higherLimit);
    }
});

here is a screenshot of the program working

image

when this program is loaded in codemicrobit.com, the same program is NOT working


 let voltage = null;
 let higherLimit = null;
 let high_voltage = null;
input.onButtonPressed(Button.A, () => {
    basic.showNumber(high_voltage);
    basic.pause(2000);
});
high_voltage = 0;
higherLimit = 1024;
basic.forever(() => {
    voltage = pins.analogReadPin(AnalogPin.P0);
    if (voltage > high_voltage) {
        high_voltage = voltage;
    }
    else {
        led.plotBarGraph(voltage, higherLimit);
    }
});


screenshot

image

the error message is ...

Voltage implicitly has an error type...

image

So I changed this to...

 let voltage = null;
 let higherLimit = null;
 let high_voltage = null;
input.onButtonPressed(Button.A, () => {
    basic.showNumber(high_voltage);
    basic.pause(2000);
});
high_voltage = 0;
higherLimit = 1024;
voltage = 0;
basic.forever(() => {
    voltage = pins.analogReadPin(AnalogPin.P0);
    if (voltage > high_voltage) {
        high_voltage = voltage;
    }
    else {
        led.plotBarGraph(voltage, higherLimit);
    }
});

possible issue:

the variables are not updating -> variables consistently showing Null

WIN10 APP - Play / Compile (Busted)

  1. new projects, JS
  2. enter this code
let jumps = 0
basic.forever(() => {
    let acc = input.acceleration(Dimension.Y)
    if (acc > 2000) {
        jumps = jumps + 1;
        radio.sendNumber(jumps)
        basic.showLeds(`
            . . . . .
            . # . # .
            . . # . .
            # . . . #
            . # # # .
            `)
        basic.clearScreen()
    }
})
input.onButtonPressed(Button.A, () => {
    basic.showNumber(jumps)
})
input.onButtonPressed(Button.AB, () => {
    let jumps = 0
    basic.showNumber(jumps)
})
radio.onDataReceived(() => {
    basic.showNumber(radio.receiveNumber())
    led.stopAnimation()
})


Run / Compile does not work

completed - converted lessons

Beginner

  • Beautiful Image, show a beautiful image with show LEDs
  • Lucky 7, show a number on the LED screen with show number
  • Answering Machine, show a text message with show string
  • Game of Chance, show a text message with game over
  • Smiley, smiley and frowney faces that transition on button pressed
  • Magic Logo, show an image on logo up
  • Snowflake Fall, repeat a series of images with forever
  • Screen Wipe, turn off the LEDs with clear screen
  • Flashing Heart, display images with a pause
  • Blink, turn an LED on and off with plot
  • Night Light, dim the LEDs with set brightness
  • Game Counter, displays the player's score with score and add points to score
  • Happy Birthday, create a popular song
    picture
    Intermediate
  • Magic 8, a fortune teller game with the BBC micro:bit
  • Guess the Number, guess a random number with pick number
  • Counter, display a number with a variable
  • Love Meter, create a love meter with on pin pressed
  • Rock Paper Scissors, create the classic game of rock paper scissors with if statement
  • Truth or Dare, a game that forces each player to reveal a secret or do something funny with if statement
  • Spinner, spin the arrow with multiple if statements
  • Die Roll, spin with more if statements
  • Looper, display a series of numbers with a for loop index
  • Strobe Light, develop shapes with a nested for loops
  • Temperature, get the ambient temperature (degree Celsius °C)
  • Digi Yoyo, create a counter with a while loop
  • Rotation Animation, control an animation with a boolean variable
  • Compass, displays the direction the BBC micro:bit is pointing with compass
  • Zoomer, measure the force with acceleration
  • Glowing Pendulum, construct a pendulum that glows using acceleration
  • Classic Beatbox, make a beatbox music player with variables
  • Light Beatbox, make a beatbox music player with light level: need to finish last exercise.
    picture.. broken link ... http://localhost:3232/microbit/lessons/hack-your-headphones/activity

Maker

  • The Watch, design and create The Watch
  • Hack your Headphones, create music on the BBC micro:bit by hacking your headphones -- broken link..
  • Banana Keyboard, create music with fruits
  • Telegraph, play the telegraph game between two BBC micro:bits
  • Ornament Chain, play the ornament chain game between two BBC micro:bits
    Advanced
  • Hero, reconstruct the classic arcade game pac man with the BBC micro:bit

light level - documentation

1 open KSF, click blocks

2 enter program using music / light level

image

 let light = 0;
input.onButtonPressed(Button.A, () => {
    music.rest(music.beat(BeatFraction.Sixteenth));
    light = input.lightLevel();
    if (light < 25) {
        music.ringTone(music.noteFrequency(Note.C));
    }
    else {
        music.ringTone(music.noteFrequency(Note.A));
    }
});


3 expect sound to play based on acceleration 'y' in simulator

convert input light level to JS - automatic set var to 0

convert input light level to JS - automatic set var to 0

1 why do you need to store light level as 0?

2 enter this code in blocks

let light = input.lightLevel();

3 then press show in code

4
this is the code that appears

 let light = 0;
light = input.lightLevel();

2 i would expect when converting from blocks to JS, the code would appear like this

let light = input.lightLevel();

rotation animation - cannot render blocks/JS

1 go to codemicrobit.com, open JS

2 enter this code

let rotating = true;
input.onButtonPressed(Button.A, () => {
    serial.writeLine("hello")
    rotating = false
})
while (rotating) {
    serial.writeLine("loop")
    basic.showLeds(`
        # . . . .
        . # . . .
        . . # . .
        . . . # .
        . . . . #
        `)
    basic.showLeds(`
        . . # . .
        . . # . .
        . . # . .
        . . # . .
        . . # . .
        `)
    basic.showLeds(`
        . . . . #
        . . . # .
        . . # . .
        . # . . .
        # . . . .
        `)
    basic.showLeds(`
        . . . . .
        . . . . .
        # # # # #
        . . . . .
        . . . . .
        `)
}

3 copy this code into docs...cannot render blocks/JS

image

blocks not rendering, again

code was fixed 5 minutes ago, the blocks are not rendering for a second time (after fixing the code - they appeared to be fixed and visibly rendering 5 minutes ago on localhost)

http://localhost:3232/lessons/prank-wifi/activity

basic.showString("Check Wifi", 150)
basic.forever(() => {
    let xAccel2 = Math.abs(input.acceleration(Dimension.X))
    let yAccel2 = Math.abs(input.acceleration(Dimension.Y))
    let zAccel2 = Math.abs(input.acceleration(Dimension.Z))
    let sum2 = xAccel2 + yAccel2 + zAccel2
    if (sum2 < 1200) {
        basic.showLeds(`
. . . . .
. . . . .
. . # . .
. # # . .
# # # . .
`)
    } else if (sum2 >= 1400 && sum2 < 1680) {
        basic.showLeds(`
. . . . .
. . . # .
. . # # .
. # # # .
# # # # .
`)
    }
    else if (sum2 >= 1680) {
        basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
# . . . .
`)
    }
    if (sum2 >= 1200 && sum2 < 1400) {
        basic.showLeds(`
. . . . #
. . . # #
. . # # #
. # # # #
# # # # #
`)
    }
})

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.