Skip to content

Commit

Permalink
add pico-os.uf2, upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-h committed Aug 19, 2022
1 parent 7379456 commit 64ea809
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Binary file added pico-os.uf2
Binary file not shown.
16 changes: 5 additions & 11 deletions upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const instrumentKey = {
const reverseInstrumentKey = Object.fromEntries(Object.entries(instrumentKey).map(([k, v]) => [v, k]));
function textToTune(text) {
const elements = text.replace(/\\s/g, '').split(',');
const elements = text.replace(/\s/g, '').split(',');
const tune = [];
for (const element of elements) {
Expand All @@ -147,7 +147,7 @@ function textToTune(text) {
const duration = Math.round(parseInt(durationRaw));
const notes = (notesRaw || '').split('+').map((noteRaw) => {
if (!noteRaw) return [];
const [, pitchRaw, instrumentRaw, durationRaw] = noteRaw.match(/^(.+)([~\\-^\\/])(.+)$/);
const [, pitchRaw, instrumentRaw, durationRaw] = noteRaw.match(/^(.+)([~\-^\/])(.+)$/);
return [
instrumentKey[instrumentRaw],
isNaN(parseInt(pitchRaw, 10)) ? pitchRaw : parseInt(pitchRaw, 10),
Expand All @@ -164,13 +164,6 @@ const sleep = async (duration) => new Promise(_ => setTimeout(_, duration))
const INSTRUMENTS = ["sine", "triangle", "square", "sawtooth"];
function playFrequency(channel, frequency, duration) {
const { setvolume, setfreq } = require("i2saudio");
setvolume(channel, 1500);
setfreq(channel, frequency);
setTimeout(() => setvolume(channel, 0), duration);
}
const audio = require("i2saudio");
function playTuneHelper(tune, number, playingRef) {
for (let i = 0; i < tune.length*number; i++) {
Expand All @@ -188,8 +181,9 @@ function playTuneHelper(tune, number, playingRef) {
? tones[note.toUpperCase()]
: 2**((note-69)/12)*440;
if (INSTRUMENTS.includes(instrument) && f !== undefined)
audio.push_freq(f);
const i = INSTRUMENTS.indexOf(instrument);
if ((i >= 0) && f !== undefined)
audio.push_freq(f, i);
}
audio.wait(sleepTime);
}
Expand Down

0 comments on commit 64ea809

Please sign in to comment.