Gavin Dinubilo
Published

Music Controller

Control your music in Spotify or iTunes using some buttons, and a big switch!!

Full instructions provided1,191
Music Controller

Story

Read more

Code

file_7176.txt

C/C++
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>

#include "version.h"

void setup() {
  Scout.setup(SKETCH_NAME, SKETCH_REVISION, SKETCH_BUILD);
  // Add custom setup code here
}

void loop() {
  Scout.loop();
  // Add custom loop code here
  if (digitalRead(2) == 0) {
    Led.green();
  } else {
    Led.red();
  }
}

file_7177.js

JavaScript
var pinocc = require("pinoccio");
var applescript = require("applescript");
var colors = require('colors');

var api = pinocc("{{api-key}}");

var application = "Spotify";

function control(app, command) {
	var com;
	switch(command){
		case "playpause":
			com = 'tell application "' + app + '" to playpause'
			break;
		case "next":
			com = 'tell application "' + app + '" to next track'
			break;
		case "previous":
			com = 'tell application "' + app + '" to previous track'
			break;
	}

	applescript.execString(com, function(err, rtn) {
  		if (err) {
    	// Something went wrong!
    	console.error("ERROR!!!");
  		}
	});
}
var s = api.sync();

s.on("data", function(data){
	data = data.data;
	if(data.type === "digital" && data.troop === '2' && data.scout === '3'){
		if (data.value.state[0] === 0) {
			application = "Spotify"
			console.log('Now Using: '+ 'Spotify'.green);
		} else if(data.value.state[0] === 1) {
			application = "iTunes"
			console.log('Now Using: '+ 'iTunes'.red);
		}
	} else if (data.type === "digital" && data.troop === '2' && data.scout === '4') {
		if (data.value.state[0] === 0) {
			control(application, "previous");
		} else if(data.value.state[1] === 0) {
			control(application, "playpause");
		} else if(data.value.state[2] === 0) {
			control(application, "next");
		}
	}
});

Credits

Gavin Dinubilo

Gavin Dinubilo

7 projects • 8 followers

Comments