Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node.jsで心拍センサ使ってみた / heartbeat sensor on Node.js

shanonim
December 17, 2015

Node.jsで心拍センサ使ってみた / heartbeat sensor on Node.js

2015.12.16
JSオジサン#6 @21cafe
https://atnd.org/events/71990

shanonim

December 17, 2015
Tweet

More Decks by shanonim

Other Decks in Technology

Transcript

  1. ʁ

  2. // THIS IS THE TIMER 2 INTERRUPT SERVICE ROUTINE. //

    Timer 2 makes sure that we take a reading every 2 miliseconds ISR(TIMER2_COMPA_vect){ // triggered when Timer2 counts to 124 cli(); // disable interrupts while we do this Signal = analogRead(pulsePin); // read the Pulse Sensor sampleCounter += 2; // keep track of the time in mS with this variable int N = sampleCounter - lastBeatTime; // monitor the time since the last beat to avoid noise ... board.on('ready', function() { var led = new five.Led(13); sensor = new five.Sensor( { pin: 'A0', freq: 2 }); sensor.on('data', function() { signal = this.value; sampleCounter += 2; var n = sampleCounter - lastBeatTime; Node.js C
  3. var ds = milkcocoa.dataStore('heartbeat'); ds.stream().size(10).next(function(err, datas) { var averageHeartbeat =

    0; datas.forEach(function(data) { averageHeartbeat += data.value.heartbeat; }); averageHeartbeat /= 10; });