Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
7 changes: 7 additions & 0 deletions JavaScript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Instructions
------------

1. Connect the Pulse Sensor to the "A0" pin of the Arduino
2. Burn Standard Firmata to Arduino memory
3. Navigate to the current directory on the console
4. Run 'node app.js'
105 changes: 105 additions & 0 deletions JavaScript/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
var rate = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
sampleCounter = 0,
lastBeatTime = 0,
P = 512,
T = 512,
thresh = 525,
amp = 100,
firstBeat = true,
secondBeat = false,
IBI = 600,
Pulse = false,
BPM,
Signal,
QS = false;

var five = require('johnny-five'),
board, sensor;
board = new five.Board();

board.on('ready', function() {
sensor = new five.Sensor({
pin: "A0",
freq: 2
});

sensor.scale([0,1024]).on('read', function() {
Signal = this.scaled;
calculate_bpm();

if(QS === true) {
console.log('BPM : ', BPM);
QS = false;
}
});
});

function calculate_bpm() {

sampleCounter += 2;
N = sampleCounter - lastBeatTime;

if(Signal < thresh && N > (IBI/5)*3) {
if (Signal < T) {
T = Signal;
}
}

if(Signal > thresh && Signal > P) {
P = Signal;
}


if (N > 250) {

if ((Signal > thresh) && (Pulse === false) && (N > (IBI/5)*3)) {
Pulse = true;
IBI = sampleCounter - lastBeatTime;
lastBeatTime = sampleCounter;

if(secondBeat) {
secondBeat = false;
for(var i=0; i<=9; i++){
rate[i] = IBI;
}
}

if(firstBeat) {
firstBeat = false;
secondBeat = true;
return;
}


var runningTotal = 0;

for(var i=0; i<=8; i++) {
rate[i] = rate[i+1];
runningTotal += rate[i];
}

rate[9] = IBI;
runningTotal += rate[9];
runningTotal /= 10;
BPM = 60000/runningTotal;
QS = true;
}
}

if (Signal < thresh && Pulse === true){
Pulse = false;
amp = P - T;
thresh = amp/2 + T;
P = thresh;
T = thresh;
}

if (N > 2500) {
thresh = 512;
P = 512;
T = 512;
lastBeatTime = sampleCounter;
firstBeat = true;
secondBeat = false;
}
}
29 changes: 29 additions & 0 deletions JavaScript/node_modules/johnny-five/.jscsrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions JavaScript/node_modules/johnny-five/.jshintrc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions JavaScript/node_modules/johnny-five/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions JavaScript/node_modules/johnny-five/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions JavaScript/node_modules/johnny-five/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading