defragster
Senior Member+
opps << This ended up on wrong thread ... https://forum.pjrc.com/threads/57441-Tensorflow-on-Teensy
BTW .. the YES/NO recognition takes 2.6 seconds on T4 ...
Seemed half done to have YES set LED high and then no indication of NO, so modified:
BTW .. the YES/NO recognition takes 2.6 seconds on T4 ...
Seemed half done to have YES set LED high and then no indication of NO, so modified:
Code:
void RespondToCommand(tflite::ErrorReporter* error_reporter,
int32_t current_time, const char* found_command,
uint8_t score, bool is_new_command) {
static bool is_initialized = false;
if (!is_initialized) {
pinMode(LED_PIN, OUTPUT);
is_initialized = true;
}
static int32_t last_yes_time = 0;
static int32_t last_no_time = 0;
static int count = 0;
if (is_new_command) {
error_reporter->Report("Heard %s (%d) @%dms [ms lag=%d]", found_command, score,
current_time, millis()-current_time);
// If we heard a "yes", switch on an LED and store the time.
if (found_command[0] == 'y') {
last_yes_time = current_time;
digitalWrite(LED_PIN, HIGH);
}
if (found_command[0] == 'n') {
last_no_time = current_time;
digitalWrite(LED_PIN, LOW);
}
}
// If last_yes_time is non-zero but was >3 seconds ago, zero it
// and switch off the LED.
if (last_yes_time != 0) {
if (last_yes_time < (current_time - 3000)) {
last_yes_time = 0;
digitalWrite(LED_PIN, LOW);
}
// If it is non-zero but <3 seconds ago, do nothing.
return;
}
if (last_no_time != 0) {
if (last_no_time < (current_time - 3000)) {
last_no_time = 0;
digitalWrite(LED_PIN, HIGH);
}
// If it is non-zero but <3 seconds ago, do nothing.
return;
}
// Otherwise, toggle the LED every time an inference is performed.
++count;
if (count & 1) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
Last edited: