-
Notifications
You must be signed in to change notification settings - Fork 46
/
heart_pulse_blood_flowing.ino
75 lines (63 loc) · 2.71 KB
/
heart_pulse_blood_flowing.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//***************************************************************
// Heart pulse, blood flowing example
//
// Marc Miller, Jan 2016
//***************************************************************
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define NUM_LEDS 32
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 255
uint8_t bloodHue = 96; // Blood color [hue from 0-255]
uint8_t bloodSat = 255; // Blood staturation [0-255]
int flowDirection = -1; // Use either 1 or -1 to set flow direction
uint16_t cycleLength = 1500; // Lover values = continuous flow, higher values = distinct pulses.
uint16_t pulseLength = 150; // How long the pulse takes to fade out. Higher value is longer.
uint16_t pulseOffset = 200; // Delay before second pulse. Higher value is more delay.
uint8_t baseBrightness = 10; // Brightness of LEDs when not pulsing. Set to 0 for off.
//---------------------------------------------------------------
void setup() {
Serial.begin(115200);
delay(3000); // 3 second delay
//FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
//---------------------------------------------------------------
void loop() {
heartBeat(); // Heart beat function
FastLED.show();
}
//===============================================================
// Heart Beat Functions
// The base for all this goodness came from Mark Kriegsman and
// was initially coded up by Chris Thodey. I updated it to use
// HSV and provided all the variables to play with up above.
// -Marc
void heartBeat(){
for (int i = 0; i < NUM_LEDS ; i++) {
uint8_t bloodVal = sumPulse( (5/NUM_LEDS/2) + (NUM_LEDS/2) * i * flowDirection );
leds[i] = CHSV( bloodHue, bloodSat, bloodVal );
}
}
int sumPulse(int time_shift) {
//time_shift = 0; //Uncomment to heart beat/pulse all LEDs together
int pulse1 = pulseWave8( millis() + time_shift, cycleLength, pulseLength );
int pulse2 = pulseWave8( millis() + time_shift + pulseOffset, cycleLength, pulseLength );
return qadd8( pulse1, pulse2 ); // Add pulses together without overflow
}
uint8_t pulseWave8(uint32_t ms, uint16_t cycleLength, uint16_t pulseLength) {
uint16_t T = ms % cycleLength;
if ( T > pulseLength) return baseBrightness;
uint16_t halfPulse = pulseLength / 2;
if (T <= halfPulse ) {
return (T * 255) / halfPulse; //first half = going up
} else {
return((pulseLength - T) * 255) / halfPulse; //second half = going down
}
}
//End_heart_beat_functions
//---------------------------------------------------------------