import Toybox.Lang; import Toybox.WatchUi; import Toybox.Application; import Toybox.Lang; import Toybox.Timer; import Toybox.System; class MetronomeApp ... { function getInitialView() ... { var view = new MetronomeView(); return [view, new MetronomeDelegate(view)] } } class MetronomeView extends WatchUi.View { private var timer as Timer; private const updateInterval = 1000; // 1000 ms = 1 second private var vibrating as Boolean; private const vibeData = [ new Attention.VibeProfile(75, 50), new Attention.VibeProfile(0, 950), new Attention.VibeProfile(50, 50), new Attention.VibeProfile(0, 950), new Attention.VibeProfile(50, 50), new Attention.VibeProfile(0, 950), new Attention.VibeProfile(50, 50), new Attention.VibeProfile(0, 950), ]; function initialize() { timer = new Timer.Timer(); myTimer.start(method(:timerCallback), updateInterval, true); } function timerCallback() as Void { WatchUi.requestUpdate(); // triggers a call to onUpdate() } function onUpdate() { if (vibrating) { Attention.vibrate(vibeData); } // render UI // ... } function startVibes() { vibrating = true; } function stopVibes() { vibrating = false; } } class MetronomeDelegate extends WatchUi.BehaviorDelegate { var metronomeView as MetronomeView; function initialize(view) { BehaviorDelegate.initialize(); metronomeView = view; } function onSwipe(swipeEvent) { var direction = swipeEvent.getDirection(); System.println(direction); if (direction == 0) { WatchUi.pushView(new Rez.Menus.MainMenu(), new MetronomeMenuDelegate(), WatchUi.SLIDE_UP); } else if (direction == 2) { metronomeView.startVibes(); } return true; } function onKey(keyEvent) { var key = keyEvent.getKey(); System.println(key); if (key == 4) { metronomeView.stopVibes(); return true; } else { metronomeView.startVibes(); return false; } } }