Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit eb02981

Browse files
Wake word classification example
1 parent 28f2454 commit eb02981

File tree

4 files changed

+74
-24
lines changed

4 files changed

+74
-24
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// On Attiny we can only do classification
2+
// since there's no Serial
3+
// We'll light a led based on the detected color
4+
5+
#include "model.h"
6+
7+
#define S2 2
8+
#define S3 3
9+
#define sensorOut 4
10+
#define LED 0
11+
12+
double features[3];
13+
14+
15+
void setup() {
16+
pinMode(S2, OUTPUT);
17+
pinMode(S3, OUTPUT);
18+
pinMode(sensorOut, INPUT);
19+
}
20+
21+
void loop() {
22+
readRGB();
23+
classify();
24+
delay(100);
25+
}
26+
27+
int readComponent(bool s2, bool s3) {
28+
delay(10);
29+
digitalWrite(S2, s2);
30+
digitalWrite(S3, s3);
31+
32+
return pulseIn(sensorOut, LOW);
33+
}
34+
35+
void readRGB() {
36+
features[0] = readComponent(LOW, LOW);
37+
features[1] = readComponent(HIGH, HIGH);
38+
features[2] = readComponent(LOW, HIGH);
39+
}
40+
41+
void classify() {
42+
for (uint8_t times = predict(features) + 1; times > 0; times--) {
43+
digitalWrite(LED, HIGH);
44+
delay(10);
45+
digitalWrite(LED, LOW);
46+
delay(10);
47+
}
48+
}
Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
1-
// uncomment when you have a model.h
2-
// to tun the classification
3-
// #define CLASSIFY
1+
// On the Attiny we can only do classification
2+
// since there's no serial
43

4+
#include "model_attiny.h"
5+
6+
7+
#define LED 0
58
#define S2 2
69
#define S3 3
710
#define sensorOut 4
811

912
double features[3];
1013

11-
#if defined(CLASSIFY)
12-
#include "model.h"
13-
14-
void classify() {
15-
Serial.print("Detected color: ");
16-
Serial.println(classIdxToName(predict(features)));
17-
}
18-
#endif
19-
2014
void setup() {
21-
Serial.begin(115200);
2215
pinMode(S2, OUTPUT);
2316
pinMode(S3, OUTPUT);
2417
pinMode(sensorOut, INPUT);
18+
pinMode(LED, OUTPUT);
2519
}
2620

2721
void loop() {
2822
readRGB();
29-
printFeatures();
30-
#if defined(CLASSIFY)
31-
classify();
32-
#endif
23+
classify();
3324
delay(100);
3425
}
3526

@@ -47,11 +38,6 @@ void readRGB() {
4738
features[2] = readComponent(LOW, HIGH);
4839
}
4940

50-
void printFeatures() {
51-
const uint16_t numFeatures = sizeof(features) / sizeof(double);
52-
53-
for (int i = 0; i < numFeatures; i++) {
54-
Serial.print(features[i]);
55-
Serial.print(i == numFeatures - 1 ? '\n' : ',');
56-
}
41+
void classify() {
42+
analogWrite(LED, classIdxToName(predict(features)));
5743
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by simone on 21/12/19.
3+
//
4+
5+
#ifndef ELOQUENTARDUINO_IRIS_ATTINY_H
6+
#define ELOQUENTARDUINO_IRIS_ATTINY_H
7+
8+
#endif //ELOQUENTARDUINO_IRIS_ATTINY_H
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// Created by simone on 21/12/19.
3+
//
4+
5+
#ifndef ELOQUENTARDUINO_MICROMLWAKEWORDIDENTIFICATIONEXAMPLE_INO
6+
#define ELOQUENTARDUINO_MICROMLWAKEWORDIDENTIFICATIONEXAMPLE_INO
7+
8+
#endif //ELOQUENTARDUINO_MICROMLWAKEWORDIDENTIFICATIONEXAMPLE_INO

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /