Hello, I want to use the Pixy2 to recognize things and control the DC motor.
For example, if the Pixy2 recognizes red, it sends a signal to the motor and the motor moves by this signal.
I’m using Arduino Uno, a Pixy2, and AFMotor to make this.
However, there is no error in the code compile, but on Arduino’s serial monitor, the motor does not work even if there is object information recognized by the Pixy2.
How can I operate the motor?
This is the code that I used
#include <Pixy2.h>
#include <AFMotor.h>
AF_DCMotor motor_1(1);
Pixy2 pixy;
void setup() {
Serial.begin(115200);
Serial.print(“Starting…\n”);
pixy.init();
motor_1.setSpeed(2000);
}
void loop() {
int i;
// grab blocks!
pixy.ccc.getBlocks();
// If there are detect blocks, print them!
if (pixy.ccc.numBlocks)
{
Serial.print("Detected ");
Serial.println(pixy.ccc.numBlocks);
motor_1.run(FORWARD);
delay(1000);
for (i=0; i<pixy.ccc.numBlocks; i++)
{
Serial.print(" block ");
Serial.print(i);
Serial.print(": ");
pixy.ccc.blocks[i].print();
}
}
}