Sam El-Husseini
Published © MIT

Microbit + Spotify (Windows)

Pause/resume your Spotify playlist with a micro:bit on Windows.

EasyFull instructions provided1 hour1,345
Microbit + Spotify (Windows)

Things used in this project

Hardware components

BBC micro:bit board
BBC micro:bit board
×2

Software apps and online services

MakeCode
Microsoft MakeCode
Spotify Web Helper

Story

Read more

Code

microbit-spotify-windows.js

JavaScript
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

Sam El-Husseini

Sam El-Husseini

2 projects • 4 followers
Working on MakeCode at Microsoft, micro:bits, Circuit Playground Express, and Minecraft.
Contact

Comments

Add projectSign up / Login