Created
November 6, 2014 19:53
-
-
Save basecode/ec386986f1b988c0cba7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tessel = require('tessel'); | |
var audio = require('audio-vs1053b').use(tessel.port['A']); | |
var climate = require('climate-si7020').use(tessel.port['B']); | |
var chunks = []; | |
// When we get data, push it into our array | |
audio.on('data', function(data) { | |
chunks.push(data); | |
}); | |
// Wait for the module to connect | |
audio.on('ready', function() { | |
console.log('Hold the config button to record...'); | |
// When the config button is pressed, start recording | |
tessel.button.once('press', startRecording); | |
}); | |
function startRecording() { | |
// Tell the audio module to start recording | |
audio.startRecording('voice', function() { | |
console.log('Recording...'); | |
// Once the button is released, stop recording | |
tessel.button.once('release', stopRecording); | |
}); | |
} | |
function stopRecording() { | |
// Tell the audio module to stop recording | |
console.log('stopping the recording...'); | |
audio.stopRecording(function() { | |
console.log('Playing it back...'); | |
readTemperatureLoop(); | |
// Concat the data and play it | |
/*audio.play(Buffer.concat(chunks), function(err) { | |
// When we're done playing, clear recordings | |
chunks = []; | |
console.log('Hold the config button to record...'); | |
// Wait for a button press again | |
});*/ | |
}); | |
} | |
function readTemperatureLoop() { | |
console.log('Connected to si7020'); | |
// Loop forever | |
setImmediate(function loop () { | |
climate.readTemperature('f', function (err, tempFahrenheit) { | |
climate.readHumidity(function (err, humid) { | |
var tempCelsius = (tempFahrenheit - 30) / 2; | |
console.log('Degrees:', tempCelsius.toFixed(4) + 'C', 'Humidity:', humid.toFixed(4) + '%RH'); | |
if (tempCelsius > 26) { | |
audio.play(Buffer.concat(chunks), function(err) { | |
if (err) console.log('error', err); | |
}); | |
} | |
setTimeout(loop, 300); | |
}); | |
}); | |
}); | |
} | |
/*climate.on('ready', function () { | |
console.log('Connected to si7020'); | |
// Loop forever | |
setImmediate(function loop () { | |
climate.readTemperature('f', function (err, tempFahrenheit) { | |
climate.readHumidity(function (err, humid) { | |
var tempCelsius = (tempFahrenheit - 30) / 2; | |
console.log('Degrees:', tempCelsius.toFixed(4) + 'C', 'Humidity:', humid.toFixed(4) + '%RH'); | |
setTimeout(loop, 300); | |
}); | |
}); | |
}); | |
});*/ | |
climate.on('error', function(err) { | |
console.log('climate: error connecting module', err); | |
}); | |
// If there is an error, report it | |
audio.on('error', function(err) { | |
console.log('audio: error connecting module', err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment