Generate p5-phone sketches and answer API questions for mobile sensor/hardware integration.

Install

mkdir -p .claude/skills/p5-phone && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10692" && unzip -o skill.zip -d .claude/skills/p5-phone && rm skill.zip

Installs to .claude/skills/p5-phone

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Use when generating p5-phone examples or answering questions about p5-phone APIs: mobile sensors, device orientation, accelerometer, gyroscope, touch, microphone, p5.sound, speech recognition, PhoneCamera, ML5 camera mapping, vibration, torch/flashlight, NFC, Bluetooth BLE, lockGestures, enablePermissionsTap, enableHardwareTap, arbitrary hardware combinations, mobile browser permissions, p5.js 2 compatibility.
413 chars✓ has a “when” triggerlonger than Claude Code's old 250-char listing cap (fine on current versions)
Intermediate

Key capabilities

  • →Generate p5-phone examples
  • →Mobile sensor access
  • →Hardware permission management
  • →Gesture locking
  • →Camera/ML5 mapping

How it works

It provides helpers for mobile browser permissions and hardware access, mapping them to p5.js callbacks.

Inputs & outputs

You give it
Hardware interaction request
You get back
p5.js mobile sketch

When to use p5-phone

  • →Generate p5.js mobile examples
  • →Get help with device sensors
  • →Debug mobile hardware permissions

About this skill

p5-phone: Mobile Hardware for p5.js

p5-phone is a single-file helper library that gives p5.js sketches access to mobile phone hardware — motion sensors, microphone, sound, speech, camera (with ML5 coordinate mapping), vibration, torch/flashlight, NFC, GPS/geolocation, Bluetooth LE, and multi-user Share rooms — plus mobile gesture locking, browser-permission activation UI, and an on-screen debug console. Current version: 1.15.0.

It works in both p5.js 1.x and 2.x (auto-detected at runtime). Every public function is attached to window (global mode) and mirrored on p5.prototype (instance mode), so you call them as bare globals like lockGestures() and enableSensorTap().

Pair this with the p5js-2x skill. p5-phone only unlocks the hardware and hands you p5's own globals and objects; the p5.js 2.x language patterns around them (async asset loading, the unified pointer/touch model, renamed APIs) live in the p5js-2x skill. Load both when writing phone sketches — and read the next section before writing any hardware code.

When to use this skill

Use it whenever the request involves a p5-phone sketch, mobile p5.js hardware interaction, or an explanation of how p5-phone works: device orientation / accelerometer / gyroscope, touch, microphone / p5.sound, speech recognition, PhoneCamera and ML5 mapping, vibration, torch/flashlight, NFC, GPS/geolocation (geoRead, geoDistance, geoInPolygon), Bluetooth BLE, Share multi-user rooms (shareSetup, shared/me/guests), keeping the screen on (Screen Wake Lock), lockGestures, enablePermissionsTap / enableHardwareTap, arbitrary hardware combinations, mobile browser permissions, or p5.js 2 compatibility.

Quick Start

For generated examples, produce a complete index.html and sketch.js unless the user asks for a single file or snippet.

HTML baseline (p5.js 2-compatible):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Mobile p5.js App</title>
  <style>
    body { margin: 0; padding: 0; overflow: hidden; }
  </style>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/p5.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/src/preload.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/p5-phone.min.js"></script>
</head>
<body>
  <script src="sketch.js"></script>
</body>
</html>

Add p5.sound only when the sketch uses microphone levels, oscillators, audio input, sound output, or speech. Place it after p5 and before p5-phone/sketch.js:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/p5.sound.min.js"></script>

Minimal sketch (sketch.js):

function setup() {
  createCanvas(windowWidth, windowHeight);
  lockGestures();
  enableSensorTap('Tap to enable motion sensors');
}

function draw() {
  background(20);
  if (!window.sensorsEnabled) {
    fill(255);
    textAlign(CENTER, CENTER);
    text('Waiting for sensors', width / 2, height / 2);
    return;
  }
  // rotationX / rotationY / rotationZ are p5.js built-ins, live once sensorsEnabled is true.
  fill(0, 180, 255);
  circle(width / 2 + rotationY * 4, height / 2 + rotationX * 4, 80);
}

function mousePressed() {
  return false; // let p5-phone's gesture handling manage the touch
}

Golden Rules

  1. Call lockGestures() in every mobile sketch setup(). It blocks pull-to-refresh, swipe-back, pinch-zoom, double-tap zoom, long-press menus, and overscroll so the canvas behaves like an app.
  2. Request every permission from a user gesture. iOS grants sensitive APIs only during transient user activation (a tap/click). Never auto-request on page load — use an enable* activation UI.
  3. Gate all hardware reads behind the matching window.*Enabled flag (sensorsEnabled, micEnabled, bleConnected, etc.). Reading before permission returns stale/undefined data.
  4. Use mousePressed / mouseDragged / mouseReleased, not p5 1.x touchStarted / touchMoved / touchEnded. The mouse callbacks fire for both mouse and touch in p5.js 1.x and 2.x; the touch callbacks are removed/no-ops in p5.js 2.
  5. Serve over HTTPS (or localhost). Sensors, mic, camera, NFC, BLE, GPS, and torch all require a secure context on mobile.
  6. Need several hardware features from one tap? Use a single combined call — enablePermissionsTap(['sensors', 'torch']) — not several single-permission binds on the same gesture. One call keeps iOS transient activation intact and fires userSetupComplete() once.
  7. Use exactly one activation style per permission need unless the user explicitly asks to compare styles.

Use p5.js built-ins — do not reimplement them

