Alex Glow
Published © CC BY-SA

HoloClock

A mobile, smart holography studio.

BeginnerFull instructions provided1,675
HoloClock

Things used in this project

Story

Read more

Schematics

LED + Laser diagram

LED into D7, laser into D0, and both into GND.

Code

HoloClock.ino

C/C++
Paste this into the Particle cloud editor and upload it to your Photon. Largely based on James' code. Has a weird tendency to re-run occasionally, without warning.
// -----------------------------------
// Controlling Holographic Laser
// -----------------------------------
// laser is D0, indicator is D7

int laser = D0;
int indicator = D7;

void setup() {
   pinMode(laser, OUTPUT);
   pinMode(indicator, OUTPUT);

   Spark.function("heat", heatToggle);

   // ensure on power on the relay is in a predictable state
   digitalWrite(laser, LOW);
   digitalWrite(indicator, LOW);
}

void loop() {
   // Nothing to do here
}

int heatToggle(String command) {
        digitalWrite(laser, HIGH);
        digitalWrite(indicator, HIGH);
        delay(3000);
        digitalWrite(laser, LOW);
        digitalWrite(indicator, LOW);
}

James' Lambda function

JavaScript
"This AWS Lambda function take the type of click from the IoT button and calls the remote method on our particle device with the appropriate arguments to turn the heat on or off. Note the access token and the actual device ID have been removed." – https://www.hackster.io/seigel/prestart-409d98
var https = require('https');

exports.handler = function(event, context) {
    // data to send to Particle for our remote message
    var data = {
        args: (event.clickType === "SINGLE" ? "on" : "off")
    };
    var options = {
        hostname: 'api.particle.io',
        port: 443,
        path: '/v1/devices/<device id>/heat?access_token=<access_token>',
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Content-Length': JSON.stringify(data).length
        }
    };   

    var req = https.request(options, function(res) {
        var body = '';
        console.log('Status:', res.statusCode);
        console.log('Headers:', JSON.stringify(res.headers));
        res.setEncoding('utf8');
        res.on('data', function(chunk) {
            body += chunk;
        });
        res.on('end', function() {
            console.log('Successfully processed HTTPS response');
            // If we know it's JSON, parse it
            if (res.headers['content-type'] === 'application/json') {
                body = JSON.parse(body);
            }
            context.succeed(body);
        });
    });
    req.on('error', context.fail);
    req.write(JSON.stringify(data));
    req.end();
};

Credits

Alex Glow

Alex Glow

145 projects • 1570 followers
The Hackster team's resident Hardware Nerd. I love robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments