Rock, paper, scissors
Play against TinkerPie with your hand: fist = rock, open hand = paper, peace sign = scissors.
What you need
- TinkerPie V1 board (or the free online simulator)
- USB-C data cable
- A laptop webcam
Step by step
- Open Rock, paper, scissors in TinkerPie Studio. It opens as blocks.
- Press Run, then Start camera in the AI camera panel and allow the webcam. No webcam? Use the “Pretend here” controls.
- 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 me, bot;
function play() {
bot = math.randomRange(1, 3);
if (bot == 1) {
basic.showLeds('......|.XXXX.|XXXXXX|XXXXXX|.XXXX.', Colors.Orange);
} else if (bot == 2) {
basic.showLeds('XXXXXX|X....X|X....X|X....X|XXXXXX', Colors.White);
} else {
basic.showLeds('X...X.|.X.X..|..X...|.X.X..|X...X.', Colors.Cyan);
}
basic.pause(600);
if (me == bot) {
basic.showString('DRAW', Colors.Yellow);
} else if (((me - bot) + 3) % 3 == 1) {
basic.showIcon(IconNames.Happy, Colors.Green);
basic.showString('YOU WIN', Colors.Green);
} else {
basic.showIcon(IconNames.Sad, Colors.Red);
basic.showString('I WIN', Colors.Red);
}
}
ai.onGesture(AiGesture.Fist, function () {
me = 1;
play();
});
ai.onGesture(AiGesture.OpenHand, function () {
me = 2;
play();
});
ai.onGesture(AiGesture.Peace, function () {
me = 3;
play();
});Arduino C++ (TinkerPie library)
// Rock, paper, scissors
// 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 me = 0;
double bot = 0;
void play();
void play() {
bot = math::randomRange(1, 3);
if (bot == 1) {
basic::showLeds("......|.XXXX.|XXXXXX|XXXXXX|.XXXX.", Colors::Orange);
} else if (bot == 2) {
basic::showLeds("XXXXXX|X....X|X....X|X....X|XXXXXX", Colors::White);
} else {
basic::showLeds("X...X.|.X.X..|..X...|.X.X..|X...X.", Colors::Cyan);
}
basic::pause(600);
if (me == bot) {
basic::showString("DRAW", Colors::Yellow);
} else if (fmod(me - bot + 3, 3) == 1) {
basic::showIcon(IconNames::Happy, Colors::Green);
basic::showString("YOU WIN", Colors::Green);
} else {
basic::showIcon(IconNames::Sad, Colors::Red);
basic::showString("I WIN", Colors::Red);
}
}
void setup() {
tinkerpie::begin();
ai::onGesture(AiGesture::Fist, []() {
me = 1;
play();
});
ai::onGesture(AiGesture::OpenHand, []() {
me = 2;
play();
});
ai::onGesture(AiGesture::Peace, []() {
me = 3;
play();
});
}
void loop() {
tinkerpie::loop(); // runs the forever blocks and handles events
}More projects like this
Finger counterShow 1, 2, 3… fingers to the webcam and TinkerPie shows the number. Use both hands for up to 10!AI cameraThumbs-up votingA class vote: thumbs up counts YES, thumbs down counts NO. Button A shows the result.AI cameraHand-controlled servoMove your hand left and right: a servo on S1 follows it, like a robot arm.AI cameraAir pianoRaise and lower your hand in the air to play high and low notes.AI cameraFace greeterWhen someone looks at the camera, TinkerPie smiles and says HI. When they leave, it falls asleep.AI cameraFace-following robotA two-wheel robot turns to keep your face in the middle of the camera picture.AI camera