#include "Seeed_Arduino_GroveAI.h"
#include <Wire.h>
#include"TFT_eSPI.h"
#include"Seeed_FS.h"
#include"RawImage.h"
#include <Adafruit_NeoPixel.h>
TFT_eSPI tft;
Adafruit_NeoPixel pixels_1 = Adafruit_NeoPixel(250, 1, NEO_GRB + NEO_KHZ800);
GroveAI ai(Wire);
uint8_t state = 0;
void setup()
{
tft.begin();
if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)) {
while (1);
}
tft.setRotation(3);
pixels_1.setBrightness(255);
pixels_1.begin();
pixels_1.setPixelColor(0, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(1, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(2, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(3, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(4, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(5, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(6, pixels_1.Color(20, 20, 20));
pixels_1.setPixelColor(7, pixels_1.Color(20, 20, 20));
pixels_1.show();
Wire.begin();
Serial.begin(115200);
Serial.println("begin");
if (ai.begin(ALGO_OBJECT_DETECTION, MODEL_EXT_INDEX_1)) // Object detection and pre-trained model 1
{
Serial.print("Version: ");
Serial.println(ai.version());
Serial.print("ID: ");
Serial.println( ai.id());
Serial.print("Algo: ");
Serial.println( ai.algo());
Serial.print("Model: ");
Serial.println(ai.model());
Serial.print("Confidence: ");
Serial.println(ai.confidence());
state = 1;
}
else
{
Serial.println("Algo begin failed.");
}
}
void loop()
{
if (state == 1)
{
uint32_t tick = millis();
if (ai.invoke()) // begin invoke
{
while (1) // wait for invoking finished
{
CMD_STATE_T ret = ai.state();
if (ret == CMD_STATE_IDLE)
{
break;
}
delay(20);
}
uint8_t len = ai.get_result_len(); // receive how many people detect
if(len)
{
int time1 = millis() - tick;
Serial.print("Time consuming: ");
Serial.println(time1);
Serial.print("Number of people: ");
Serial.println(len);
object_detection_t data; //get data
for (int i = 0; i < len; i++)
{
Serial.println("result:detected");
Serial.print("Detecting and calculating: ");
Serial.println(i+1);
ai.get_result(i, (uint8_t*)&data, sizeof(object_detection_t)); //get result
Serial.print("confidence:");
Serial.print(data.confidence);
Serial.println();
pixels_1.setBrightness(255);
pixels_1.begin();
pixels_1.setPixelColor(0, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(1, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(2, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(3, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(4, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(5, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(6, pixels_1.Color(200, 200, 200));
pixels_1.setPixelColor(7, pixels_1.Color(200, 200, 200));
pixels_1.show();
drawImage<uint8_t>("1.bmp", 0,0);
tone(WIO_BUZZER,262);
delay(250);
noTone(WIO_BUZZER);
tone(WIO_BUZZER,330);
delay(250);
noTone(WIO_BUZZER);
tone(WIO_BUZZER,392);
delay(250);
noTone(WIO_BUZZER);
delay(1000);
}
}
else
{
Serial.println("No identification");
pixels_1.setPixelColor(0, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(1, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(2, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(3, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(4, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(5, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(6, pixels_1.Color(1, 10, 20));
pixels_1.setPixelColor(7, pixels_1.Color(1, 10, 20));
pixels_1.show();
drawImage<uint8_t>("2.bmp", 0,0);
delay(1000);
}
}
else
{
delay(1000);
Serial.println("Invoke Failed.");
}
}
else
{
state == 0;
}
}
Comments