From 436e376de9ba403ae698859d894f68082aeec218 Mon Sep 17 00:00:00 2001 From: "Matthias L. Jugel" Date: Sat, 25 Mar 2017 13:42:52 +0100 Subject: [PATCH] add midi example and i2c test --- libs/calliope-i2c/i2c.ts | 18 ++++++++++++++++++ libs/calliope-i2c/pxt.json | 11 +++++++++++ libs/calliope-midi/midi.ts | 23 +++++++++++++++++++++++ libs/calliope-midi/pxt.json | 11 +++++++++++ 4 files changed, 63 insertions(+) create mode 100644 libs/calliope-i2c/i2c.ts create mode 100644 libs/calliope-i2c/pxt.json create mode 100644 libs/calliope-midi/midi.ts create mode 100644 libs/calliope-midi/pxt.json diff --git a/libs/calliope-i2c/i2c.ts b/libs/calliope-i2c/i2c.ts new file mode 100644 index 00000000..d1d0d7b4 --- /dev/null +++ b/libs/calliope-i2c/i2c.ts @@ -0,0 +1,18 @@ +serial.writeLine("I2C"); +// send to 0x44, register 0x00, value 0x46 (RESET ISL29125) +pins.i2cWriteNumber(0x44, 0x0046, NumberFormat.UInt16BE); +// send to 0x44, register 0x01, value 0x05 (GRB SAMPLING) +pins.i2cWriteNumber(0x44, 0x0105, NumberFormat.UInt16BE); +basic.forever(() => { + serial.writeString("["); + pins.i2cWriteNumber(0x44, 0x0A, NumberFormat.Int8BE); + serial.writeNumber(pins.i2cReadNumber(0x44, NumberFormat.UInt8BE)); + serial.writeString(","); + pins.i2cWriteNumber(0x44, 0x0C, NumberFormat.UInt8BE); + serial.writeNumber(pins.i2cReadNumber(0x44, NumberFormat.UInt8BE)); + serial.writeString(","); + pins.i2cWriteNumber(0x44, 0x0E, NumberFormat.UInt8BE); + serial.writeNumber(pins.i2cReadNumber(0x44, NumberFormat.UInt8LE)); + serial.writeLine("]"); + basic.pause(1000); +}); \ No newline at end of file diff --git a/libs/calliope-i2c/pxt.json b/libs/calliope-i2c/pxt.json new file mode 100644 index 00000000..d5e66d31 --- /dev/null +++ b/libs/calliope-i2c/pxt.json @@ -0,0 +1,11 @@ +{ + "name": "calliope-i2c", + "description": "Calliope I2C test", + "files": [ + "i2c.ts" + ], + "public": true, + "dependencies": { + "core": "file:../core" + } +} diff --git a/libs/calliope-midi/midi.ts b/libs/calliope-midi/midi.ts new file mode 100644 index 00000000..f384598b --- /dev/null +++ b/libs/calliope-midi/midi.ts @@ -0,0 +1,23 @@ +serial.redirect( + SerialPin.P0, + SerialPin.P1, + 31250 +); + +basic.forever(() => { + for (let note = 0; note <= 90 - 1; note++) { + // Note on channel 1 (0x90), some note value (note), + // middle velocity (0x45): + serial.writeString(String.fromCharCode(144)); + serial.writeString(String.fromCharCode(note)); + serial.writeString(String.fromCharCode(69)); + basic.pause(100); + // Note on channel 1 (0x90), some note value (note), + // silent velocity (0x00): + serial.writeString(String.fromCharCode(144)); + serial.writeString(String.fromCharCode(note)); + serial.writeString("\0"); + basic.pause(100); + basic.pause(1000); + } +}); diff --git a/libs/calliope-midi/pxt.json b/libs/calliope-midi/pxt.json new file mode 100644 index 00000000..72fadda6 --- /dev/null +++ b/libs/calliope-midi/pxt.json @@ -0,0 +1,11 @@ +{ + "name": "midi", + "description": "MIDI Example via Serial", + "files": [ + "midi.ts" + ], + "public": true, + "dependencies": { + "core": "file:../core" + } +}