Initial files for MakeCode project

This commit is contained in:
Alexander Davis
2021-06-19 17:23:04 +01:00
parent 0b816eead3
commit 5e42d4ad77
13 changed files with 319 additions and 0 deletions

29
.github/workflows/makecode.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
name: MakeCode
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.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
.vscode/settings.json vendored Normal file
View File

@@ -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
.vscode/tasks.json vendored Normal file
View File

@@ -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
Gemfile Normal file
View File

@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins

10
Makefile Normal file
View File

@@ -0,0 +1,10 @@
all: deploy
build:
pxt build
deploy:
pxt deploy
test:
pxt test

31
README.md Normal file
View File

@@ -0,0 +1,31 @@
> Open this page at [https://alexanderedavis.github.io/binary-light-box/](https://alexanderedavis.github.io/binary-light-box/)
## 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/alexanderedavis/binary-light-box** and import
## Edit this project ![Build status badge](https://github.com/alexanderedavis/binary-light-box/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/alexanderedavis/binary-light-box** 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/alexanderedavis/binary-light-box/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
_config.yml Normal file
View File

@@ -0,0 +1,8 @@
makecode:
target: microbit
platform: microbit
home_url: https://makecode.microbit.org/
theme: jekyll-theme-slate
include:
- assets
- README.md

1
main.blocks Normal file

File diff suppressed because one or more lines are too long

91
main.py Normal file
View File

@@ -0,0 +1,91 @@
def changes2(difference: number, flag: number):
global Denary
Denary += difference
Display(Denary)
def changes4(difference: number, flag: number):
global Denary
Denary += difference
column4 = flag
Display(Denary)
def changes128(difference: number, flag: number):
global Denary
Denary += difference
column128 = flag
Display(Denary)
def Display(number: number):
serial.write_string("/")
serial.write_number(number)
def changes256(difference: number, flag: number):
global Denary
Denary += difference
column256 = flag
Display(Denary)
def changes1(difference: number, flag: number):
global Denary
Denary += difference
column1 = flag
Display(Denary)
def changes16(difference: number, flag: number):
global Denary
Denary += difference
column16 = flag
Display(Denary)
def changes32(difference: number, flag: number):
global Denary
Denary += difference
column32 = flag
Display(Denary)
def changes64(difference: number, flag: number):
global Denary
Denary += difference
column64 = flag
Display(Denary)
def changes8(difference: number, flag: number):
global Denary
Denary += difference
column8 = flag
Display(Denary)
Denary = 0
serial.redirect(SerialPin.P0, SerialPin.P16, BaudRate.BAUD_RATE9600)
columns = [0, 0, 0, 0, 0, 0, 0, 0, 0]
Denary = 0
Display(Denary)
def on_forever():
if pins.digital_read_pin(DigitalPin.P1) == 1 and columns[0] == 0:
changes1(1, 1)
elif pins.digital_read_pin(DigitalPin.P1) == 0 and columns[0] == 1:
changes1(-1, 0)
elif pins.digital_read_pin(DigitalPin.P2) == 1 and columns[1] == 0:
changes2(2, 1)
elif pins.digital_read_pin(DigitalPin.P2) == 0 and columns[1] == 1:
changes2(-2, 0)
elif pins.digital_read_pin(DigitalPin.P3) == 1 and columns[2] == 0:
changes4(4, 1)
elif pins.digital_read_pin(DigitalPin.P3) == 0 and columns[2] == 1:
changes4(-4, 0)
elif pins.digital_read_pin(DigitalPin.P4) == 1 and columns[3] == 0:
changes8(8, 1)
elif pins.digital_read_pin(DigitalPin.P4) == 0 and columns[3] == 1:
changes8(-8, 0)
elif pins.digital_read_pin(DigitalPin.P6) == 1 and columns[4] == 0:
changes16(16, 1)
elif pins.digital_read_pin(DigitalPin.P6) == 0 and columns[4] == 1:
changes16(-16, 0)
elif pins.digital_read_pin(DigitalPin.P7) == 1 and columns[5] == 0:
changes32(32, 1)
elif pins.digital_read_pin(DigitalPin.P7) == 0 and columns[5] == 1:
changes32(-32, 0)
elif pins.digital_read_pin(DigitalPin.P8) == 1 and columns[6] == 0:
changes64(64, 1)
elif pins.digital_read_pin(DigitalPin.P8) == 0 and columns[6] == 1:
changes64(-64, 0)
elif pins.digital_read_pin(DigitalPin.P9) == 1 and columns[7] == 0:
changes128(128, 1)
elif pins.digital_read_pin(DigitalPin.P9) == 0 and columns[7] == 1:
changes128(-128, 0)
elif pins.digital_read_pin(DigitalPin.P10) == 1 and columns[8] == 0:
changes256(256, 1)
elif pins.digital_read_pin(DigitalPin.P10) == 0 and columns[0] == 1:
changes256(-256, 0)
basic.forever(on_forever)

62
main.ts Normal file
View File

@@ -0,0 +1,62 @@
function updateNumber (flag: number, column: number, difference: number) {
Denary += difference
columns[column] = flag
Display(Denary)
}
function Display (number: number) {
serial.writeString("/")
serial.writeNumber(number)
}
let Denary = 0
let columns: number[] = []
let ready = false
serial.redirect(
SerialPin.P0,
SerialPin.P16,
BaudRate.BaudRate9600
)
columns = [0, 0, 0, 0, 0, 0, 0, 0, 0]
Denary = 0
Display(Denary)
ready = true
basic.forever(function () {
if (ready) {
if (pins.digitalReadPin(DigitalPin.P1) == 1 && columns[0] == 0) {
updateNumber(1, 0, 1)
} else if (pins.digitalReadPin(DigitalPin.P1) == 0 && columns[0] == 1) {
updateNumber(0, 0, -1)
} else if (pins.digitalReadPin(DigitalPin.P2) == 1 && columns[1] == 0) {
updateNumber(1, 1, 2)
} else if (pins.digitalReadPin(DigitalPin.P2) == 0 && columns[1] == 1) {
updateNumber(0, 1, -2)
} else if (pins.digitalReadPin(DigitalPin.P3) == 1 && columns[2] == 0) {
updateNumber(1, 2, 4)
} else if (pins.digitalReadPin(DigitalPin.P3) == 0 && columns[2] == 1) {
updateNumber(0, 2, -4)
} else if (pins.digitalReadPin(DigitalPin.P4) == 1 && columns[3] == 0) {
updateNumber(1, 3, 8)
} else if (pins.digitalReadPin(DigitalPin.P4) == 0 && columns[3] == 1) {
updateNumber(0, 3, -8)
} else if (pins.digitalReadPin(DigitalPin.P6) == 1 && columns[4] == 0) {
updateNumber(1, 4, 16)
} else if (pins.digitalReadPin(DigitalPin.P6) == 0 && columns[4] == 1) {
updateNumber(0, 4, -16)
} else if (pins.digitalReadPin(DigitalPin.P7) == 1 && columns[5] == 0) {
updateNumber(1, 5, 32)
} else if (pins.digitalReadPin(DigitalPin.P7) == 0 && columns[5] == 1) {
updateNumber(0, 5, -32)
} else if (pins.digitalReadPin(DigitalPin.P8) == 1 && columns[6] == 0) {
updateNumber(1, 6, 64)
} else if (pins.digitalReadPin(DigitalPin.P8) == 0 && columns[6] == 1) {
updateNumber(0, 6, -64)
} else if (pins.digitalReadPin(DigitalPin.P9) == 1 && columns[7] == 0) {
updateNumber(1, 7, 128)
} else if (pins.digitalReadPin(DigitalPin.P9) == 0 && columns[7] == 1) {
updateNumber(0, 7, -128)
} else if (pins.digitalReadPin(DigitalPin.P10) == 1 && columns[8] == 0) {
updateNumber(1, 8, 256)
} else if (pins.digitalReadPin(DigitalPin.P10) == 0 && columns[8] == 1) {
updateNumber(0, 8, -256)
}
}
})

22
pxt.json Normal file
View File

@@ -0,0 +1,22 @@
{
"name": "Binary Box",
"description": "",
"dependencies": {
"core": "*",
"radio": "*",
"microphone": "*"
},
"files": [
"main.blocks",
"main.ts",
"README.md",
"main.py"
],
"testFiles": [
"test.ts"
],
"supportedTargets": [
"microbit"
],
"preferredEditor": "blocksprj"
}

1
test.ts Normal file
View File

@@ -0,0 +1 @@
// tests go here; this will not be compiled when this package is used as an extension.

9
tsconfig.json Normal file
View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"outDir": "built",
"rootDir": "."
},
"exclude": ["pxt_modules/**/*test.ts"]
}