|
// 0_Variables |
|
// Version 14 April #01 |
|
#define led_pin_0 2 // pushup |
|
#define led_pin_1 13 // squats |
|
#define led_pin_2 12 // plank taps |
|
|
|
int pin_matrix[3] = {led_pin_0, led_pin_1, led_pin_2}; |
|
|
|
// matrix[i][j] |
|
// i = set number (1 = pushup, 2 = squat, 3 = plank) |
|
// j = level number |
|
// A_{ij} = required reps for set i at level j |
|
int myMatrix[3][5] = { |
|
{10, 20, 30, 40, 50}, |
|
{10, 20, 30, 40, 50}, |
|
{10, 20, 30, 40, 50}, |
|
}; |
|
|
|
|
|
int counter_0 = 0; |
|
int counter_1 = 0; |
|
int counter_2 = 0; |
|
|
|
// 1_TimerAndArrowLED |
|
#include <FastLED.h> |
|
|
|
#define PIN_ARROW 9 |
|
#define NUM_ARROWS 20 |
|
|
|
CRGB arrow_leds[20]; |
|
|
|
// Define constants for workout and rest phases |
|
const unsigned long duration_p = 45000; // 45 seconds |
|
const unsigned long duration_q = 15000; // 15 seconds |
|
|
|
// Define variables to keep track of time elapsed |
|
unsigned long workout_start_time = 0; |
|
unsigned long rest_start_time = 0; |
|
|
|
bool switch_p = true; |
|
bool switch_q = false; |
|
unsigned long current_time = 0; |
|
|
|
void red_led() { |
|
for (int i = 0; i < NUM_ARROWS ; i++) { |
|
arrow_leds[i] = CRGB::Black; |
|
} |
|
// Show the updated LEDs |
|
FastLED.show(); |
|
} |
|
void green_led() { |
|
int cycles_left = 25; |
|
while(cycles_left > 0) { |
|
for (int i = 0; i < NUM_ARROWS; i++) { |
|
arrow_leds[i] = CRGB::Green; |
|
} |
|
FastLED.setBrightness(50); |
|
FastLED.show(); |
|
delay(200); |
|
|
|
for (int i = 0; i < NUM_ARROWS; i++) { |
|
arrow_leds[i] = CRGB::Black; |
|
} |
|
FastLED.show(); |
|
delay(200); |
|
cycles_left--; |
|
} |
|
} |
|
void turn_off() { |
|
for (int i =0; i < NUM_ARROWS; i++) { |
|
arrow_leds[i] = CRGB::Black; |
|
} |
|
FastLED.show(); |
|
} |
|
|
|
|
|
void run_arrow_leds() { |
|
if (switch_p) { |
|
if (millis() - workout_start_time < duration_p) { |
|
red_led(); |
|
} else if (millis() - workout_start_time >= duration_p) { |
|
switch_p = false; |
|
switch_q = true; |
|
rest_start_time = millis(); |
|
} |
|
} else if (switch_q) { |
|
if (millis() - rest_start_time < duration_q) { |
|
green_led(); |
|
} else if (millis() - rest_start_time >= duration_q) { |
|
switch_q = false; |
|
switch_p = true; |
|
workout_start_time = millis(); |
|
} |
|
} |
|
} |
|
|
|
// 2_Sensors |
|
#define trig_0 3 |
|
#define trig_1 5 |
|
#define trig_2 7 |
|
#define echo_0 4 |
|
#define echo_1 6 |
|
#define echo_2 8 |
|
|
|
|
|
int current_state_0 = 0; |
|
int previous_state_0 = 0; |
|
boolean trig_up_0 = false; |
|
boolean trig_down_0 = false; |
|
|
|
int current_state_1 = 0; |
|
int previous_state_1 = 0; |
|
boolean trig_up_1 = false; |
|
boolean trig_down_1 = false; |
|
|
|
int current_state_2 = 0; |
|
int previous_state_2 = 0; |
|
boolean trig_up_2 = false; |
|
boolean trig_down_2 = false; |
|
|
|
|
|
void setup_sensors() { |
|
pinMode(trig_0, OUTPUT); |
|
pinMode(trig_1, OUTPUT); |
|
pinMode(trig_2, OUTPUT); |
|
pinMode(echo_0, INPUT); |
|
pinMode(echo_1, INPUT); |
|
pinMode(echo_2, INPUT); |
|
} |
|
|
|
|
|
void run_sensor_0() { |
|
long duration_0, distance_0; |
|
digitalWrite(trig_0, LOW); |
|
delayMicroseconds(2); |
|
digitalWrite(trig_0, HIGH); |
|
delayMicroseconds(10); |
|
digitalWrite(trig_0, LOW); |
|
duration_0 = pulseIn(echo_0, HIGH); |
|
distance_0 = duration_0 * 0.034/2.; |
|
|
|
if (distance_0>15 && distance_0<=30){ |
|
trig_up_0 = true; |
|
} else if (distance_0 < 10){ |
|
trig_down_0 = true; |
|
} else if(distance_0 >30) {} |
|
|
|
if (trig_up_0==true && trig_down_0==true){ |
|
counter_0=counter_0+1; |
|
trig_up_0=false; |
|
delay(200); |
|
trig_down_0=false; |
|
Serial.println("Pushup"); |
|
delay(10); |
|
Serial.println(counter_0); |
|
delay(10); |
|
} |
|
} |
|
void run_sensor_1() { |
|
long duration_1, distance_1; |
|
digitalWrite(trig_1, LOW); |
|
delayMicroseconds(2); |
|
digitalWrite(trig_1, HIGH); |
|
delayMicroseconds(10); |
|
digitalWrite(trig_1, LOW); |
|
duration_1 = pulseIn(echo_1, HIGH); |
|
distance_1 = duration_1 * 0.034/2.; |
|
|
|
if (distance_1>30 && distance_1<=60){ |
|
trig_up_1 = true; |
|
} else if (distance_1 < 30){ |
|
trig_down_1 = true; |
|
} else if(distance_1 >60) {} |
|
|
|
if (trig_up_1==true && trig_down_1==true){ |
|
counter_1=counter_1+1; |
|
trig_up_1=false; |
|
delay(200); |
|
trig_down_1=false; |
|
Serial.println("Squat"); |
|
delay(10); |
|
Serial.println(counter_1); |
|
delay(10); |
|
} |
|
|
|
} |
|
void run_sensor_2() { |
|
long duration_2, distance_2; |
|
digitalWrite(trig_2, LOW); |
|
delayMicroseconds(2); |
|
digitalWrite(trig_2, HIGH); |
|
delayMicroseconds(10); |
|
digitalWrite(trig_2, LOW); |
|
duration_2 = pulseIn(echo_2, HIGH); |
|
distance_2 = duration_2 * 0.034/2.; |
|
|
|
if (distance_2>10 && distance_2<=30){ |
|
trig_up_2 = true; |
|
} else if (distance_2 < 10){ |
|
trig_down_2 = true; |
|
} else if(distance_2 >30) {} |
|
|
|
if (trig_up_2==true && trig_down_2==true){ |
|
counter_2=counter_2+1; |
|
trig_up_2=false; |
|
delay(200); |
|
trig_down_2=false; |
|
Serial.println("Planks"); |
|
delay(10); |
|
Serial.println(counter_2); |
|
delay(10); |
|
} |
|
} |
|
|
|
|
|
// 3_LED |
|
// ======================== |
|
// BASIC LIGHT PATTERNS |
|
// ======================== |
|
#include <FastLED.h> |
|
FASTLED_USING_NAMESPACE |
|
#define LED_TYPE WS2811 |
|
#define PIN_ARROW 9 |
|
#define COLOR_ORDER GRB |
|
#define NUM_LEDS 20 |
|
#define BRIGHTNESS 255 |
|
#define FRAMES_PER_SECOND 120 |
|
CRGB leds[NUM_LEDS]; |
|
|
|
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current |
|
uint8_t gHue = 0; // rotating "base color" used by many of the patterns |
|
|
|
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) |
|
|
|
void rainbow() { |
|
// FastLED's built-in rainbow generator |
|
fill_rainbow(leds, NUM_LEDS, gHue, 7); |
|
} |
|
|
|
|
|
void rainbowWithGlitter() |
|
{ |
|
// built-in FastLED rainbow, plus some random sparkly glitter |
|
rainbow(); |
|
addGlitter(0.3125); |
|
} |
|
|
|
void addGlitter( float chanceOfGlitter) |
|
{ |
|
if( random8() < chanceOfGlitter) { |
|
leds[ random16(NUM_LEDS) ] += CRGB::White; |
|
} |
|
} |
|
|
|
|
|
|
|
void confetti() { |
|
// random colored speckles that blink in and fade smoothly |
|
fadeToBlackBy(leds, NUM_LEDS, 10); |
|
int pos = random16(NUM_LEDS); |
|
leds[pos] += CHSV(gHue + random8(64), 200, 255); |
|
} |
|
void sinelon() { |
|
// a colored dot sweeping back and forth, with fading trails |
|
fadeToBlackBy(leds, NUM_LEDS, 20); |
|
int pos = beatsin16(13, 0, NUM_LEDS - 1); |
|
leds[pos] += CHSV(gHue, 255, 192); |
|
} |
|
void bpm() { |
|
// colored stripes pulsing at a defined Beats-Per-Minute (BPM) |
|
uint8_t BeatsPerMinute = 62; |
|
CRGBPalette16 palette = PartyColors_p; |
|
uint8_t beat = beatsin8(BeatsPerMinute, 64, 255); |
|
for (int i = 0; i < NUM_LEDS; i++) { //9948 |
|
leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10)); |
|
} |
|
} |
|
void juggle() { |
|
// eight colored dots, weaving in and out of sync with each other |
|
fadeToBlackBy(leds, NUM_LEDS, 20); |
|
uint8_t dothue = 0; |
|
for (int i = 0; i < 8; i++) { |
|
leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(dothue, 200, 255); |
|
dothue += 32; |
|
} |
|
} |
|
void bground() { |
|
static int startIndex = 0; // starting index of the rainbow |
|
static int endIndex = 3; // ending index of the rainbow |
|
|
|
// loop through each LED within the specified range |
|
for (int i = startIndex; i <= endIndex; i++) { |
|
// calculate the color index based on the LED index |
|
uint8_t colorIndex = map(i, startIndex, endIndex, 150, 100); // start with green |
|
|
|
// generate a rainbow gradient |
|
CRGB color = CHSV(colorIndex, 255, 255); |
|
|
|
// set the color of the LED |
|
leds[i] = color; |
|
} |
|
|
|
FastLED.show(); |
|
delay(100); // adjust delay for speed |
|
|
|
// increment the start and end indices for the next loop iteration |
|
startIndex++; |
|
endIndex++; |
|
|
|
// if the end index is greater than the number of LEDs, reset the indices |
|
if (endIndex > NUM_LEDS) { |
|
startIndex = 0; |
|
endIndex = 3; |
|
} |
|
} |
|
|
|
#define COOLING 55 |
|
#define SPARKING 120 |
|
bool gReverseDirection = false; |
|
|
|
void Fire2012WithPalette() { |
|
random16_add_entropy( random()); |
|
CRGBPalette16 gPal; |
|
|
|
// gPal = HeatColors_p; |
|
|
|
gPal = CRGBPalette16( CRGB::Black, CRGB::Green, CRGB::Blue, CRGB::Purple); |
|
// Array of temperature readings at each simulation cell |
|
static uint8_t heat[NUM_LEDS]; |
|
|
|
// Step 1. Cool down every cell a little |
|
for( int i = 0; i < NUM_LEDS; i++) { |
|
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2)); |
|
} |
|
|
|
// Step 2. Heat from each cell drifts 'up' and diffuses a little |
|
for( int k= NUM_LEDS - 1; k >= 2; k--) { |
|
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; |
|
} |
|
|
|
// Step 3. Randomly ignite new 'sparks' of heat near the bottom |
|
if( random8() < SPARKING ) { |
|
int y = random8(7); |
|
heat[y] = qadd8( heat[y], random8(160,255) ); |
|
} |
|
|
|
// Step 4. Map from heat cells to LED colors |
|
for( int j = 0; j < NUM_LEDS; j++) { |
|
// Scale the heat value from 0-255 down to 0-240 |
|
// for best results with color palettes. |
|
uint8_t colorindex = scale8( heat[j], 240); |
|
CRGB color = ColorFromPalette( gPal, colorindex); |
|
int pixelnumber; |
|
if( gReverseDirection ) { |
|
pixelnumber = (NUM_LEDS-1) - j; |
|
} else { |
|
pixelnumber = j; |
|
} |
|
leds[pixelnumber] = color; |
|
} |
|
} |
|
|
|
|
|
// ============================ |
|
// VOID SETUP |
|
// ============================ |
|
void setup() { |
|
setup_sensors(); |
|
delay(200); |
|
// delay(3000); |
|
Serial.begin(9600); |
|
Serial.println("SETUP READY"); |
|
delay(300); |
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.addLeds<WS2812, PIN_ARROW, GRB>(arrow_leds, NUM_ARROWS); |
|
}; |
|
|
|
// 4_LEDsAdvanced |
|
// ADVANCED LED PROMPTS |
|
typedef void (*SimplePatternList[])(); |
|
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; |
|
SimplePatternList pattern_4 = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; |
|
SimplePatternList pattern_3 = { rainbow, juggle, bpm }; |
|
SimplePatternList pattern_2 = { juggle, bpm }; |
|
SimplePatternList pattern_1 = { bpm }; |
|
SimplePatternList pattern_0 = { bpm }; |
|
|
|
// Fire2012WithPalette |
|
void nextPattern() { |
|
// add one to the current pattern number, and wrap around at the end |
|
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE(pattern_4); |
|
} |
|
|
|
int range_matrix[5] = {6, 10, 10, 14, 20}; |
|
|
|
|
|
|
|
bool switch_4_0 = false; |
|
bool switch_3_0 = false; |
|
bool switch_2_0 = false; |
|
bool switch_1_0 = false; |
|
bool switch_0_0 = false; |
|
|
|
bool switch_4_1 = false; |
|
bool switch_3_1 = false; |
|
bool switch_2_1 = false; |
|
bool switch_1_1 = false; |
|
bool switch_0_1 = false; |
|
|
|
bool switch_4_2 = false; |
|
bool switch_3_2 = false; |
|
bool switch_2_2 = false; |
|
bool switch_1_2 = false; |
|
bool switch_0_2 = false; |
|
|
|
// ADVANCED LED PROMPTS |
|
void run_pattern_4_0() { |
|
if (switch_4_0) { |
|
int j_value = 4; |
|
FastLED.addLeds<LED_TYPE, led_pin_0, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_4[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_4_1() { |
|
if (switch_4_1) { |
|
int j_value = 4; |
|
FastLED.addLeds<LED_TYPE, led_pin_1, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_4[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_4_2() { |
|
if (switch_4_2) { |
|
int j_value = 4; |
|
FastLED.addLeds<LED_TYPE, led_pin_2, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_4[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
|
|
|
|
void run_pattern_3_0() { |
|
if (switch_3_0) { |
|
int j_value = 3; |
|
FastLED.addLeds<LED_TYPE, led_pin_0, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_3[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_3_1() { |
|
if (switch_3_1) { |
|
int j_value = 3; |
|
FastLED.addLeds<LED_TYPE, led_pin_1, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_3[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_3_2() { |
|
if (switch_3_2) { |
|
int j_value = 3; |
|
FastLED.addLeds<LED_TYPE, led_pin_2, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_3[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
|
|
void run_pattern_2_0() { |
|
if (switch_2_0) { |
|
int j_value = 2; |
|
FastLED.addLeds<LED_TYPE, led_pin_0, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_2[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_2_1() { |
|
if (switch_2_1) { |
|
int j_value = 2; |
|
FastLED.addLeds<LED_TYPE, led_pin_1, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_2[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_2_2() { |
|
if (switch_2_2) { |
|
int j_value = 2; |
|
FastLED.addLeds<LED_TYPE, led_pin_2, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_2[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
|
|
void run_pattern_1_0() { |
|
if (switch_1_0) { |
|
int j_value = 1; |
|
FastLED.addLeds<LED_TYPE, led_pin_0, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_1[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_1_1() { |
|
if (switch_1_1) { |
|
int j_value = 1; |
|
FastLED.addLeds<LED_TYPE, led_pin_1, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_1[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_1_2() { |
|
if (switch_1_2) { |
|
int j_value = 1; |
|
FastLED.addLeds<LED_TYPE, led_pin_2, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_1[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
|
|
|
|
void run_pattern_0_0() { |
|
if (switch_0_0) { |
|
int j_value = 0; |
|
FastLED.addLeds<LED_TYPE, led_pin_0, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_0[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_0_1() { |
|
if (switch_0_1) { |
|
int j_value = 0; |
|
FastLED.addLeds<LED_TYPE, led_pin_1, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_0[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
void run_pattern_0_2() { |
|
if (switch_0_2) { |
|
int j_value = 0; |
|
FastLED.addLeds<LED_TYPE, led_pin_2, COLOR_ORDER>(leds, range_matrix[j_value]).setCorrection(TypicalLEDStrip); |
|
|
|
pattern_0[gCurrentPatternNumber](); |
|
|
|
FastLED.setBrightness(BRIGHTNESS); |
|
FastLED.show(); |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } |
|
} |
|
} |
|
|
|
// 5_VoidLoop |
|
// matrix[i][j] |
|
// i = set number (1 = pushup, 2 = squat, 3 = plank) |
|
// j = level number |
|
// A_{ij} = required reps for set i at level j |
|
// int myMatrix[3][5] = { |
|
// {5, 10, 15, 20, 25}, |
|
// {3, 6, 9, 12, 15}, |
|
// {3, 6, 9, 12, 15}, |
|
// }; |
|
|
|
|
|
void decide_pattern_at_0() { |
|
// Serial.print("pushup\n"); |
|
if (counter_0 >= myMatrix[0][4]) { |
|
switch_4_0 = true; |
|
switch_3_0 = false; |
|
switch_2_0 = false; |
|
switch_1_0 = false; |
|
switch_0_0 = false; |
|
// Serial.print("4_0\n"); |
|
|
|
} else if (counter_0 >= myMatrix[0][3]) { |
|
switch_4_0 = false; |
|
switch_3_0 = true; |
|
switch_2_0 = false; |
|
switch_1_0 = false; |
|
switch_0_0 = false; |
|
// Serial.print("3_0\n"); |
|
|
|
} else if (counter_0 >= myMatrix[0][2]) { |
|
switch_4_0 = false; |
|
switch_3_0 = false; |
|
switch_2_0 = true; |
|
switch_1_0 = false; |
|
switch_0_0 = false; |
|
// Serial.print("2_0\n"); |
|
|
|
} else if (counter_0 >= myMatrix[0][1]) { |
|
switch_4_0 = false; |
|
switch_3_0 = false; |
|
switch_2_0 = false; |
|
switch_1_0 = true; |
|
switch_0_0 = false; |
|
// Serial.print("1_0\n"); |
|
|
|
} else if (counter_0 >= myMatrix[0][0]) { |
|
switch_4_0 = false; |
|
switch_3_0 = false; |
|
switch_2_0 = false; |
|
switch_1_0 = false; |
|
switch_0_0 = true; |
|
// Serial.print("0_0\n"); |
|
} |
|
} |
|
void decide_pattern_at_1() { |
|
// Serial.print("pushup\n"); |
|
if (counter_1 >= myMatrix[1][4]) { |
|
switch_4_1 = true; |
|
switch_3_1 = false; |
|
switch_2_1 = false; |
|
switch_1_1 = false; |
|
switch_0_1 = false; |
|
// Serial.print("4_0\n"); |
|
|
|
} else if (counter_1 >= myMatrix[1][3]) { |
|
switch_4_1 = false; |
|
switch_3_1 = true; |
|
switch_2_1 = false; |
|
switch_1_1 = false; |
|
switch_0_1 = false; |
|
// Serial.print("3_0\n"); |
|
|
|
} else if (counter_1 >= myMatrix[1][2]) { |
|
switch_4_1 = false; |
|
switch_3_1 = false; |
|
switch_2_1 = true; |
|
switch_1_1 = false; |
|
switch_0_1 = false; |
|
// Serial.print("2_0\n"); |
|
|
|
} else if (counter_1 >= myMatrix[1][1]) { |
|
switch_4_1 = false; |
|
switch_3_1 = false; |
|
switch_2_1 = false; |
|
switch_1_1 = true; |
|
switch_0_1 = false; |
|
// Serial.print("1_0\n"); |
|
|
|
} else if (counter_1 >= myMatrix[1][0]) { |
|
switch_4_1 = false; |
|
switch_3_1 = false; |
|
switch_2_1 = false; |
|
switch_1_1 = false; |
|
switch_0_1 = true; |
|
// Serial.print("0_0\n"); |
|
} |
|
} |
|
void decide_pattern_at_2() { |
|
// Serial.print("pushup\n"); |
|
if (counter_2 >= myMatrix[2][4]) { |
|
switch_4_2 = true; |
|
switch_3_2 = false; |
|
switch_2_2 = false; |
|
switch_1_2 = false; |
|
switch_0_2 = false; |
|
// Serial.print("4_0\n"); |
|
|
|
} else if (counter_2 >= myMatrix[2][3]) { |
|
switch_4_2 = false; |
|
switch_3_2 = true; |
|
switch_2_2 = false; |
|
switch_1_2 = false; |
|
switch_0_2 = false; |
|
// Serial.print("3_0\n"); |
|
|
|
} else if (counter_2 >= myMatrix[2][2]) { |
|
switch_4_2 = false; |
|
switch_3_2 = false; |
|
switch_2_2 = true; |
|
switch_1_2 = false; |
|
switch_0_2 = false; |
|
// Serial.print("2_0\n"); |
|
|
|
} else if (counter_2 >= myMatrix[2][1]) { |
|
switch_4_2 = false; |
|
switch_3_2 = false; |
|
switch_2_2 = false; |
|
switch_1_2 = true; |
|
switch_0_2 = false; |
|
// Serial.print("1_0\n"); |
|
|
|
} else if (counter_2 >= myMatrix[2][0]) { |
|
switch_4_2 = false; |
|
switch_3_2 = false; |
|
switch_2_2 = false; |
|
switch_1_2 = false; |
|
switch_0_2 = true; |
|
// Serial.print("0_0\n"); |
|
} |
|
} |
|
|
|
const unsigned long break_condition = 3*duration_p + 2*duration_q; |
|
// const unsigned long break_condition = 1000; |
|
|
|
|
|
void loop() { |
|
if (millis() <= break_condition) { |
|
run_arrow_leds(); |
|
|
|
run_sensor_0(); |
|
run_sensor_1(); |
|
run_sensor_2(); |
|
|
|
decide_pattern_at_0(); |
|
decide_pattern_at_1(); |
|
decide_pattern_at_2(); |
|
run_pattern_4_0(); |
|
run_pattern_4_1(); |
|
run_pattern_4_2(); |
|
|
|
run_pattern_3_0(); |
|
run_pattern_3_1(); |
|
run_pattern_3_2(); |
|
|
|
run_pattern_2_0(); |
|
run_pattern_2_1(); |
|
run_pattern_2_2(); |
|
|
|
run_pattern_1_0(); |
|
run_pattern_1_1(); |
|
run_pattern_1_2(); |
|
|
|
run_pattern_0_0(); |
|
run_pattern_0_1(); |
|
run_pattern_0_2(); |
|
|
|
} else if (millis() > break_condition) { |
|
turn_off(); |
|
FastLED.addLeds<LED_TYPE,13,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); |
|
FastLED.addLeds<LED_TYPE,12,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); |
|
FastLED.addLeds<LED_TYPE,2,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); |
|
|
|
gPatterns[gCurrentPatternNumber](); |
|
|
|
// send the 'leds' array out to the actual LED strip |
|
FastLED.show(); |
|
// insert a delay to keep the framerate modest |
|
FastLED.delay(1000/FRAMES_PER_SECOND); |
|
|
|
// do some periodic updates |
|
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow |
|
EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically |
|
|
|
|
|
|
|
|
|
} |
|
} |
|
|