<< return to Pixycam.com

Code to turn on a LED

Hi! Thanks for your support. Working with Arduino I wanted to mix the pan-titl example code for Arduino with a circuit with a LED.
The easiest version is:
When an object is detected, then the LED is on for 2 seconds.
Is it possible?
I also wanted -later- to experiment with other variables, as the X and Y position coordenates of the object in an IF function.
For the first idea,
When I insert inside void setup:
pinMODE(13,OUTPUT);
And then,inside void loop:
digitalWrite (13,HIGH);
delay(1000);
digitalWrite (13,LOW);
delay (1000);
It has a lot of errors…
What could be the main problem? -Sorry I am new with Arduino too :)…

( I’ve found something similar on the internet time ago, I forgot abouy it!.. I will check it again.Anyway, maybe there is a simple way of doing this and I am missing it.Why I can’t mix the two codes ( Arduino Blink example + Arduino Pixy hello world? ) Thanks in advance…

Hi, I am sorry I am answering again to my own discussion. I have solved my problem, but now, I would like to know if this code is OK:
if(pixy.blocks[j].x==pixy.blocks[j+1].x)
{
digitalWrite(redled,HIGH);
delay(200);
digitalWrite(redled,LOW);
}
break

(I include “break” to finish the loop)
Thank you in advance,
María

Hello Maria,
How about something like this (based off of hello_world code: https://github.com/charmedlabs/pixy/blob/master/src/host/arduino/libraries/Pixy/examples/hello_world/hello_world.ino)

while(1)
{
  blocks = pixy.getBlocks();

  if (blocks) // if blocks != 0, which is the same as "pixy has detected something"
  {
    digitalWrite(redled,HIGH);
    delay(200);
    digitalWrite(redled,LOW);
  }
}

Hope this helps. :slight_smile:

Edward

Hi Edward,
Yes it helps, but not totally, because what I wanted to do is to do something if "pixy detected object ( no matter what object or signature ) x position coordenate is the same as the pixy next detected object x position coordenate ( no matter what object or signature ).
In other words, I would like to turn the led on if the x coordenates of the object remains the same for 1-2 seconds, that is why I wrote:

if(pixy.blocks[j].x==pixy.blocks[j+1].x) {

coordenate x of no matter what recognized object ( j ), and coordenate x of no matter what recognized object, the following second (j+1) ( that is why I wrote j and j+1, does it makes any sense this code for you?

thank you in advance!
María

Hello Maria,
Looks like you’re on the right track. :slight_smile:

Edward