hi all, am working on a final year project. this project involve an Arduino uno + wifi, pixy camera. the aim is to detect colored object eg a red. when the object i want the Arduino to send out put to the serial monitor and to also send the out put to the webpage of the Arduino.
#include <Wire.h>
#include <UnoWiFiDevEd.h>
#include <SPI.h>
#include <Pixy.h>
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
Pixy pixy;
void setup() {
Serial.begin(9600);
Serial.print("Starting...\n");
Wifi.begin();
Wifi.println("Web Server is up");
pixy.init();
}
void loop() {
while(Wifi.available()){
process(Wifi);
}
}
void process(WifiData client) {
// read the command
String command = client.readStringUntil('/');
// is "digital" command?
if (command == "webserver") {
WebServer(client);
}
}
void WebServer(WifiData client) {
// grab blocks!
blocks = pixy.getBlocks();
// If there are detect blocks, print them!
if (blocks)
{
i++;
// do this (print) every 50 frames because printing every
// frame would bog down the Arduino
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();
}
}
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("");
client.println(" ");
client.print("");
client.print(buf);
client.print("");
client.println("");
client.print(DELIMITER); // very important to end the communication !!!
}