public
Last active

node-serialport + arduino + popcorn.js DIY video scrubber

  • Download Gist
awesome.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
<html>
<head>
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="http://burritopizza.local/socket.io/socket.io.js"></script>
<script src="https://gist.github.com/raw/952547/f298c7e30d0978da0c78df0ff79436e883efbad2/gistfile1.txt"></script>
<script src="http://popcornjs.org/code/players/youtube/popcorn.youtube.js"></script>
<style type='text/css'>
body {
}
</style>
<script type='text/javascript'>
$(function() {
var monkeyGoat = "http://www.youtube.com/watch?v=T0LYbP3uwNU";
p = Popcorn(
Popcorn.youtube('monkeyGoat', monkeyGoat)
)
p.play();
var queued = false;
function queueChange(position) {
if ( position < 400 && position > 160 ) {
return;
}
if (!queued) {
setTimeout(function() {
if (position < 300) {
p.currentTime(p.currentTime() - 10);
console.log("BACK", position)
} else {
p.currentTime(p.currentTime() + 10);
console.log("FORWARD", position)
}
queued = false;
}, 100)
queued = true;
}
}
var socket = new io.Socket("burritopizza.local");
socket.connect();
socket.on('connect', function(){ console.log('connect!') })
socket.on('message', function(m){
// jsfxgui.doIt(m)
queueChange(m);
})
socket.on('disconnect', function(){ console.log('disconnect!') })
})
</script>
</head>
<body>
<h2>Soft Potentiometer + Arduino + Node.js + Socket.io + Popcorn.js + A Monkey Riding a Damn Goat = </h2>
<div id="monkeyGoat" style="width: 800px; height: 600px"></div>
<h1>AWESOME</h1>
</body>
</html>
monkeyridinggoat.pde
Processing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
 
void setup() {
Serial.begin(9600);
}
 
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
 
Serial.print(sensorValue);
 
delay(1);
}
serial.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
var sys = require("sys"),
repl = require("repl"),
serialPort = require("serialport").SerialPort,
 
// Required
defaults = {
baudrate: 9600
}
 
var serial = new serialPort("/dev/tty.usbmodem641" , defaults);
 
serial.on( "data", function( data ) {
data = +data;
console.log(data);
})

serial.js originally had a lot more logic but I accidentally deleted the file.

essentially it would read in sensor values and compute a running average of the last 50 values. This smoothed out the input from the linear potentiometer that was hooked up to the arduino since the input values were pretty chaotic.

It would then pipe that running average in to socket.io

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.