Tilt maze ball
Tilt the board to roll the green ball onto the red target. Each catch beeps and moves the target.
What you need
- TinkerPie V1 board (or the free online simulator)
- USB-C data cable
Step by step
- Open Tilt maze ball in TinkerPie Studio. It opens as blocks.
- Press Run to try it in the simulator. Use the sliders and buttons under the board picture to test it.
- Connect TinkerPie with a USB-C cable in Chrome or Edge, press Connect, then Download. Or, with Studio started from the TinkerPie launcher on your computer, open the Arduino C++ tab and press Build & Flash.
- Change something: a colour, a number, a sound. Then run it again.
The code
This is the program the blocks make. The same program runs in the simulator and on the board.
JavaScript
var x, nx, y, ny, tx, ty;
basic.forever(function () {
nx = x;
ny = y;
if (input.rotation(Rotation.Roll) < -15) {
nx = math.constrain(x - 1, 0, 5);
} else if (input.rotation(Rotation.Roll) > 15) {
nx = math.constrain(x + 1, 0, 5);
}
if (input.rotation(Rotation.Pitch) < -15) {
ny = math.constrain(y - 1, 0, 4);
} else if (input.rotation(Rotation.Pitch) > 15) {
ny = math.constrain(y + 1, 0, 4);
}
if (nx != x || ny != y) {
led.unplot(x, y);
basic.pause(20);
x = nx;
y = ny;
led.plot(x, y, Colors.Green);
basic.pause(20);
}
if (x == tx && y == ty) {
music.playTone(1047, 80);
tx = math.randomRange(0, 5);
ty = math.randomRange(0, 4);
led.plot(tx, ty, Colors.Red);
basic.pause(20);
}
basic.pause(150);
});
x = 2;
y = 2;
tx = 5;
ty = 0;
led.plot(tx, ty, Colors.Red);
basic.pause(20);
led.plot(x, y, Colors.Green);
basic.pause(20);Arduino C++ (TinkerPie library)
// Tilt maze ball
// Arduino C++ made by TinkerPie Studio from the blocks. Board: TinkerPie V1 (ESP32-S3).
// Arduino IDE: install the TinkerPie library (Studio menu > Arduino library), then Tools > Board > ESP32S3 Dev Module,
// USB CDC On Boot: Enabled, Flash Size: 16MB, Partition Scheme: 16M Flash (3MB APP/9.9MB FATFS), PSRAM: OPI PSRAM.
#include <TinkerPie.h>
using namespace tinkerpie;
double x = 0;
double nx = 0;
double y = 0;
double ny = 0;
double tx = 0;
double ty = 0;
void setup() {
tinkerpie::begin();
basic::forever([]() {
nx = x;
ny = y;
if (input::rotation(Rotation::Roll) < -15) {
nx = math::clamp(x - 1, 0, 5);
} else if (input::rotation(Rotation::Roll) > 15) {
nx = math::clamp(x + 1, 0, 5);
}
if (input::rotation(Rotation::Pitch) < -15) {
ny = math::clamp(y - 1, 0, 4);
} else if (input::rotation(Rotation::Pitch) > 15) {
ny = math::clamp(y + 1, 0, 4);
}
if (nx != x || ny != y) {
led::unplot(x, y);
basic::pause(20);
x = nx;
y = ny;
led::plot(x, y, Colors::Green);
basic::pause(20);
}
if (x == tx && y == ty) {
music::playTone(1047, 80);
tx = math::randomRange(0, 5);
ty = math::randomRange(0, 4);
led::plot(tx, ty, Colors::Red);
basic::pause(20);
}
basic::pause(150);
});
x = 2;
y = 2;
tx = 5;
ty = 0;
led::plot(tx, ty, Colors::Red);
basic::pause(20);
led::plot(x, y, Colors::Green);
basic::pause(20);
}
void loop() {
tinkerpie::loop(); // runs the forever blocks and handles events
}More projects like this
Hello, TinkerPieA red heart, then your first scrolling message.StarterScrolling BOTICSBOTICS scrolls across the matrix in a new colour every time.StarterHeartbeatA beating heart: brightness pulses like lub-dub.Starter
Rainbow waveA rainbow that flows across all 30 LEDs.StarterButton counterA adds one, B resets. Counts show on the matrix.StarterShake diceShake the board to roll a number from 1 to 6, with a click.Starter