Skip to content

Instantly share code, notes, and snippets.

@betzrhodes
Created September 6, 2015 00:48
Show Gist options
  • Save betzrhodes/0ad355558bc1eb2cb56a to your computer and use it in GitHub Desktop.
Save betzrhodes/0ad355558bc1eb2cb56a to your computer and use it in GitHub Desktop.
#require "rocky.class.nut:1.2.2"
#require "Twitter.class.nut:1.2.0"
const API_KEY = "";
const API_SECRET = "";
const AUTH_TOKEN = "";
const TOKEN_SECRET = "";
html <- @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<meta name='description' content>
<meta name='author' content>
<title>LED Demo</title>
<style>
button {
font-size: 3em;
border-radius: 4px;
color: #fff;
border : 1px solid #000;
margin: 10px 5px;
}
.colors {
text-align: center;
margin: 50px auto 10px;
}
#red {
display: inline-block;
background-color: red;
}
#blue {
display: inline-block;
background-color: blue;
}
#green {
display: inline-block;
background-color: green;
}
#off {
margin: 10px auto;
display: block;
background-color: #000;
}
</style>
</head>
<body>
<div class='colors'>
<button id='red'>RED</button>
<button id='green'>GREEN</button>
<button id='blue'>BLUE</button>
</div>
<button id='off'>OFF</button>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
<script>
$('button').on('click', function(e) {
e.preventdefault;
var button = e.currentTarget.id;
var route = window.location.href;
if( route.slice(-1) === '/' ) {
route = route + button;
} else {
route = route + '/' + button;
}
$.ajax({
url : route
});
});
</script>
</body>
</html>
"
on <- 30;
colors <- { "red" : [on, 0, 0],
"green" : [0, on, 0 ],
"blue" : [0, 0, on] };
///////////////// Twitter //////////////////
// twitter <- Twitter(API_KEY, API_SECRET, AUTH_TOKEN, TOKEN_SECRET)
// function onTweet(tweetData) {
// device.send("setColor", colors.blue);
// server.log(format("%s - %s", tweetData.text, tweetData.user.screen_name));
// }
// twitter.stream("#electricimp@pennApps", onTweet);
///////////////// Rocky ////////////////////
app <- Rocky();
app.get("/", function(context) {
context.send(200, html)
})
app.get("/red", function(context) {
context.send(200, "<h1 style='color:red; margin:80px; text-align: center; font-size: 3em'>RED</h1>");
device.send("setColor", colors.red);
});
app.get("/green", function(context) {
context.send(200, "<h1 style='color:green; margin:80px; text-align: center; font-size: 3em'>GREEN</h1>");
device.send("setColor", colors.green);
});
app.get("/blue", function(context) {
context.send(200, "<h1 style='color:blue; margin:80px; text-align: center; font-size: 3em'>BLUE</h1>");
device.send("setColor", colors.blue);
});
app.get("/off", function(context) {
context.send(200, "<h1 style='margin:80px; text-align: center; font-size: 3em'>OFF<h1>");
device.send("setColor", [0, 0, 0]);
});
#require "ws2812.class.nut:2.0.1"
pixels <- WS2812(hardware.spi257, 5, false).configure();
function setColor(color) {
pixels.fill(color).draw();
}
agent.on("setColor", setColor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment