Cant get servo and LED matrix to work together

Hello,
I have been trying to get my servo and an LED matrix to run using an IR remote. Ideally, by pressing a button, the servo should activate, the led matrix should display the message, and the servo should return to the start position. We seem to be able to get the servo OR the Led matrix to work separately, but not together. This is the code we have been using:

#include "IRremote.h"
#include <SPI.h>
#include <DMD.h>
#include <TimerOne.h>
#include "Arial_black_16.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include "Arial14.h"
#include "SystemFont5x7.h"
#include <Servo.h>

#define DISPLAYS_ACROSS 1 //-> Number of P10 panels used, side to side.
#define DISPLAYS_DOWN 1

int receiver = 2;
int servoPin = 9; // define the pin for the servo
Servo myservo;  // create servo object to control a servo

IRrecv irrecv(receiver);    // create instance of 'irrecv'
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);
decode_results results;

char Text = "";

void ScanDMD() { 
  dmd.scanDisplayBySPI();
}

void setup()
{ 
  irrecv.enableIRIn(); // Start the receiver
  Timer1.initialize(1000);
  Timer1.attachInterrupt(ScanDMD);
  dmd.clearScreen(true);
  Serial.begin(115200);
  myservo.attach(servoPin);  // attaches the servo on the defined pin to the servo object
}

void loop()
{
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
    switch(results.value)
    {
      case 0xFFA25D: // Power button pressed
        dmd.selectFont(Arial_Black_16_ISO_8859_1);
        Text = "Nuts";
        dmd.drawMarquee(Text,strlen(Text),(32DISPLAYS_ACROSS)-1,0);
        boolean ret=false;
        while(!ret){
          ret=dmd.stepMarquee(-1,0);
          delay(100);
        }
        myservo.write(90); // sets the servo position to 90 degrees
        delay(1000); // waits for 1 second
        myservo.write(0); // sets the servo position to 0 degrees
        delay(1000); // waits for 1 second
        break;
    }
    irrecv.resume(); // receive the next value
  }
}

Thanks for your help

How is the servo powered? How is the LED matrix powered?

You need a separate power supply for the servo and the matrix. Please post a wiring diagram.

The Servo and TimerOne libraries are both uses the Timer1 of AVR mcu and can't be used together.
The simplest way to resolve this is to use Timer2 for DMD led matrix scan interrupt.

Thanks for your response, we have tried both powering separately and together with the Arduino. Neither worked, I will try to get that wiring diagram on here shortly.

I think you should remove the "32" in the line above because it is not defined in your sketch, but you have the following line defined:

In the DMD.CPP implementation, the "drawMarquee" line say that "DISPLAYS_ACROSS" should be an INT:

void DMD::drawMarquee(const char *bChars, byte length, int left, int top)

I think it is a typo, it should be:

Makes sense. I was thinking "1" - 1 is not a big matrix. : )

It is not a matrix,

in the method above left and top are start coordinates for running text, so they can be both positive and negative, 0 is legal value also.

I know this because I once modified this library :slight_smile:

Very nice.

Sorry I butchered the analysis of the sketch issue ("remove 32").