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