Robert Gallup
Published © Apache-2.0

Euphonic You

An ambient soundtrack that reflects status and events in your physical and virtual world

IntermediateWork in progress1,659
Euphonic You

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
Smart Things Multi-Sensor
×1
Smart Things Hub
×1
Teensy 3.0 Microcontroller
×1

Story

Read more

Schematics

Euphonic You Prototype Components

This shows the Spark Core which has been configured as a Smart Things device. Also shown is the Teensy 3.0 which is programmed as a MIDI device to control a sound synthesizer on the laptop. Finally, the Smart Things multi-sensor controls the Spark Core through the Ambience On, Ambience Off application.

Code

Spark Core Firmware

Plain text
This is what responds to HTTP requests from the Smart Things Euphonia device.
/* A Spark function to parse the commands */
int ledControl(String command);

// We name pin D7 as led
int led = D7; 

// This routine runs only once upon reset
void setup() 
{
  //Register Spark function
  Spark.function("ledstate", ledControl);    
  // Initialize D0 pin as an output
  pinMode(led, OUTPUT);
}

// This routine loops forever 
void loop()
{
  // Nothing to do here
}

int ledControl(String command)
{
  if (command == "1") {   
    digitalWrite(led, HIGH);   // Turn ON the LED
    return 1;
  } else {               
    digitalWrite(led, LOW);    // Turn OFF the LED
    return 0;
  }
}

Spark Core Blink Device Handler

Plain text
This turns the Euphonia device (Teensy) on and off.
/**
 *  Spark Core Blink
 *
 *  Copyright 2015 Robert Gallup
 *
 */

preferences {
    input("deviceId", "text", title: "Device ID")
    input("token", "text", title: "Access Token")
}

metadata {
	definition (name: "Spark Core Blink", namespace: "robertgallup", author: "Robert Gallup") {
		capability "Switch"
	}

	simulator {
		// TODO: define status and reply messages here
	}

    // tile definitions
	tiles {
		standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
			state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
			state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
		}

		main "switch"
		details "switch"
	}

}

// parse events into attributes
def parse(String description) {
	log.error "This device does not support incoming events"
	// TODO: handle 'switch' attribute
}

def on() {
	put '1'
}

def off() {
	put '0'
}

private put(led) {
    //Spark Core API Call
	httpPost(
		uri: "https://api.spark.io/v1/devices/${deviceId}/ledstate",
        body: [access_token: token, command: led],  
	) {response -> log.debug (response.data)}
}

Ambience On, Ambience Off Smart Things Application

Plain text
This closes the loop between the multi-sensor and the Euphonia device
/**
 *  Lights Off, When Closed
 *
 *  Author: SmartThings/Robert Gallup
 */
definition(
    name: "Ambience On, Ambience Off",
    namespace: "smartthings",
    author: "SmartThings",
    description: "Turn your lights off when an open/close sensor closes.",
    category: "Convenience",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet@2x.png"
)

preferences {
	section ("When the door closes...") {
		input "contact1", "capability.contactSensor", title: "Where?"
	}
	section ("Turn off a light...") {
		input "switch1", "capability.switch"
	}
}

def initialize() {
    subscribe(contact1, "contact.closed", contactClosedHandler)
    subscribe(contact1, "contact.open", contactOpenHandler)
}

def installed()
{
	initialize ()
}

def updated()
{
	unsubscribe()
	initialize ()
}

def contactClosedHandler(evt) {
	switch1.off()
}

def contactOpenHandler(evt) {
	switch1.on()
}

Credits

Robert Gallup

Robert Gallup

1 project • 7 followers
Entrepreneur, technologist, designer, maker, coder, speaker, and instigator. Co-founder: PDX Maker Week.

Comments