Skip to content

Instantly share code, notes, and snippets.

@k26dr
Created August 8, 2016 18:29
Show Gist options
  • Save k26dr/dcf751172ce5b82087d0d25cc2b28c97 to your computer and use it in GitHub Desktop.
Save k26dr/dcf751172ce5b82087d0d25cc2b28c97 to your computer and use it in GitHub Desktop.
Linking a Johnny 5 Tessel kit LCD screen up to the heart rate sensor
var five = require("johnny-five");
var Tessel = require("tessel-io");
var tessel = require('tessel');
var board = new five.Board({
io: new Tessel()
});
var pin = tessel.port.B.pin[2];
var startTime = new Date().getTime()
var high = true
var beats = 0
board.on("ready", () => {
var lcd = new five.LCD({
pins: ["a2", "a3", "a4", "a5", "a6", "a7"]
});
// lcd.cursor(0, 0).print("hello world");
// lcd.cursor(1, 0).print("this is LAAAAA");
setInterval(function () {
console.log("interval")
pin.analogRead(function(error, value) {
var time = (new Date().getTime() - startTime) / 1000
var bpm = Math.round(beats / time * 60)
console.log(time)
lcd.cursor(0,0).print(value.toString())
lcd.cursor(1,0).print(bpm.toString() + " BPM")
// lcd.cursor(1,0).print(beats)
if (value < 2.5 && high) {
high = false
beats += 1
}
else if (value > 2.5 && !high) {
high = true
}
});
}, 100)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment