1
0
Fork 0

initial commit adding metronome app

master
Michael Bengfort 2020-04-19 13:55:20 +02:00
parent 745e4d38a9
commit 0df1fb19e3
6 changed files with 125 additions and 0 deletions

View File

@ -1293,5 +1293,25 @@
"evaluate": true
}
]
},
{
"id": "Metronome",
"name": "Metronome",
"icon": "metronome_icon.png",
"version": "0.03",
"description": "Makes the watch blinking and vibrating with a given rate",
"tags": "tool",
"allow_emulator": true,
"storage": [
{
"name": "metronome.app.js",
"url": "metronome.js"
},
{
"name": "metronome.img",
"url": "metronome-icon.js",
"evaluate": true
}
]
}
]

10
apps/metronome/README.md Normal file
View File

@ -0,0 +1,10 @@
# Metronome
This metronome makes your watch blink and vibrate with a given rate.
## Usage
* Tap the screen at least three times. The app calculates the mean rate of your tapping. This rate is displayed in bmp while the text blinks and the watch softly vibrates with every beat.
* Use `BTN1` to increase the bmp value by one.
* Use `BTN3` to decrease the bmp value by one.
* You can change the bpm value any time by tapping the screen or using `BTN1` and `BTN3`.

View File

@ -0,0 +1 @@
require("heatshrink").decompress(atob("mEwxH+ABt4AB4fOFyFOABtUGDotOAAYvcp4ARqovbq0rACAvbqwABF98yGCAvdGAcHgAAEF8tWmIuGGA6QaF4lWFw4vgFwovPmIvuYDIvd0ejF59cF6qQFFwIvnMAguSqxfaFyQvYvOi0QuTF64uCAAQuRXwIvUqouEF6guFF5+cAAiOZF6iOaF5sxv+iF6xfRmVWFwWjv8rp4tSL6YvBqwuDMgQvnFwovURwIvQRggAELygvPgwuIF8ouEBwIvnFwwwXF54uBvwuFq0yF6buCF5guClQuFGAgvfFwcAF49WmIvRFwQvKFwkAmQvHYQMxF7l+FwgvKGAIvalQuGF5dWFx1VABVUvF4p0qAAdPCZNPF51OAD4vOKQIACF/4waF9wuEqgv/F/gwMF97vvAAUqADYtQAAMAADYuRGDgmLA="))

View File

@ -0,0 +1 @@
{"id":"metronome","name":"Metronome","src":"metronome.app.js", "icon": "metronome_icon.png", "sortorder":-2,"version":"0.03","files":"metronome.info,metronome.app.js, metronome_icon.png"}

View File

@ -0,0 +1,93 @@
var tStart = Date.now();
var cindex=0; // index to iterate through colous
var bpm=60; // ininital bpm value
var time_diffs = [1000, 1000, 1000]; //array to calculate mean bpm
var tindex=0; //index to iterate through time_diffs
Bangle.setLCDTimeout(undefined); //do not deaktivate display while running this app
function changecolor() {
const maxColors = 2;
const colors = {
0: { value: 0xFFFF, name: "White" },
1: { value: 0x000F, name: "Navy" },
// 2: { value: 0x03E0, name: "DarkGreen" },
// 3: { value: 0x03EF, name: "DarkCyan" },
// 4: { value: 0x7800, name: "Maroon" },
// 5: { value: 0x780F, name: "Purple" },
// 6: { value: 0x7BE0, name: "Olive" },
// 7: { value: 0xC618, name: "LightGray" },
// 8: { value: 0x7BEF, name: "DarkGrey" },
// 9: { value: 0x001F, name: "Blue" },
// 10: { value: 0x07E0, name: "Green" },
// 11: { value: 0x07FF, name: "Cyan" },
// 12: { value: 0xF800, name: "Red" },
// 13: { value: 0xF81F, name: "Magenta" },
// 14: { value: 0xFFE0, name: "Yellow" },
// 15: { value: 0xFFFF, name: "White" },
// 16: { value: 0xFD20, name: "Orange" },
// 17: { value: 0xAFE5, name: "GreenYellow" },
// 18: { value: 0xF81F, name: "Pink" },
};
g.setColor(colors[cindex].value);
if (cindex == maxColors-1) {
cindex = 0;
}
else {
cindex += 1;
}
return cindex;
}
function updateScreen() {
g.clear();
changecolor();
Bangle.buzz(50, 0.75);
g.setFont("Vector",48);
g.drawString(Math.floor(bpm)+"bpm", -1, 70);
}
Bangle.on('touch', function(button) {
// setting bpm by tapping the screen. Uses the mean time difference between several tappings.
if (tindex < time_diffs.length) {
if (Date.now()-tStart < 5000) {
time_diffs[tindex] = Date.now()-tStart;
}
} else {
tindex=0;
time_diffs[tindex] = Date.now()-tStart;
}
tindex += 1;
mean_time = 0.0;
for(count = 0; count < time_diffs.length; count++) {
mean_time += time_diffs[count];
}
time_diff = mean_time/count;
tStart = Date.now();
clearInterval(time_diff);
g.clear();
g.setFont("Vector",48);
bpm = (60 * 1000/(time_diff));
g.drawString(Math.floor(bpm)+"bpm", -1, 70);
clearInterval(interval);
interval = setInterval(updateScreen, 60000 / bpm);
return bpm;
});
// enable bpm finetuning via buttons.
setWatch(() => {
bpm += 1;
clearInterval(interval);
interval = setInterval(updateScreen, 60000 / bpm);
}, BTN1, {repeat:true});
setWatch(() => {
if (bpm > 1) {
bpm -= 1;
clearInterval(interval);
interval = setInterval(updateScreen, 60000 / bpm);
}
}, BTN3, {repeat:true});
interval = setInterval(updateScreen, 60000 / bpm);

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB