FastLED 3.9.15
Loading...
Searching...
No Matches
lib8tion.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef __INC_LIB8TION_H
4#define __INC_LIB8TION_H
5
6#include "FastLED.h"
7#include "lib8tion/types.h"
8#include "fl/deprecated.h"
9
10#include "fl/compiler_control.h"
11
18
19
20#ifndef __INC_LED_SYSDEFS_H
21#error WTH? led_sysdefs needs to be included first
22#endif
23
27
28#include "fl/stdint.h"
29#include "lib8tion/lib8static.h"
30#include "lib8tion/qfx.h"
31#include "lib8tion/memmove.h"
32#include "lib8tion/config.h"
33#include "fl/ease.h"
34
35
36#if !defined(__AVR__)
37#include <string.h>
38// for memmove, memcpy, and memset if not defined here
39#endif // end of !defined(__AVR__)
40
41
232
233
234
235
236#include "lib8tion/math8.h"
237#include "lib8tion/scale8.h"
238#include "lib8tion/random8.h"
239#include "lib8tion/trig8.h"
240
242
243
244
245
247
248
255
258{
259 return y / 32768.0f;
260}
261
266{
267 return static_cast<sfract15>(f * 32768.0f);
268}
269
271
272
273
274
275
290
293LIB8STATIC uint8_t lerp8by8( uint8_t a, uint8_t b, fract8 frac)
294{
295 uint8_t result;
296 if( b > a) {
297 uint8_t delta = b - a;
298 uint8_t scaled = scale8( delta, frac);
299 result = a + scaled;
300 } else {
301 uint8_t delta = a - b;
302 uint8_t scaled = scale8( delta, frac);
303 result = a - scaled;
304 }
305 return result;
306}
307
310LIB8STATIC uint16_t lerp16by16( uint16_t a, uint16_t b, fract16 frac)
311{
312 uint16_t result;
313 if( b > a ) {
314 uint16_t delta = b - a;
315 uint16_t scaled = scale16(delta, frac);
316 result = a + scaled;
317 } else {
318 uint16_t delta = a - b;
319 uint16_t scaled = scale16( delta, frac);
320 result = a - scaled;
321 }
322 return result;
323}
324
327LIB8STATIC uint16_t lerp16by8( uint16_t a, uint16_t b, fract8 frac)
328{
329 uint16_t result;
330 if( b > a) {
331 uint16_t delta = b - a;
332 uint16_t scaled = scale16by8( delta, frac);
333 result = a + scaled;
334 } else {
335 uint16_t delta = a - b;
336 uint16_t scaled = scale16by8( delta, frac);
337 result = a - scaled;
338 }
339 return result;
340}
341
344LIB8STATIC int16_t lerp15by8( int16_t a, int16_t b, fract8 frac)
345{
346 int16_t result;
347 if( b > a) {
348 uint16_t delta = b - a;
349 uint16_t scaled = scale16by8( delta, frac);
350 result = a + scaled;
351 } else {
352 uint16_t delta = a - b;
353 uint16_t scaled = scale16by8( delta, frac);
354 result = a - scaled;
355 }
356 return result;
357}
358
361LIB8STATIC int16_t lerp15by16( int16_t a, int16_t b, fract16 frac)
362{
363 int16_t result;
364 if( b > a) {
365 uint16_t delta = b - a;
366 uint16_t scaled = scale16( delta, frac);
367 result = a + scaled;
368 } else {
369 uint16_t delta = a - b;
370 uint16_t scaled = scale16( delta, frac);
371 result = a - scaled;
372 }
373 return result;
374}
375
397LIB8STATIC uint8_t map8( uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
398{
399 uint8_t rangeWidth = rangeEnd - rangeStart;
400 uint8_t out = scale8( in, rangeWidth);
401 out += rangeStart;
402 return out;
403}
404
406
407
414
417#if (EASE8_C == 1) || defined(FASTLED_DOXYGEN)
418LIB8STATIC uint8_t ease8InOutQuad( uint8_t i)
419{
420 uint8_t j = i;
421 if( j & 0x80 ) {
422 j = 255 - j;
423 }
424 uint8_t jj = scale8( j, j);
425 uint8_t jj2 = jj << 1;
426 if( i & 0x80 ) {
427 jj2 = 255 - jj2;
428 }
429 return jj2;
430}
431
432#elif EASE8_AVRASM == 1
433// This AVR asm version of ease8InOutQuad preserves one more
434// low-bit of precision than the C version, and is also slightly
435// smaller and faster.
436LIB8STATIC uint8_t ease8InOutQuad(uint8_t val) {
437 uint8_t j=val;
438 asm volatile (
439 "sbrc %[val], 7 \n"
440 "com %[j] \n"
441 "mul %[j], %[j] \n"
442 "add r0, %[j] \n"
443 "ldi %[j], 0 \n"
444 "adc %[j], r1 \n"
445 "lsl r0 \n" // carry = high bit of low byte of mul product
446 "rol %[j] \n" // j = (j * 2) + carry // preserve add'l bit of precision
447 "sbrc %[val], 7 \n"
448 "com %[j] \n"
449 "clr __zero_reg__ \n"
450 : [j] "+&a" (j)
451 : [val] "a" (val)
452 : "r0", "r1"
453 );
454 return j;
455}
456
457#else
458#error "No implementation for ease8InOutQuad available."
459#endif
460
461LIB8STATIC uint16_t ease16InOutQuad( uint16_t i)
462{
463 // This is the legacy version, there is a slightly more accurate version in fl/ease.cpp
464 // with fl::easeInOutQuad16. However the difference is minimal.
465 //
466 // 16-bit quadratic ease-in / ease-out function
467 uint16_t j = i;
468 if (j & 0x8000) {
469 j = 65535 - j;
470 }
471 uint16_t jj = scale16(j, j);
472 uint16_t jj2 = jj << 1;
473 if (i & 0x8000) {
474 jj2 = 65535 - jj2;
475 }
476 return jj2;
477}
478
479LIB8STATIC uint16_t ease16InOutCubic(uint16_t i) {
480 // This function produces wrong results, use fl::easeInOutCubic16 instead
481 //
482 // 16-bit cubic ease-in / ease-out function
483 // Equivalent to ease8InOutCubic() but for 16-bit values
484 // Formula: 3(x^2) - 2(x^3) applied with proper ease-in-out curve
485
486 // Apply the cubic formula directly, similar to the 8-bit version
487 // scale16(a, b) computes (a * b) / 65536
488 uint32_t ii = scale16(i, i); // i^2 scaled to 16-bit
489 uint32_t iii = scale16(ii, i); // i^3 scaled to 16-bit
490
491 // Apply cubic formula: 3x^2 - 2x^3
492 uint32_t r1 = (3 * ii) - (2 * iii);
493
494 // Clamp result to 16-bit range
495 if (r1 > 65535) {
496 return 65535;
497 }
498 return (uint16_t)r1;
499}
500
501
505{
506 uint8_t ii = scale8_LEAVING_R1_DIRTY( i, i);
507 uint8_t iii = scale8_LEAVING_R1_DIRTY( ii, i);
508
509 uint16_t r1 = (3 * (uint16_t)(ii)) - ( 2 * (uint16_t)(iii));
510
511 /* the code generated for the above *'s automatically
512 cleans up R1, so there's no need to explicitily call
513 cleanup_R1(); */
514
515 uint8_t result = r1;
516
517 // if we got "256", return 255:
518 if( r1 & 0x100 ) {
519 result = 255;
520 }
521 return result;
522}
523
524
532#if (EASE8_C == 1) || defined(FASTLED_DOXYGEN)
534{
535 if( i < 64) {
536 // start with slope 0.5
537 i /= 2;
538 } else if( i > (255 - 64)) {
539 // end with slope 0.5
540 i = 255 - i;
541 i /= 2;
542 i = 255 - i;
543 } else {
544 // in the middle, use slope 192/128 = 1.5
545 i -= 64;
546 i += (i / 2);
547 i += 32;
548 }
549
550 return i;
551}
552
553#elif EASE8_AVRASM == 1
555{
556 // takes around 7 cycles on AVR
557 asm volatile (
558 " subi %[i], 64 \n\t"
559 " cpi %[i], 128 \n\t"
560 " brcc Lshift_%= \n\t"
561
562 // middle case
563 " mov __tmp_reg__, %[i] \n\t"
564 " lsr __tmp_reg__ \n\t"
565 " add %[i], __tmp_reg__ \n\t"
566 " subi %[i], 224 \n\t"
567 " rjmp Ldone_%= \n\t"
568
569 // start or end case
570 "Lshift_%=: \n\t"
571 " lsr %[i] \n\t"
572 " subi %[i], 96 \n\t"
573
574 "Ldone_%=: \n\t"
575
576 : [i] "+a" (i)
577 :
578 : "r0"
579 );
580 return i;
581}
582#else
583#error "No implementation for ease8 available."
584#endif
585
587
588
595
596
608LIB8STATIC uint8_t triwave8(uint8_t in)
609{
610 if( in & 0x80) {
611 in = 255 - in;
612 }
613 uint8_t out = in << 1;
614 return out;
615}
616
627LIB8STATIC uint8_t quadwave8(uint8_t in)
628{
629 return ease8InOutQuad( triwave8( in));
630}
631
635LIB8STATIC uint8_t cubicwave8(uint8_t in)
636{
637 return ease8InOutCubic( triwave8( in));
638}
639
640
664LIB8STATIC uint8_t squarewave8( uint8_t in, uint8_t pulsewidth=128)
665{
666 if( in < pulsewidth || (pulsewidth == 255)) {
667 return 255;
668 } else {
669 return 0;
670 }
671}
672
674
676
677
684
685#if ((defined(ARDUINO) || defined(SPARK) || defined(FASTLED_HAS_MILLIS)) && !defined(USE_GET_MILLISECOND_TIMER)) || defined(FASTLED_DOXYGEN)
686// Forward declaration of Arduino function 'millis'.
687//uint32_t millis();
688
699#define GET_MILLIS millis
700#else
701uint32_t get_millisecond_timer();
702#define GET_MILLIS get_millisecond_timer
703#endif
704
706
707
710
711
750
751
759LIB8STATIC uint16_t beat88( accum88 beats_per_minute_88, uint32_t timebase = 0)
760{
761 // BPM is 'beats per minute', or 'beats per 60000ms'.
762 // To avoid using the (slower) division operator, we
763 // want to convert 'beats per 60000ms' to 'beats per 65536ms',
764 // and then use a simple, fast bit-shift to divide by 65536.
765 //
766 // The ratio 65536:60000 is 279.620266667:256; we'll call it 280:256.
767 // The conversion is accurate to about 0.05%, more or less,
768 // e.g. if you ask for "120 BPM", you'll get about "119.93".
769 return (((GET_MILLIS()) - timebase) * beats_per_minute_88 * 280) >> 16;
770}
771
775LIB8STATIC uint16_t beat16( accum88 beats_per_minute, uint32_t timebase = 0)
776{
777 // Convert simple 8-bit BPM's to full Q8.8 accum88's if needed
778 if( beats_per_minute < 256) beats_per_minute <<= 8;
779 return beat88(beats_per_minute, timebase);
780}
781
785LIB8STATIC uint8_t beat8( accum88 beats_per_minute, uint32_t timebase = 0)
786{
787 return beat16( beats_per_minute, timebase) >> 8;
788}
789
790
801LIB8STATIC uint16_t beatsin88( accum88 beats_per_minute_88, uint16_t lowest = 0, uint16_t highest = 65535,
802 uint32_t timebase = 0, uint16_t phase_offset = 0)
803{
804 uint16_t beat = beat88( beats_per_minute_88, timebase);
805 uint16_t beatsin = (sin16( beat + phase_offset) + 32768);
806 uint16_t rangewidth = highest - lowest;
807 uint16_t scaledbeat = scale16( beatsin, rangewidth);
808 uint16_t result = lowest + scaledbeat;
809 return result;
810}
811
819LIB8STATIC uint16_t beatsin16( accum88 beats_per_minute, uint16_t lowest = 0, uint16_t highest = 65535,
820 uint32_t timebase = 0, uint16_t phase_offset = 0)
821{
822 uint16_t beat = beat16( beats_per_minute, timebase);
823 uint16_t beatsin = (sin16( beat + phase_offset) + 32768);
824 uint16_t rangewidth = highest - lowest;
825 uint16_t scaledbeat = scale16( beatsin, rangewidth);
826 uint16_t result = lowest + scaledbeat;
827 return result;
828}
829
837LIB8STATIC uint8_t beatsin8( accum88 beats_per_minute, uint8_t lowest = 0, uint8_t highest = 255,
838 uint32_t timebase = 0, uint8_t phase_offset = 0)
839{
840 uint8_t beat = beat8( beats_per_minute, timebase);
841 uint8_t beatsin = sin8( beat + phase_offset);
842 uint8_t rangewidth = highest - lowest;
843 uint8_t scaledbeat = scale8( beatsin, rangewidth);
844 uint8_t result = lowest + scaledbeat;
845 return result;
846}
847
849
851
852
857
861{
862 uint32_t ms = GET_MILLIS();
863 uint16_t s16;
864 s16 = ms / 1000;
865 return s16;
866}
867
871{
872 uint32_t ms = GET_MILLIS();
873 uint16_t m16;
874 m16 = (ms / (60000L)) & 0xFFFF;
875 return m16;
876}
877
881{
882 uint32_t ms = GET_MILLIS();
883 uint8_t h8;
884 h8 = (ms / (3600000L)) & 0xFF;
885 return h8;
886}
887
888
902LIB8STATIC uint16_t div1024_32_16( uint32_t in32)
903{
904 uint16_t out16;
905#if defined(__AVR__)
906 asm volatile (
907 " lsr %D[in] \n\t"
908 " ror %C[in] \n\t"
909 " ror %B[in] \n\t"
910 " lsr %D[in] \n\t"
911 " ror %C[in] \n\t"
912 " ror %B[in] \n\t"
913 " mov %B[out],%C[in] \n\t"
914 " mov %A[out],%B[in] \n\t"
915 : [in] "+r" (in32),
916 [out] "=r" (out16)
917 );
918#else
919 out16 = (in32 >> 10) & 0xFFFF;
920#endif
921 return out16;
922}
923
928{
929 uint32_t ms = GET_MILLIS();
930 uint16_t s16;
931 s16 = div1024_32_16( ms);
932 return s16;
933}
934
938#if 1
939#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME,TIMETYPE,TIMEGETTER) \
940class NAME { \
941public: \
942 TIMETYPE mPrevTrigger; \
943 TIMETYPE mPeriod; \
944 \
945 NAME() { reset(); mPeriod = 1; }; \
946 NAME(TIMETYPE period) { reset(); setPeriod(period); }; \
947 void setPeriod( TIMETYPE period) { mPeriod = period; }; \
948 TIMETYPE getTime() { return (TIMETYPE)(TIMEGETTER()); }; \
949 TIMETYPE getPeriod() { return mPeriod; }; \
950 TIMETYPE getElapsed() { return getTime() - mPrevTrigger; } \
951 TIMETYPE getRemaining() { return mPeriod - getElapsed(); } \
952 TIMETYPE getLastTriggerTime() { return mPrevTrigger; } \
953 bool ready() { \
954 bool isReady = (getElapsed() >= mPeriod); \
955 if( isReady ) { reset(); } \
956 return isReady; \
957 } \
958 void reset() { mPrevTrigger = getTime(); }; \
959 void trigger() { mPrevTrigger = getTime() - mPeriod; }; \
960 \
961 operator bool() { return ready(); } \
962};
963
968
969#if defined(FASTLED_DOXYGEN)
983public:
984 TIMETYPE mPrevTrigger;
985 TIMETYPE mPeriod;
986
988 CEveryNTime() { reset(); mPeriod = 1; };
991 CEveryNTime(TIMETYPE period) { reset(); setPeriod(period); };
992
994 void setPeriod( TIMETYPE period) { mPeriod = period; };
995
997 TIMETYPE getTime() { return (TIMETYPE)(TIMEGETTER()); };
998
1000 TIMETYPE getPeriod() { return mPeriod; };
1001
1003 TIMETYPE getElapsed() { return getTime() - mPrevTrigger; }
1004
1006 TIMETYPE getRemaining() { return mPeriod - getElapsed(); }
1007
1009 TIMETYPE getLastTriggerTime() { return mPrevTrigger; }
1010
1012 bool ready() {
1013 bool isReady = (getElapsed() >= mPeriod);
1014 if( isReady ) { reset(); }
1015 return isReady;
1016 }
1017
1019 void reset() { mPrevTrigger = getTime(); };
1020
1023
1025 operator bool() { return ready(); }
1026};
1027#endif // FASTLED_DOXYGEN
1028
1031
1034
1037
1040
1043
1045#define CEveryNMilliseconds CEveryNMillis
1046
1049public:
1051 uint32_t mPeriod;
1052
1053 CEveryNMillisDynamic(uint32_t period) : mPeriod(period) { reset(); };
1054 uint32_t getTime() { return GET_MILLIS(); };
1055 uint32_t getPeriod() const { return mPeriod; };
1056 uint32_t getElapsed() { return getTime() - mPrevTrigger; }
1057 uint32_t getRemaining() { return getPeriod() - getElapsed(); }
1058 uint32_t getLastTriggerTime() { return mPrevTrigger; }
1059 bool ready() {
1060 bool isReady = (getElapsed() >= getPeriod());
1061 if( isReady ) { reset(); }
1062 return isReady;
1063 }
1064 void reset() { mPrevTrigger = getTime(); };
1066 void setPeriod(uint32_t period) { mPeriod = period; }
1067
1068 operator bool() { return ready(); }
1069};
1070
1071
1072
1073
1074// ————————————————————————————————————————————————
1075// Random‐interval version of EVERY_N_MILLISECONDS:
1076// on each trigger, pick the next period randomly in [MIN..MAX].
1077// ————————————————————————————————————————————————
1079public:
1081 uint32_t mPeriod;
1082 uint32_t mMinPeriod;
1083 uint32_t mMaxPeriod;
1084
1085 CEveryNMillisRandom(uint32_t minPeriod, uint32_t maxPeriod)
1086 : mMinPeriod(minPeriod), mMaxPeriod(maxPeriod)
1087 {
1088 computeNext();
1089 reset();
1090 }
1091
1093 // random16(x) returns [0..x-1], so this yields MIN..MAX
1094 uint32_t range = mMaxPeriod - mMinPeriod + 1;
1095 mPeriod = mMinPeriod + random16(range);
1096 }
1097
1098 uint32_t getTime() const { return GET_MILLIS(); }
1099
1100 bool ready() {
1101 uint32_t now = getTime();
1102 if (now - mPrevTrigger >= mPeriod) {
1103 mPrevTrigger = now;
1104 computeNext();
1105 return true;
1106 }
1107 return false;
1108 }
1109
1111};
1112
1113#else
1114
1115// Under C++11 rules, we would be allowed to use not-external
1116// -linkage-type symbols as template arguments,
1117// e.g., LIB8STATIC seconds16, and we'd be able to use these
1118// templates as shown below.
1119// However, under C++03 rules, we cannot do that, and thus we
1120// have to resort to the preprocessor to 'instantiate' 'templates',
1121// as handled above.
1122template<typename timeType,timeType (*timeGetter)()>
1123class CEveryNTimePeriods {
1124public:
1125 timeType mPrevTrigger;
1126 timeType mPeriod;
1127
1128 CEveryNTimePeriods() { reset(); mPeriod = 1; };
1129 CEveryNTimePeriods(timeType period) { reset(); setPeriod(period); };
1130 void setPeriod( timeType period) { mPeriod = period; };
1131 timeType getTime() { return (timeType)(timeGetter()); };
1132 timeType getPeriod() { return mPeriod; };
1133 timeType getElapsed() { return getTime() - mPrevTrigger; }
1134 timeType getRemaining() { return mPeriod - getElapsed(); }
1135 timeType getLastTriggerTime() { return mPrevTrigger; }
1136 bool ready() {
1137 bool isReady = (getElapsed() >= mPeriod);
1138 if( isReady ) { reset(); }
1139 return isReady;
1140 }
1141 void reset() { mPrevTrigger = getTime(); };
1142 void trigger() { mPrevTrigger = getTime() - mPeriod; };
1143
1144 operator bool() { return ready(); }
1145};
1146typedef CEveryNTimePeriods<uint16_t,seconds16> CEveryNSeconds;
1147typedef CEveryNTimePeriods<uint16_t,bseconds16> CEveryNBSeconds;
1148typedef CEveryNTimePeriods<uint32_t,millis> CEveryNMillis;
1149typedef CEveryNTimePeriods<uint16_t,minutes16> CEveryNMinutes;
1150typedef CEveryNTimePeriods<uint8_t,hours8> CEveryNHours;
1151#endif
1152
1153
1168
1170#define CONCAT_HELPER( x, y ) x##y
1171#define CONCAT_MACRO( x, y ) CONCAT_HELPER( x, y )
1173
1174
1177#define EVERY_N_MILLIS(N) EVERY_N_MILLIS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1178
1181#define EVERY_N_MILLIS_I(NAME,N) static CEveryNMillis NAME(N); if( NAME )
1182
1183
1186#define EVERY_N_SECONDS(N) EVERY_N_SECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1187
1190#define EVERY_N_SECONDS_I(NAME,N) static CEveryNSeconds NAME(N); if( NAME )
1191
1192
1195#define EVERY_N_BSECONDS(N) EVERY_N_BSECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1196
1199#define EVERY_N_BSECONDS_I(NAME,N) static CEveryNBSeconds NAME(N); if( NAME )
1200
1201
1204#define EVERY_N_MINUTES(N) EVERY_N_MINUTES_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1205
1208#define EVERY_N_MINUTES_I(NAME,N) static CEveryNMinutes NAME(N); if( NAME )
1209
1210
1213#define EVERY_N_HOURS(N) EVERY_N_HOURS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1214
1217#define EVERY_N_HOURS_I(NAME,N) static CEveryNHours NAME(N); if( NAME )
1218
1219
1221#define EVERY_N_MILLISECONDS(N) EVERY_N_MILLIS(N)
1223#define EVERY_N_MILLISECONDS_I(NAME,N) EVERY_N_MILLIS_I(NAME,N)
1224
1226#define EVERY_N_MILLISECONDS_DYNAMIC(PERIOD_FUNC) EVERY_N_MILLISECONDS_DYNAMIC_I(CONCAT_MACRO(__dynamic_millis_timer, __COUNTER__ ), (PERIOD_FUNC))
1227
1229#define EVERY_N_MILLISECONDS_DYNAMIC_I(NAME, PERIOD_FUNC) \
1230 static CEveryNMillisDynamic NAME(1); \
1231 NAME.setPeriod(PERIOD_FUNC); \
1232 if( NAME )
1233
1234
1235#define EVERY_N_MILLISECONDS_RANDOM(MIN, MAX) \
1236 EVERY_N_MILLISECONDS_RANDOM_I( \
1237 CONCAT_MACRO(_permRand, __COUNTER__), MIN, MAX)
1238
1239#define EVERY_N_MILLISECONDS_RANDOM_I(NAME, MIN, MAX) \
1240 static CEveryNMillisRandom NAME(MIN, MAX); \
1241 if (NAME.ready())
1242
1245
1246
1247// These defines are used to declare hidden or commented symbols for the
1248// purposes of Doxygen documentation generation. They do not affect your program.
1249#ifdef FASTLED_DOXYGEN
1253#define USE_GET_MILLISECOND_TIMER
1254#endif
1255
1257
1258#endif
1259
int y
Definition simple.h:93
central include file for FastLED, defines the CFastLED class/object
void setPeriod(uint32_t period)
Definition lib8tion.h:1066
uint32_t getLastTriggerTime()
Definition lib8tion.h:1058
uint32_t getPeriod() const
Definition lib8tion.h:1055
uint32_t getRemaining()
Definition lib8tion.h:1057
uint32_t getElapsed()
Definition lib8tion.h:1056
CEveryNMillisDynamic(uint32_t period)
Definition lib8tion.h:1053
CEveryNMillisRandom(uint32_t minPeriod, uint32_t maxPeriod)
Definition lib8tion.h:1085
uint32_t getTime() const
Definition lib8tion.h:1098
uint32_t mPrevTrigger
Definition lib8tion.h:1080
void trigger()
Reset the timestamp so it is ready() on next call.
Definition lib8tion.h:1022
TIMETYPE mPeriod
Timing interval to check.
Definition lib8tion.h:985
CEveryNTime(TIMETYPE period)
Constructor.
Definition lib8tion.h:991
TIMETYPE getLastTriggerTime()
Get the timestamp of the most recent trigger event.
Definition lib8tion.h:1009
CEveryNTime()
Default constructor.
Definition lib8tion.h:988
TIMETYPE getTime()
Get the current time according to the class' timekeeper.
Definition lib8tion.h:997
TIMETYPE getElapsed()
Get the time elapsed since the last trigger event.
Definition lib8tion.h:1003
void setPeriod(TIMETYPE period)
Set the time interval between triggers.
Definition lib8tion.h:994
bool ready()
Check if the time interval has elapsed.
Definition lib8tion.h:1012
void reset()
Reset the timestamp to the current time.
Definition lib8tion.h:1019
TIMETYPE getPeriod()
Get the time interval between triggers.
Definition lib8tion.h:1000
TIMETYPE mPrevTrigger
Timestamp of the last time the class was "ready".
Definition lib8tion.h:984
TIMETYPE getRemaining()
Get the time until the next trigger event.
Definition lib8tion.h:1006
#define FL_DISABLE_WARNING_RETURN_TYPE
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_SIGN_CONVERSION
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_UNUSED_PARAMETER
#define FL_DISABLE_WARNING_FLOAT_CONVERSION
UIButton trigger("Trigger")
LIB8STATIC uint8_t beat8(accum88 beats_per_minute, uint32_t timebase=0)
Generates an 8-bit "sawtooth" wave at a given BPM.
Definition lib8tion.h:785
LIB8STATIC uint16_t beat88(accum88 beats_per_minute_88, uint32_t timebase=0)
Generates a 16-bit "sawtooth" wave at a given BPM, with BPM specified in Q8.8 fixed-point format.
Definition lib8tion.h:759
LIB8STATIC uint16_t beatsin16(accum88 beats_per_minute, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:819
LIB8STATIC uint16_t beat16(accum88 beats_per_minute, uint32_t timebase=0)
Generates a 16-bit "sawtooth" wave at a given BPM.
Definition lib8tion.h:775
LIB8STATIC uint8_t beatsin8(accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:837
LIB8STATIC uint16_t beatsin88(accum88 beats_per_minute_88, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:801
LIB8STATIC uint16_t ease16InOutQuad(uint16_t i)
Definition lib8tion.h:461
LIB8STATIC uint16_t ease16InOutCubic(uint16_t i)
Definition lib8tion.h:479
LIB8STATIC fract8 ease8InOutApprox(fract8 i)
Fast, rough 8-bit ease-in/ease-out function.
Definition lib8tion.h:533
LIB8STATIC uint8_t ease8InOutQuad(uint8_t i)
8-bit quadratic ease-in / ease-out function.
Definition lib8tion.h:418
LIB8STATIC fract8 ease8InOutCubic(fract8 i)
8-bit cubic ease-in / ease-out function.
Definition lib8tion.h:504
LIB8STATIC sfract15 floatToSfract15(float f)
Conversion from IEEE754 float in the range (-1,1) to 16-bit fixed point (sfract15).
Definition lib8tion.h:265
LIB8STATIC float sfract15ToFloat(sfract15 y)
Conversion from 16-bit fixed point (sfract15) to IEEE754 32-bit float.
Definition lib8tion.h:257
LIB8STATIC uint8_t lerp8by8(uint8_t a, uint8_t b, fract8 frac)
Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.
Definition lib8tion.h:293
LIB8STATIC uint16_t lerp16by16(uint16_t a, uint16_t b, fract16 frac)
Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
Definition lib8tion.h:310
LIB8STATIC uint16_t lerp16by8(uint16_t a, uint16_t b, fract8 frac)
Linear interpolation between two unsigned 16-bit values, with 8-bit fraction.
Definition lib8tion.h:327
LIB8STATIC int16_t lerp15by8(int16_t a, int16_t b, fract8 frac)
Linear interpolation between two signed 15-bit values, with 8-bit fraction.
Definition lib8tion.h:344
LIB8STATIC int16_t lerp15by16(int16_t a, int16_t b, fract16 frac)
Linear interpolation between two signed 15-bit values, with 8-bit fraction.
Definition lib8tion.h:361
LIB8STATIC uint8_t map8(uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
Definition lib8tion.h:397
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
Definition random8.h:56
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
Definition scale8.h:180
LIB8STATIC uint16_t scale16(uint16_t i, fract16 scale)
Scale a 16-bit unsigned value by an 16-bit value, which is treated as the numerator of a fraction who...
Definition scale8.h:551
LIB8STATIC_ALWAYS_INLINE uint16_t scale16by8(uint16_t i, fract8 scale)
Scale a 16-bit unsigned value by an 8-bit value, which is treated as the numerator of a fraction whos...
Definition scale8.h:478
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:44
#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME, TIMETYPE, TIMEGETTER)
Preprocessor-based class "template" for CEveryNTime, used with EVERY_N_TIME timekeepers.
Definition lib8tion.h:939
LIB8STATIC uint16_t minutes16()
Return the current minutes since boot in a 16-bit value.
Definition lib8tion.h:870
LIB8STATIC uint16_t bseconds16()
Returns the current time-since-boot in "binary seconds", which are actually 1024/1000 of a second lon...
Definition lib8tion.h:927
#define GET_MILLIS
The a number of functions need access to a millisecond counter in order to keep time.
Definition lib8tion.h:699
LIB8STATIC uint16_t div1024_32_16(uint32_t in32)
Helper routine to divide a 32-bit value by 1024, returning only the low 16 bits.
Definition lib8tion.h:902
LIB8STATIC uint8_t hours8()
Return the current hours since boot in an 8-bit value.
Definition lib8tion.h:880
LIB8STATIC uint16_t seconds16()
Return the current seconds since boot in a 16-bit value.
Definition lib8tion.h:860
#define sin16
Platform-independent alias of the fast sin implementation.
Definition trig8.h:112
#define sin8
Platform-independent alias of the fast sin implementation.
Definition trig8.h:230
LIB8STATIC uint8_t cubicwave8(uint8_t in)
Cubic waveform generator.
Definition lib8tion.h:635
LIB8STATIC uint8_t squarewave8(uint8_t in, uint8_t pulsewidth=128)
Square wave generator.
Definition lib8tion.h:664
LIB8STATIC uint8_t quadwave8(uint8_t in)
Quadratic waveform generator.
Definition lib8tion.h:627
LIB8STATIC uint8_t triwave8(uint8_t in)
Triangle wave generator.
Definition lib8tion.h:608
#define LIB8STATIC
Define a LIB8TION member function as static inline with an "unused" attribute.
Definition lib8static.h:10
Defines static inlining macros for lib8tion functions.
Defines fractional types used for lib8tion functions.
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
Definition namespace.h:23
#define FASTLED_NAMESPACE_BEGIN
Definition namespace.h:22
i16 sfract15
ANSI: signed _Fract.
Definition int.h:68
u8 fract8
Fixed-Point Fractional Types.
Definition int.h:49
u16 accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Definition int.h:70
u16 fract16
ANSI: unsigned _Fract.
Definition int.h:59
Fast, efficient random number generators specifically designed for high-performance LED programming.
Fast, efficient 8-bit scaling functions specifically designed for high-performance LED programming.
Fast, efficient 8-bit trigonometry functions specifically designed for high-performance LED programmi...