Skip to content

Instantly share code, notes, and snippets.

@arleighdickerson
Created October 9, 2024 02:16
Show Gist options
  • Save arleighdickerson/2330a4ff3579120e462e8eacc6f2cfbd to your computer and use it in GitHub Desktop.
Save arleighdickerson/2330a4ff3579120e462e8eacc6f2cfbd to your computer and use it in GitHub Desktop.
import { useEffect } from 'react';
const bpmToMillis = (bpm: number) => (bpm === 0 ? 0 : Math.round(60000.0 / bpm));
let vibrateInterval: number;
function startVibrate(duration: number) {
navigator.vibrate([duration, duration]);
}
function stopVibrate() {
if (vibrateInterval) {
clearInterval(vibrateInterval);
}
navigator.vibrate(0);
}
function startPersistentVibrate(interval: number) {
vibrateInterval = setInterval(() => {
startVibrate(interval);
}, interval * 2);
}
const millis = bpmToMillis(60);
export default function PhoneTestPage() {
useEffect(() => {
startPersistentVibrate(millis);
return () => {
stopVibrate();
};
}, []);
return (
<div>
<h1>Touch Screen to Test Actuator</h1>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment