Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created May 12, 2011 15:37
Show Gist options
  • Save max-mapper/968773 to your computer and use it in GitHub Desktop.
Save max-mapper/968773 to your computer and use it in GitHub Desktop.
node-serialport + arduino + popcorn.js DIY video scrubber
<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>
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);
}
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);
})
@max-mapper
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment