Skip to content

Commit

Permalink
Initial files for MakeCode project
Browse files Browse the repository at this point in the history
  • Loading branch information
owoellen committed May 27, 2022
1 parent da8049d commit 19c0223
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/cfg-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Check pxt.json

on:
push:
branches:
- 'master'
- 'main'

jobs:
check-cfg:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: |
npm install -g pxt
pxt target microbit
- name: Checkout current state
run: |
git checkout -- .
git clean -fd
- name: Fix files listed in config if necessary
run: pxt checkpkgcfg
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
continue-on-error: true
with:
title: 'Removing missing files from pxt.json'
commit-message: 'Removing missing files from pxt.json'
delete-branch: true
29 changes: 29 additions & 0 deletions .github/workflows/makecode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: MakeCode

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install
run: |
npm install -g pxt
pxt target microbit
- name: build
run: |
pxt install
pxt build --cloud
env:
CI: true
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"editor.formatOnType": true,
"files.autoSave": "afterDelay",
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/built/**": true,
"**/node_modules/**": true,
"**/yotta_modules/**": true,
"**/yotta_targets": true,
"**/pxt_modules/**": true
},
"files.associations": {
"*.blocks": "html",
"*.jres": "json"
},
"search.exclude": {
"**/built": true,
"**/node_modules": true,
"**/yotta_modules": true,
"**/yotta_targets": true,
"**/pxt_modules": true
}
}
30 changes: 30 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

// A task runner that calls the MakeCode (PXT) compiler
{
"version": "2.0.0",
"tasks": [{
"label": "pxt deploy",
"type": "shell",
"command": "pxt deploy --local",
"group": "build",
"problemMatcher": [ "$tsc" ]
}, {
"label": "pxt build",
"type": "shell",
"command": "pxt build --local",
"group": "build",
"problemMatcher": [ "$tsc" ]
}, {
"label": "pxt install",
"type": "shell",
"command": "pxt install",
"group": "build",
"problemMatcher": [ "$tsc" ]
}, {
"label": "pxt clean",
"type": "shell",
"command": "pxt clean",
"group": "test",
"problemMatcher": [ "$tsc" ]
}]
}
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: deploy

build:
pxt build

deploy:
pxt deploy

test:
pxt test
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

