Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Triggered breathing aka sine wave starting at 0.
- *
- * By: Andrew Tuline
- *
- * Date: May, 2020
- *
- * I selected a sine function that starts at 0 and the standard sine functions do not do that.
- * No point in phase shifting, etc, if I can just use an alternate function, i.e. cubicwave, etc.
- *
- */
- #include <FastLED.h>
- #define LED_PIN 12
- #define NUM_LEDS 40
- #define COLOR_ORDER GRB
- #define LED_TYPE WS2812B
- #define MAX_BRIGHTNESS 255
- struct CRGB leds[NUM_LEDS];
- void setup() {
- Serial.begin(115200);
- LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(MAX_BRIGHTNESS);
- FastLED.clear();
- } // setup()
- void loop() {
- EVERY_N_MILLIS(3000) { // Trigger the event every 3 seconds. Could also use a button, etc.
- triggered(1);
- }
- EVERY_N_MILLIS(10) { // Continusly call the sine wave routine.
- triggered(0);
- }
- FastLED.show();
- } // loop()
- void triggered(uint8_t trigger) {
- static uint16_t counte = 256; // High count.
- if (counte >255) Serial.println(0);
- if (trigger) {counte=0;}
- if (counte < 256) {
- uint16_t breathing = cubicwave8(counte++);
- breathing = breathing * breathing /256; // Optional multiplier to reduce the wave time.
- Serial.println(breathing);
- // fill_solid(leds, NUM_LEDS, CHSV(40, 250, breathing));
- }
- } // triggered()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement