Friends:
My question is this: I am interested in setting pins HIGH with Arduino if “sees” an object centered at various locations.I have been experimenting with code such as the rough sample below… but the delay function seems not the way to go in order to operate the pins momentarily. It affects camera operation. Suggestions for improvement?
Friends: Can I please have some input on the following beginning sketch? Ultimately, I have 30 pins (Arduino Mega) that each need to be set HIGH momentarily when an object center is in one of 30 distinct locations in the camera's field of view. I am developing the sketch on an Uno. However, there are some errors in that the LED onset is not restricted to the X values indicated and I am not sure if I have used the "centerX", "centerY" names correctly. Suggestions? #include #include Pixy pixy;// This is the main Pixy object unsigned long tempo; int centerX; // the name to be used for X value of object center int centerY; // the name to be used for X value of object center int Pin2 = 2; int Pin3 = 3; int Pin4 = 4; int Pin5 = 5; void setup() { Serial.begin(9600); Serial.print("Starting...\n"); pixy.init(); pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); } void loop() { static int i = 0; int j; uint16_t blocks; char buf[32]; // grab blocks! blocks = pixy.getBlocks(); centerX = pixy.blocks[i].x; // I am not sure if these are correct or in right place centerY = pixy.blocks[i].y; if (centerX >100 && centerX < 200) // when the object center is between these values on the X axis { if (millis() - tempo <= 1000) // when the object center is between these values on the X axis digitalWrite(Pin4, HIGH); // LED on for 1000 ms } else { tempo = millis(); } digitalWrite(Pin4, LOW); // If there are detect blocks if (blocks) { i++; if (i % 50 == 0) { sprintf(buf, "Detected %d:\n", blocks); Serial.print(buf); for (j = 0; j < blocks; j++) { sprintf(buf, " block %d: ", j); Serial.print(buf); pixy.blocks[j].print(); } } } } // end of if (blocks)