Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Robot with MLedMatrix panel, 4x servo's, Arduino Uno, and Adafruit 16bit PWM Driver
#include "Wire.h"
#include "MeOrion.h"
#include "Adafruit_PWMServoDriver.h"
#include "IRremote.h"
#include "MatrixGraphics.h"
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
MeLEDMatrix ledMx(PORT_1);
int IR_PIN = 8;
int b=random(300,10000);
#define FORWARD 150 // this is the 'minimum' pulse length count (out of 4096)
#define REVERSE 600 // this is the 'maximum' pulse length count (out of 4096)
#define STOP 2048
#define FR 0
#define FL 1
#define RR 2
#define RL 3
IRrecv irDetect(IR_PIN);
decode_results irIn;
char *s = "HI";
char *t = "OK";
void setup()
{
ledMx.setBrightness(2);
ledMx.setColorIndex(1);
ledMx.drawBitmap(0, 0, sizeof(Bitmap_Logo), Bitmap_Logo);
delay(3000);
ledMx.drawStr(2,7,s);
delay(1000);
ledMx.drawStr(1,7,t);
delay(1000);
ledMx.drawBitmap(0, 0, sizeof(Bitmap_EyesFR2), Bitmap_EyesFR2);
irDetect.enableIRIn();
pwm.begin();
pwm.setPWMFreq(60);
yield();
}
void loop()
{
if (irDetect.decode(&irIn)) {
decodeIR();
irDetect.resume();
}
}
void decodeIR() // Indicate what key is pressed
{
switch(irIn.value)
{
case 0xFF42BD:
ledMx.drawBitmap(0, 0, sizeof(Bitmap_Ir_Text), Bitmap_Ir_Text);
delay(20);
break;
case 0xFF52AD:
ledMx.drawBitmap(0, 0, sizeof(Bitmap_Auto_Text), Bitmap_Auto_Text);
delay(20);
break;
case 0xFF629D: //forward
ledMx.drawBitmap(0, 0, sizeof(Bitmap_EyesFR2), Bitmap_EyesFR2);
pwm.setPWM(FR, 0, FORWARD);
pwm.setPWM(FL, 0, REVERSE); // reverse on left is forward
pwm.setPWM(RR, 0, FORWARD);
pwm.setPWM(RL, 0, REVERSE);
break;
case 0xFF02FD: //stop (ok)
ledMx.drawBitmap(0, 0, sizeof(Bitmap_EyesFR2), Bitmap_EyesFR2);
pwm.setPWM(FR, 0, STOP);
pwm.setPWM(FL, 0, STOP);
pwm.setPWM(RR, 0, STOP);
pwm.setPWM(RL, 0, STOP);
break;
case 0xFFC23D: //right
ledMx.drawBitmap(0, 0, sizeof(Bitmap_EyesRight), Bitmap_EyesRight);
pwm.setPWM(FR, 0, FORWARD);
pwm.setPWM(FL, 0, FORWARD);
pwm.setPWM(RR, 0, FORWARD);
pwm.setPWM(RL, 0, FORWARD);
break;
case 0xFF22DD: // left
ledMx.drawBitmap(0, 0, sizeof(Bitmap_EyesLeft), Bitmap_EyesLeft);
pwm.setPWM(FR, 0, REVERSE);
pwm.setPWM(FL, 0, REVERSE); // forward is reverse on left
pwm.setPWM(RR, 0, REVERSE
);
pwm.setPWM(RL, 0, REVERSE);
break;
case 0xFFA857: // reverse
ledMx.drawBitmap(0, 0, sizeof(Bitmap_EyesUp), Bitmap_EyesUp);
pwm.setPWM(FR, 0, REVERSE);
pwm.setPWM(FL, 0, FORWARD); // forward is reverse on left
pwm.setPWM(RR, 0, REVERSE);
pwm.setPWM(RL, 0, FORWARD);
break;
default:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.