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 a3b3f8e

Browse files
+ MicromlColorIdentificationExample
1 parent f7416ad commit a3b3f8e

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

‎.idea/workspace.xml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// uncomment when you have a model.h
2+
// to tun the classification
3+
//#define CLASSIFY
4+
5+
#define S2 2
6+
#define S3 3
7+
#define sensorOut 4
8+
9+
double features[3];
10+
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+
20+
void setup() {
21+
Serial.begin(115200);
22+
pinMode(S2, OUTPUT);
23+
pinMode(S3, OUTPUT);
24+
pinMode(sensorOut, INPUT);
25+
}
26+
27+
void loop() {
28+
readRGB();
29+
printFeatures();
30+
#if defined(CLASSIFY)
31+
classify();
32+
#endif
33+
delay(100);
34+
}
35+
36+
int readComponent(bool s2, bool s3) {
37+
delay(10);
38+
digitalWrite(S2, s2);
39+
digitalWrite(S3, s3);
40+
41+
return pulseIn(sensorOut, LOW);
42+
}
43+
44+
void readRGB() {
45+
features[0] = readComponent(LOW, LOW);
46+
features[1] = readComponent(HIGH, HIGH);
47+
features[2] = readComponent(LOW, HIGH);
48+
}
49+
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+
}
57+
}

0 commit comments

Comments
(0)

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