I am controlling 4 motors using the PWM ports on an Arduino Uno (3,9,10,11). For some reason, the motor hooked up to port 11 doesn't move with my current code. I know it's a code issue because I can create a new basic code that just moves the motor and it works fine, but for some reason it doesn't in this code.
#include <SPI.h>
#include <Pixy.h>
Pixy pixy;
int personX = 0;
int offCount = 0;
void setup()
{
pinMode(3, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
while (! Serial);
pixy.init();
}
void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
blocks = pixy.getBlocks();
if (blocks)
{
personX = pixy.blocks[0].x;
}
if (blocks){
Serial.println(personX);
if (personX < 110){
analogWrite(11, 130);
analogWrite(3, 130);
analogWrite(9, 250);
analogWrite(10, 250);
} else if (personX > 190){
analogWrite(11, 250);
analogWrite(3, 250);
analogWrite(9, 130);
analogWrite(10, 130);
} else {
analogWrite(11, 190);
analogWrite(3, 190);
analogWrite(9, 190);
analogWrite(10, 190);
}
offCount = 0;
} else {
if (offCount < 1000){
offCount = offCount + 1;
} else {
analogWrite(11, 190);
analogWrite(3, 190);
analogWrite(9, 190);
analogWrite(10, 190);
}
}
}
Also, when I take the motor and swap it with another, the old one works in the new PWM port, but the new one stops working once I put it in port 11.