> Open this page at [https://fadeongithub.github.io/magnet-meter-for-microbit/](https://fadeongithub.github.io/magnet-meter-for-microbit/)
## Use as Extension

This repository can be added as an **extension** in MakeCode.

* open [https://makecode.microbit.org/](https://makecode.microbit.org/)
* click on **New Project**
* click on **Extensions** under the gearwheel menu
* search for **https://github.com/fadeongithub/magnet-meter-for-microbit** and import

## Edit this project ![Build status badge](https://github.com/fadeongithub/magnet-meter-for-microbit/workflows/MakeCode/badge.svg)

To edit this repository in MakeCode.

* open [https://makecode.microbit.org/](https://makecode.microbit.org/)
* click on **Import** then click on **Import URL**
* paste **https://github.com/fadeongithub/magnet-meter-for-microbit** and click import

## Blocks preview

This image shows the blocks code from the last commit in master.
This image may take a few minutes to refresh.

![A rendered view of the blocks](https://github.com/fadeongithub/magnet-meter-for-microbit/raw/master/.github/makecode/blocks.png)

#### Metadata (used for search, rendering)

* for PXT/microbit
<script src="https://makecode.com/gh-pages-embed.js"></script><script>makeCodeRender("{{ site.makecode.home_url }}", "{{ site.github.owner_name }}/{{ site.github.repository_name }}");</script>
8 changes: 8 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
makecode:
target: microbit
platform: microbit
home_url: https://makecode.microbit.org/
theme: jekyll-theme-slate
include:
- assets
- README.md
1 change: 1 addition & 0 deletions main.blocks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<xml xmlns="https://developers.google.com/blockly/xml"/>
84 changes: 84 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
def on_microbit_id_button_a_evt():
if input.magnetic_force(Dimension.STRENGTH) < 0 and input.magnetic_force(Dimension.STRENGTH) < 20:
basic.show_leds("""
. . . . .
. . . . .
. . . . .
. . . . .
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 20 and input.magnetic_force(Dimension.STRENGTH) < 40:
basic.show_leds("""
. . . . .
. . . . .
. . . . .
# # # # #
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 40 and input.magnetic_force(Dimension.STRENGTH) < 60:
basic.show_leds("""
. . . . .
. . . . .
# # # # #
# # # # #
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 60 and input.magnetic_force(Dimension.STRENGTH) < 80:
basic.show_leds("""
. . . . .
# # # # #
# # # # #
# # # # #
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 80 and input.magnetic_force(Dimension.STRENGTH) < 100:
basic.show_leds("""
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
""")
else:
basic.show_leds("""
# . # . #
# . # . #
# . # . #
. . . . .
# . # . #
""")
control.on_event(EventBusSource.MICROBIT_ID_BUTTON_A,
EventBusValue.MICROBIT_EVT_ANY,
on_microbit_id_button_a_evt)

basic.show_string("MAGNET METER")
basic.show_leds("""
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
""")
control.wait_micros(48)
basic.clear_screen()
basic.show_leds("""
. # # # .
# . . . #
# # # # #
# . . . #
# . . . #
""")
control.raise_event(EventBusSource.MICROBIT_ID_BUTTON_A,
EventBusValue.MICROBIT_EVT_ANY)

def on_forever():
if input.button_is_pressed(Button.AB):
basic.show_leds("""
# # # # #
# . . . .
# . # . #
# . . . .
# # # # #
""")
music.play_melody("E F G A G - B C5 ", 500)
basic.forever(on_forever)
83 changes: 83 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
control.onEvent(EventBusSource.MICROBIT_ID_BUTTON_A, EventBusValue.MICROBIT_EVT_ANY, function on_microbit_id_button_a_evt() {
if (input.magneticForce(Dimension.Strength) < 0 && input.magneticForce(Dimension.Strength) < 20) {
basic.showLeds(`
. . . . .
. . . . .
. . . . .
. . . . .
# # # # #
`)
} else if (input.magneticForce(Dimension.Strength) > 20 && input.magneticForce(Dimension.Strength) < 40) {
basic.showLeds(`
. . . . .
. . . . .
. . . . .
# # # # #
# # # # #
`)
} else if (input.magneticForce(Dimension.Strength) > 40 && input.magneticForce(Dimension.Strength) < 60) {
basic.showLeds(`
. . . . .
. . . . .
# # # # #
# # # # #
# # # # #
`)
} else if (input.magneticForce(Dimension.Strength) > 60 && input.magneticForce(Dimension.Strength) < 80) {
basic.showLeds(`
. . . . .
# # # # #
# # # # #
# # # # #
# # # # #
`)
} else if (input.magneticForce(Dimension.Strength) > 80 && input.magneticForce(Dimension.Strength) < 100) {
basic.showLeds(`
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
`)
} else {
basic.showLeds(`
# . # . #
# . # . #
# . # . #
. . . . .
# . # . #
`)
}

})
basic.showString("MAGNET METER")
basic.showLeds(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
control.waitMicros(48)
basic.clearScreen()
basic.showLeds(`
. # # # .
# . . . #
# # # # #
# . . . #
# . . . #
`)
control.raiseEvent(EventBusSource.MICROBIT_ID_BUTTON_A, EventBusValue.MICROBIT_EVT_ANY)
basic.forever(function on_forever() {
if (input.buttonIsPressed(Button.AB)) {
basic.showLeds(`
# # # # #
# . . . .
# . # . #
# . . . .
# # # # #
`)
music.playMelody("E F G A G - B C5 ", 500)
}

})
26 changes: 26 additions & 0 deletions pxt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "magnet meter",
"description": "",
"dependencies": {
"core": "*",
"radio": "*",
"microphone": "*"
},
"files": [
"main.blocks",
"main.ts",
"README.md",
"main.py"
],
"testFiles": [
"test.ts"
],
"targetVersions": {
"target": "4.0.18",
"targetId": "microbit"
},
"supportedTargets": [
"microbit"
],
"preferredEditor": "pyprj"
}
1 change: 1 addition & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// tests go here; this will not be compiled when this package is used as an extension.
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "ES5",
"noImplicitAny": true,
"outDir": "built",
"rootDir": "."
},
"exclude": ["pxt_modules/**/*test.ts"]
}

0 comments on commit 19c0223

Please sign in to comment.