Skip to content

Instantly share code, notes, and snippets.

@smak7
Last active December 15, 2015 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smak7/1f5e8257bb3122d33a0b to your computer and use it in GitHub Desktop.
Save smak7/1f5e8257bb3122d33a0b to your computer and use it in GitHub Desktop.
artisanal tech flip flop code
// Variables
int pulsePin = 3; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin
// Volatile Variables, used in the interrupt service routine!
volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.
// Regards Serial OutPut -- Set This Up to your needs
static boolean serialVisual = false; // Set to 'false' by Default. Re-set to 'true' to see Arduino Serial Monitor ASCII Visual Pulse
void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE LESS THAN THE BOARD VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT VOLTAGE TO THE A-REF PIN
// analogReference(EXTERNAL);
}
// Where the Magic Happens
void loop(){
//serialOutput() ;
if (QS == true){ // A Heartbeat Was Found
// BPM and IBI have been Determined
// Quantified Self "QS" true when arduino finds a heartbeat
digitalWrite(blinkPin,HIGH); // Blink LED, we got a beat.
fadeRate = 255; // Makes the LED Fade Effect Happen
// Set 'fadeRate' Variable to 255 to fade LED with pulse
// serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false;
if(BPM > 45 && BPM < 95){
Serial.write(1);
// reset the Quantified Self flag for next time
}
}
ledFadeToBeat(); // Makes the LED Fade Effect Happen
delay(20); // take a break
}
void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}
import processing.serial.*;
import processing.pdf.*;
Serial myPort;
int val;
float lastTimeBeatFound = 0;
boolean bRecording = false;
void setup() {
size(500, 700);
background(255);
fill(255);
noStroke();
println(Serial.list());
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 115200);
}
void draw() {
if ( myPort.available () > 0) {
val = myPort.read();
println(val);
}
if (val == 1) {
lastTimeBeatFound = millis();
if(!bRecording){
bRecording = true;
beginRecord(PDF, "Lines-######.pdf");
println("START PDF");
}
//ellipseMode(CENTER);
//ellipse(width/2, height/2, random(48,50), random(48,50));
stroke(0);
triangle(random(0, 700), random(0, 700), random(0, 700), random(0, 700), random(0,700), random(0,700));
}else{
if( bRecording && millis() - lastTimeBeatFound > (5*1000)){
bRecording = false;
endRecord();
println("STOP PDF");
}
}
val = 0;
if(!bRecording){
background(255);
}
}
void mousePressed() {
beginRecord(PDF, "Lines.pdf");
background(255);
}
void mouseReleased() {
endRecord();
background(255);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment