Advertisement
atuline

Triggered single sine wave

Aug 21st, 2020 (edited)
1,712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. /* Triggered breathing aka sine wave starting at 0.
  2.  *  
  3.  *  By: Andrew Tuline
  4.  *  
  5.  *  Date: May, 2020
  6.  *  
  7.  *  I selected a sine function that starts at 0 and the standard sine functions do not do that.
  8.  *  No point in phase shifting, etc, if I can just use an alternate function, i.e. cubicwave, etc.
  9.  *  
  10.  */
  11.  
  12. #include <FastLED.h>
  13.  
  14. #define LED_PIN 12
  15. #define NUM_LEDS 40
  16. #define COLOR_ORDER GRB
  17. #define LED_TYPE WS2812B
  18. #define MAX_BRIGHTNESS 255    
  19.  
  20. struct CRGB leds[NUM_LEDS];
  21.  
  22. void setup() {
  23.   Serial.begin(115200);
  24.   LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  25.   FastLED.setBrightness(MAX_BRIGHTNESS);
  26.   FastLED.clear();
  27. } // setup()
  28.  
  29.  
  30.  
  31. void loop() {
  32.  
  33.   EVERY_N_MILLIS(3000) {             // Trigger the event every 3 seconds. Could also use a button, etc.
  34.     triggered(1);
  35.   }
  36.  
  37.   EVERY_N_MILLIS(10) {              // Continusly call the sine wave routine.
  38.     triggered(0);
  39.   }
  40.  
  41.   FastLED.show();
  42. } // loop()
  43.  
  44.  
  45.  
  46. void triggered(uint8_t trigger) {
  47.  
  48.   static uint16_t counte = 256;     // High count.
  49.  
  50.   if (counte >255) Serial.println(0);
  51.  
  52.     if (trigger) {counte=0;}
  53.     if (counte < 256) {
  54.       uint16_t breathing = cubicwave8(counte++);
  55.       breathing = breathing * breathing /256;                        // Optional multiplier to reduce the wave time.
  56.       Serial.println(breathing);
  57. //      fill_solid(leds, NUM_LEDS, CHSV(40, 250, breathing));
  58.     }
  59. } // triggered()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement