Merry XMAS

I have a pro mini which drives 2 RGB LED strips on its 6 PWM pins, via 6 2N7000 N-channel MOSFETs. Alongside these, I have 4 x MAX7219 modules in series controlled via SPI. Both work perfectly, but not concurrently - yet. I need to do sleek PWM on the RGB strips whilst outputting scrolling text on the MAX7219s. The functions for the MAX7219 display take some time to complete for each blob of text.

I added a udelay() function (works like delay(), but just uses delayMicroseconds instead) so I could use interrupts/timers.

I am now interested in the best practice for doing that - I have no experience with interrupts, and would rather not use something lile FreeRTOS for this.

Desired functionality: 1) Drive 2 RGB LED strips on 6 PWM pins, smoothly. 2) While at the same time outputting arbitrary text/foo on the MAX7219s on SPI.

I have this snippet for smoother RGB fading ( http://forum.arduino.cc/index.php?topic=12004.0 ) and would also like to know what variables periode, displace denote, and if this method has merit.

void loop() {  time = millis();  value = 128+127*cos(2*PI/periode*time);  value2 = 128+127*cos(2*PI/periode*(displace-time));  analogWrite(ledpin, value);           // sets the value (range from 0 to 255)  analogWrite(ledpin2, value2);           // sets the value (range from 0 to 255) }

@Majenko et al?

Cluebats at the ready - any advice would be appreciated!

  • 1
    The functions for the MAX7219 display take some time to complete for each blob of text. - They shouldn't. How are you driving them? Have you thought about interleaving updating each row with updating your LED strips? What are you even considering any form of delay function?
    – Majenko
    Dec 20, 2016 at 12:17
  • @Majenko I am using the LedControl library - no I haven't thought about that, I don't know how to interleave updating each row, and even if I did, the text blobs have to be displayed for some time. I am interested in the equivalent of two threads (I'll use FreeRTOS if I must), can't that be done with interrupts? I'm sure there's plenty of delay()s in the printbuffer( textStr ) functions for the fading to take place. The udelay() function is explicitly for functions which run as interrupts - do forgive me my lack of insight here; if fork() was possible, this would be straightforward.
    – user400344
    Dec 20, 2016 at 20:42
  • 1
    I see that library uses shiftOut(). First step will be to ditch that and use proper hardware SPI.
    – Majenko
    Dec 20, 2016 at 20:46
  • 1
    I'd probably go the other way than Majenko suggest, and leave the max7219 code as is, but use a timer interrupt to update the PWM values.
    – Gerben
    Dec 20, 2016 at 21:18
  • 1
    @Gerben Alright - You validate my own idea. I will proceed accordingly. Post as answer and I will close this question.
    – user400344
    Dec 20, 2016 at 21:49


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.