From f391e6de16f6c1fe5fa834a7a4e45f16733ec23c Mon Sep 17 00:00:00 2001 From: Tom Ball Date: Fri, 17 Mar 2017 16:05:00 -0700 Subject: [PATCH] examples from chapter 1. --- docs/fcp.md | 5 ++++ docs/fcp/ch1.md | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 docs/fcp.md create mode 100644 docs/fcp/ch1.md diff --git a/docs/fcp.md b/docs/fcp.md new file mode 100644 index 00000000..3ea29dc4 --- /dev/null +++ b/docs/fcp.md @@ -0,0 +1,5 @@ +# Foundations of Computing and Programming: exploring the micro:bit + +This page provides examples from the book "Foundations of Computing and Programming: exploring the micro:bit". + +* [Chapter 1: Introduction](fcp/ch1) diff --git a/docs/fcp/ch1.md b/docs/fcp/ch1.md new file mode 100644 index 00000000..49294d58 --- /dev/null +++ b/docs/fcp/ch1.md @@ -0,0 +1,69 @@ +# Chapter 1 + +Here are the code examples from Chapter 1 +of [Foundations of Computing and Programming: exploring the micro:bit](../fcp). +You can switch between the Blocks and JavaScript versions of each example, +as well as run the example in the web browser, and retrieve a file to +install on a micro:bit. + +## Figure 1.11 +LED Screen with code: +```blocks +basic.showIcon(IconNames.Square) +led.plot(2, 2) +``` + +## Figure 1.12 + +Take action on button A/B pressed. +```blocks +input.onButtonPressed(Button.A, () => { + basic.showIcon(IconNames.Square) +}) +input.onButtonPressed(Button.B, () => { + led.plot(2, 2) +}) +``` + +## Figure 1.13 + +Take action on button A/B pressed, as +well as shaking the micro:bit. +```blocks +input.onButtonPressed(Button.A, () => { + basic.showIcon(IconNames.Square) +}) +input.onButtonPressed(Button.B, () => { + led.plot(2, 2) +}) +input.onGesture(Gesture.Shake, () => { + basic.clearScreen() +}) +``` + +## Figure 1.15 + +Program to send signals over pin P0. +```blocks +basic.forever(() => { + pins.digitalWritePin(DigitalPin.P0, 1) + basic.pause(1000) + pins.servoWritePin(AnalogPin.P0, 180) + basic.pause(1000) +}) +``` + +## Figure 1.17 + +Communicating using radio. +```blocks +input.onButtonPressed(Button.A, () => { + radio.sendString("A") +}) +input.onButtonPressed(Button.B, () => { + radio.sendString("B") +}) +radio.onDataPacketReceived(({receivedString}) => { + basic.showString(receivedString) +}) +``` \ No newline at end of file