Things used in this project

Hardware components:
Microbitheart
BBC micro:bit board
×2
Software apps and online services:
Screen shot 2017 06 26 at 3 41 02 pm sfoohotutu
Microsoft MakeCode
Spotify Web Helper

Code

microbit-spotify-windows.jsJavaScript
var SerialPort = require("serialport");
const Readline = SerialPort.parsers.Readline;

const SpotifyWebHelper = require('spotify-web-helper');
const spotify = SpotifyWebHelper({'port': 4381});

var port = new SerialPort('COM7', {
 baudRate: 115200,
 autoOpen: false
})
const parser = new Readline();
port.pipe(parser);

spotify.player.on('ready', () => {
    console.log("Spotify ready")
    port.open(() => {
        console.log("Port open");
        parser.on('data', (data) => {
            console.log('Received Data: ' + data.toString());
            processData(data);
        });
    })

    function processData(data) {
        if (data.indexOf('PLAY') == 0) {
            // Handle PLAY received
            spotify.player.pause(true);
        } else if (data.indexOf('PAUSE') == 0) {
            // Handle PAUSE received
            spotify.player.pause(false);
        }
    }
});

Credits

Thumb 2 edrkme11ef
Sam El-Husseini
2 projects • 2 followers
Working on MakeCode at Microsoft, micro:bits, Circuit Playground Express, and Minecraft.
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login