Skip to content
155 changes: 155 additions & 0 deletions demos/laurensong.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<!DOCTYPE html>
<html>

<head>
<title>Birthday Song demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
<link href="../css/styles.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
<style>
body {
background-color: OldLace; //make different so pages can be known on sight.
}
</style>

<script>
var tempo = 2000;
mysong = [
[293.7, tempo * .1875],
[293.7, tempo * .0675],
[329.6, tempo * .25],
[293.7, tempo * .25],
[392, tempo * .25],
[370, tempo * .5],
[null, tempo * .25],
[293.7, tempo * .1875],
[293.7, tempo * .0675],
[329.6, tempo * .25],
[293.7, tempo * .25],
[440, tempo * .25],
[392, tempo * .5],
[null, tempo * .0625],
[null, tempo * .0625], //extra nulls so rests happen
[null, tempo * .0625], //at pauses (every 16 notes)
[293.7, tempo * .1875],
[293.7, tempo * .0675],
[587.3, tempo * .25],
[493.9, tempo * .25],
[392, tempo * .25],
[370, tempo * .25],
[329.6, tempo * .25],
[null, tempo * .5],
[523.3, tempo * .125],
[523.3, tempo * .125],
[493.9, tempo * .25],
[392, tempo * .25],
[440, tempo * .25],
[392, tempo * .5]
];

$(document).ready(function() {

$("#togglesensors").click(function(e) {
$("#allsensors").toggleClass('hidden');
});
var socket = io.connect('http://10.48.102.xxx:3001'); //change this to match your robot
socket.on('sensordata', function(data) {
$("#voltage").text(data.battery.voltage.volts.toFixed(2));
$("#current").text(data.battery.current.amps.toFixed(2));
var power = data.battery.voltage.volts * data.battery.current.amps;
$("#power").text(power.toFixed(2));
$("#allsensors").text(JSON.stringify(data));
});




$("#playsong").click(function(e) {
socket.emit('sing', mysong);
});

$("#passiveMode").click(function(e) {
socket.emit('passiveMode');
});
$("#safeMode").click(function(e) {
socket.emit('safeMode');
});

$("#fullMode").click(function(e) {
socket.emit('fullMode');
});


$('body').keydown(function(event) {

console.log(event.which);
if (event.which === 80) //p - play

{
event.preventDefault();
socket.emit('sing', mysong);
}

if (event.which === 49) //1 -- Play tune when 1 is pressed

{
event.preventDefault();
socket.emit('sing', [
[640, 100],
[650, 100]
]);
}

});

});
</script>

</head>

<body>
<div class="container">

<div class="row">
<div class="col-xs-3 sensor-block col-xs-offset-1">
<div class="sensor-title">Voltage</div>
<div class="sensor-value" id="voltage">...</div>
</div>
<div class="col-xs-3 sensor-block col-xs-offset-1">
<div class="sensor-title">Current</div>
<div class="sensor-value" id="current">...</div>
</div>
<div class="col-xs-3 sensor-block col-xs-offset-1">
<div class="sensor-title">Power</div>
<div class="sensor-value" id="power">...</div>
</div>
</div>

<h3>Robot Control</h3>
<div class="row">
<button class="btn-success btn col-md-2" id="passiveMode">Passive Mode</button>
<button class="btn-warning btn col-md-2" id="safeMode">Safe Mode</button>
<button class="btn-danger btn col-md-2" id="fullMode">Full Mode</button>
</div>

<div class="row">
<div class="col-xs-3">
<button id="playsong" class="btn-success btn-lg btn-block">Play Music
<span class="glyphicon glyphicon-music"></span>
</button>
</div>
</div>

<div class="row">
<button id="togglesensors">Toggle Sensors</button>
<div class="hidden" id="allsensors">...</div>
</div>

</div>

</body>

</html>
Loading