blargbeast

Untitled

Dec 2nd, 2023
778
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 1 0
  1.  
  2. volatile uint8_t BRIGHTNESS_BUFFER[NUM_LEDS] = { 0 };
  3. volatile uint8_t current_led = 0;
  4. volatile uint8_t pwm_counter = 0;
  5.  
  6. ISR(TCA0_OVF_vect) {
  7.   static uint32_t lastCheck = 0;
  8.   static uint32_t lastCheck2 = 0;
  9.   static uint8_t rot = 0;
  10.  
  11.   if (countDown(&lastCheck2, 10)) {
  12.     BRIGHTNESS_BUFFER[28] = BREATH[rot++];
  13.   }
  14.  
  15.   if (countDown(&lastCheck, 300)) {
  16.     for (uint8_t led = 0; led < NUM_LEDS; ++led) {
  17.       if (led == 28) {
  18.  
  19.       } else if (random8() & random8() & 1) {
  20.         BRIGHTNESS_BUFFER[led] = random8() >> 3;
  21.       } else {
  22.         BRIGHTNESS_BUFFER[led] = 0;
  23.       }
  24.     }
  25.   }
  26.  
  27.   TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm;  // Clear the interrupt flag
  28. }
  29.  
  30. void loop() {
  31.  
  32.   resetLeds();
  33.   if (pwm_counter < BRIGHTNESS_BUFFER[current_led]) {
  34.     setLed(current_led);
  35.   }
  36.   delayMicroseconds(50);
  37.  
  38.   current_led++;
  39.   if (current_led >= NUM_LEDS) {
  40.     current_led = 0;
  41.   }
  42.   pwm_counter++;
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment