I’m having trouble figuring out what the command would be to single out a return on different signatures through my Arduino UNO. Basically what I want is
if signature1 detected then pinMode (13, HIGH);
if signature2 detected then pinMode (12, HIGH);
and so on if needed. //,but I don’t know exactly how to do that.
#include <SPI.h>
#include <Pixy.h>
Pixy pixy;
void setup() {
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
pixy.init();
}
void loop() {
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
if (pixy.blocks[i].signature== 1)
{
digitalWrite(13, HIGH);
delay(1000);
}}
Update I’ve got a “working code” right now I plan to test it tomorrow.
Hello Drew,
It looks like you’re on the right track
#include <SPI.h>
#include <Pixy.h>
// This is the main Pixy object
Pixy pixy;
void setup()
{
pinMode (13, OUTPUT);
Serial.begin(9600);
Serial.print(“Starting…\n”);
pixy.init();
}
void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
digitalWrite (13, LOW);
// grab blocks!
blocks = pixy.getBlocks();
// If there are detect blocks, print them!
if (blocks)
{
if (i%50==0)
{
for (j=0; j<blocks; j++)
{ if (pixy.blocks[j].signature==1)
digitalWrite (13, HIGH);
delay (100);
digitalWrite (13, LOW);
delay (100);
}
}
}
}
This kind of works. when it sees any signature it triggers. I would like for it to just be signature 1 for this and probably repeat for a signature 2
// Edit
Also it actually turns off when it sees a signature so not quite sure what I did.
pixy.init();
interrupts the digitalWrite command for the code I narrowed it down by writing
//
#include <SPI.h>
#include <Pixy.h>
// This is the main Pixy object
Pixy pixy;
void setup()
{
pixy.init();
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
}
void loop()
{
static int i = 0;
int j;
char buf[32];
digitalWrite (13, HIGH);
digitalWrite (12, HIGH);
}
vs
//
#include <SPI.h>
#include <Pixy.h>
// This is the main Pixy object
Pixy pixy;
void setup()
{
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
}
void loop()
{
static int i = 0;
int j;
char buf[32];
digitalWrite (13, HIGH);
digitalWrite (12, HIGH);
}
and in the bottom code both LED light up
The problem involved pin 12 & 13 being tied to something else in the Arduino. Causing the LEDs to trigger “irregularly” not as I intended. I realized some of my earlier code was poorly written due to my own ineptitude during the early process of this project. I re-learned how to program in Arduino and made an early model for my main project.
#include <SPI.h>
#include <Pixy.h>
// This is the main Pixy object
Pixy pixy;
void setup()
{
pixy.init();
pinMode (7, OUTPUT);
pinMode (4, OUTPUT);
}
void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
digitalWrite (7, HIGH);
digitalWrite (4, HIGH);
// get blocks
blocks = pixy.getBlocks();
// If there are detect blocks, print them!
if (blocks)
{
if (i%50==0)
{
for (j=0; j<blocks; j++)
{ if (pixy.blocks[j].signature==1)
{
digitalWrite (7, LOW);
delay (100);
}
if (pixy.blocks[j].signature==2)
{
digitalWrite (4, LOW);
delay (100);
}
}}}}
Hi Drew,
It sounds like you got it figured out
One note –
The line “if (i%50==0)” is to reduce the amount of prints. In other words, it only prints once every 50 iterations. You might find that you get better performance if you remove that condition.
Thanks for sharing.
Edward