Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit e306864

Browse files
authored
Minor formatting fixes
1 parent 6a937cc commit e306864

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

examples/Color_Perceptron/Color_Perceptron.ino

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
/*
22
3-
Perceptron example
3+
Color_Perceptron.ino
44
5-
Hardware: Arduino Nano BLE Sense
5+
Perceptron color classification example
66
7-
Usage: Follow the prompts in the Serial Monitor and show two objects of different colors to the color sensor onboard the Arduino.
8-
The sketch will train a perceptron using these examples, and then classify objects you show it in the future.
7+
Hardware: Arduino Nano 33 BLE Sense
8+
9+
Usage: Follow the prompts in the Serial Monitor and show two objects of different colors to the color sensor onboard the Arduino.
10+
The sketch will train a perceptron using these examples, and then classify objects you show it in the future.
911
1012
*/
1113

1214
#include <Arduino_APDS9960.h>
1315
#include <Arduino_Perceptron.h>
1416

15-
const int NUM_INPUTS = 3; // Classifier input is color sensor data; red, green and blue levels
16-
const int CLASSES = 2; // The perceptron only has 2 possible classes (-1 and 1)
17-
const int EXAMPLES = 50; // Number of samples for each object
18-
const int MAX_EPOCHS = 250; // Maximum training iterations
19-
const float LEARNING_RATE = 0.001; // Perceptron learning rate
20-
const int THRESHOLD = 5; // Color sensor light threshold
17+
const int NUM_INPUTS = 3; // Classifier has 3 inputs - red, green and blue levels
18+
const int CLASSES = 2; // The perceptron only has 2 possible classes (-1 and 1)
19+
const int EXAMPLES = 50; // Number of samples for each object
20+
const int MAX_EPOCHS = 250; // Maximum training iterations
21+
const float LEARNING_RATE = 0.001; // Perceptron learning rate
22+
const int THRESHOLD = 5; // Color sensor light threshold
2123

2224
float color[NUM_INPUTS];
2325
String label[CLASSES] = {"object A", "object B"};
@@ -35,8 +37,8 @@ void setup() {
3537

3638
Serial.println("Arduino perceptron");
3739

38-
// Get examples for the two possible outputs, -1 and 1
39-
// ---------------------------------------------------
40+
// Get color examples for the two objects
41+
// --------------------------------------
4042
for (int output = -1; output < 2; output += 2) {
4143

4244
Serial.print("Show me ");
@@ -61,6 +63,7 @@ void setup() {
6163
int epoch = 0;
6264
float accuracy = 0;
6365

66+
// Iterate until the perceptron is 99% accurate or we hit max epochs
6467
while (epoch < MAX_EPOCHS && accuracy < 0.99) {
6568
accuracy = perceptron.train();
6669
epoch++;
@@ -74,24 +77,23 @@ void setup() {
7477

7578

7679
void loop() {
77-
7880
int output;
7981

8082
// Wait for the object to move away again
8183
while (!APDS.proximityAvailable() || APDS.readProximity() == 0) {}
82-
8384
Serial.println("Let me guess your object");
8485

8586
// Wait for an object then read its color
8687
readColor(color);
87-
8888
output = perceptron.classify(color);
8989

9090
Serial.print("You showed me ");
9191
printLabel(output);
9292
}
9393

94+
9495
void printLabel(int output) {
96+
// Perceptron output can only be -1 or 1
9597
if (output == -1) {
9698
Serial.println(label[0]);
9799
} else {

0 commit comments

Comments
 (0)