The most common failure mode is a model hand-rolling hardware plumbing (a raw DeviceOrientationEvent listener, a touchstart handler, a Web Audio graph, a manual asset loader) instead of reading the values p5-phone and p5.js already provide. p5-phone deliberately surfaces everything through p5's own globals and objects. For each concern below, use the p5 built-in — never a bespoke equivalent:

p5-phone concernUse these p5.js built-ins (not custom code)Notes
Device orientationrotationX, rotationY, rotationZ (+ pRotationX/Y/Z)p5 globals; p5-phone only gates them via sensorsEnabled
AccelerationaccelerationX/Y/Z, pAccelerationX/Y/Zp5 globals
How fast it is turningrotationX - pRotationX (and Y, Z) each frame, or deviceTurned() with turnAxisp5.js has no rotation-rate globals (see the trap below)
Motion events / thresholdsdeviceMoved(), deviceShaken(), setMoveThreshold(), setShakeThreshold(), deviceOrientationdefine the callbacks as globals
Touch / pointer inputmousePressed(), mouseDragged(), mouseReleased(), mouseX, mouseY, touches[]p5.js 2 unifies mouse+touch under the pointer model; use touches[] for multitouch. Do not add your own addEventListener('touchstart', …)
Drawing the camera feedimage(cam, x, y, w, h) + cam.mapKeypoint()/mapBox()PhoneCamera integrates with p5's image(); map ML5 results with its helpers, not manual video compositing
Microphone level / analysisp5.AudioIn, p5.Amplitude, p5.FFT (p5.sound)not a raw Web Audio graph
Generated soundp5.Oscillator, p5.Envelope (p5.sound)prefer over loadSound() for portability
Loading images/audio/JSON/fontawait loadImage()/loadSound()/loadJSON()/loadFont() in async setup()p5.js 2: load* return Promises — no preload(). See the p5js-2x skill
Mapping / rangesmap(), constrain(), lerp()p5 math helpers

Two specific traps worth calling out:

  • Motion values are p5.js built-ins, not p5-phone APIs. p5-phone only requests the permission and sets window.sensorsEnabled. The data (rotationX, accelerationX, deviceShaken(), …) comes straight from p5.js. Do not invent p5-phone getters for them.
  • p5.js has no rotation rate. rotationRateAlpha, rotationRateBeta and rotationRateGamma are not p5 globals, in 1.x or 2.x, and p5-phone does not add them. Reading them throws a ReferenceError on every frame once the sensors are on, so the sketch stops drawing. For how fast the phone is turning, use the change in rotationX/Y/Z from pRotationX/Y/Z each frame (watch the wrap at ±180°), or deviceTurned() and turnAxis for a quarter turn. Only if a sketch truly needs the gyroscope's own rate, read event.rotationRate (it can be null) in a devicemotion listener once window.sensorsEnabled is true. That is the one place a listener is the right call.
  • There is no bleValue() getter. Read incoming BLE data from window.bleValues[name] or from the bleReceive(name, value) callback. bleValues is an object keyed by characteristic name.

Permissions model

Every hardware family exposes the same six activation styles. Pick one:

  • Tap — enable<Feature>Tap(message) — full-screen tap overlay.
  • Button — enable<Feature>Button(buttonText, statusText?) — auto-generated button.
  • Canvas — enable<Feature>Canvas(message) — prompt drawn on the p5 canvas.
  • Banner — enable<Feature>Banner(message, position?) — animated slide-in banner (position = 'top'/'bottom').
  • On (custom element) — enable<Feature>On(selector) — bind activation to any existing HTML element by CSS selector. The element stays on the page; hide it in draw() once the flag is true (select('#start').hide()).
  • Minimal — enable<Feature>Minimal(message?) or enable<Feature>Minimal({ color, opacity, icon, iconColor, iconSize, message }) — bare semi-transparent overlay with a pulsing icon, no message box (v1.14.0).

Full matrix:

FeatureTapButtonCanvasBannerMinimalOn (selector)
Motion sensorsenableSensorTap(msg)enableSensorButton(text)enableSensorCanvas(msg)enableSensorBanner(msg)enableSensorMinimal(msg/opts?)enableSensorOn(sel)
MicrophoneenableMicTap(msg)enableMicButton(text)enableMicCanvas(msg)enableMicBanner(msg)enableMicMinimal(msg/opts?)enableMicOn(sel)
Sound outputenableSoundTap(msg)enableSoundButton(text)enableSoundCanvas(msg)enableSoundBanner(msg)enableSoundMinimal(msg/opts?)enableSoundOn(sel)
SpeechenableSpeechTap(msg)enableSpeechButton(text)enableSpeechCanvas(msg)enableSpeechBanner(msg)enableSpeechMinimal(msg/opts?)enableSpeechOn(sel)
VibrationenableVibrationTap(msg)enableVibrationButton(text)enableVibrationCanvas(msg)enableVibrationBanner(msg)enableVibrationMinimal(msg/opts?)enableVibrationOn(sel)
Torch / flashlightenableTorchTap(msg)enableTorchButton(text)

Content truncated.

When not to use it

  • →Desktop-only p5.js sketches

Prerequisites

p5.jsp5-phone

Limitations

  • →Requires HTTPS
  • →Browser-specific hardware support

How it compares

It simplifies complex mobile browser permission flows into simple tap-to-enable functions.

Compared to similar skills

p5-phone side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
p5-phone (this skill)03moNo flagsIntermediate
flutter-development1,5557moNo flagsIntermediate
flutter-expert735moNo flagsAdvanced
react-native-architecture554moReviewAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry