Skip to content

Commit 6997510

Browse files
committed
Add micro:bit hello world
1 parent 243c22c commit 6997510

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,4 @@ bin
133133
build
134134

135135
.idea/
136+
src/**/*.py

examples/microbit/App.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module App
2+
3+
open Fable.Python.MicroBit
4+
5+
display.scroll("Fable Python!") |> ignore

examples/microbit/MicroBit.fsproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<GenerateProgramFile>false</GenerateProgramFile>
6+
<Author>Dag Brattli</Author>
7+
<Copyright>Dag Brattli</Copyright>
8+
<OutputType>Exe</OutputType>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="App.fs" />
12+
</ItemGroup>
13+
<ItemGroup>
14+
<ProjectReference Include="../../src/Fable.Python.fsproj" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<PackageReference Include="Fable.Core.Experimental" Version="4.0.0-alpha-002" />
18+
</ItemGroup>
19+
</Project>

src/Fable.Python.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<Compile Include="flask/Flask.fs" />
2121

2222
<Compile Include="cognite-sdk/CogniteSdk.fs" />
23+
24+
<Compile Include="microbit/MicroBit.fs" />
2325
</ItemGroup>
2426
<ItemGroup>
2527
<ProjectReference Include="../../Fable/src/Fable.Core/Fable.Core.fsproj" />

src/microbit/MicroBit.fs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Fable.Python.MicroBit
2+
3+
open Fable.Core
4+
5+
/// Micro:Bit stubs for Fable Python
6+
type IDisplay =
7+
/// Clear the display.
8+
abstract clear : unit -> unit
9+
10+
/// Scrolls value horizontally on the display. If value is an integer or
11+
/// float it is first converted to a string using str(). The delay
12+
/// parameter controls how fast the text is scrolling. If wait is True,
13+
/// this function will block until the animation is finished, otherwise the
14+
/// animation will happen in the background. If loop is True, the animation
15+
/// will repeat forever. If monospace is True, the characters will all take
16+
/// up 5 pixel-columns in width, otherwise there will be exactly 1 blank
17+
/// pixel-column between each character as they scroll. Note that the wait,
18+
/// loop and monospace arguments must be specified using their keyword.
19+
abstract scroll : value: string -> unit
20+
abstract scroll : value: string * delay: int -> unit
21+
22+
/// Turn on the display.
23+
abstract on : unit -> unit
24+
25+
/// Turn off the display.
26+
abstract off : unit -> unit
27+
28+
/// Returns true if the display is on.
29+
abstract is_on : unit -> bool
30+
31+
[<Import("display", "microbit")>]
32+
let display: IDisplay = nativeOnly

0 commit comments

Comments
 (0)