classifier
object
Holds the ml5.js image classifier instance loaded from Teachable Machine—used to classify each video frame
let classifier; // set in preload() by ml5.imageClassifier()
video
object
Stores the webcam video stream from createCapture(VIDEO)—passed to the classifier for frame-by-frame analysis
let video; // initialized in setup()
modelURL
string
The URL to your Teachable Machine model—change this to point to your own trained model
let modelURL = 'https://api.gen-ai.fi/model/NdjaeKeF/';
currentClassification
object
Stores the latest classification result with 'label' (class name) and 'confidence' (0 to 1) properties
let currentClassification = { label: 'Loading model...', confidence: 0 };
port
object
Holds the Web Serial port connection to the microcontroller—undefined when disconnected
let port; // set by connectSerial()
reader
object
Reads incoming text data from the serial port stream
let reader; // created in connectSerial()
writer
object
Writes outgoing text data to the serial port stream
let writer; // created in connectSerial()
serialConnectButton
object
The p5.js button element that toggles serial connection on and off
let serialConnectButton; // created in setup()
serialStatusP
object
The p5.js paragraph element displaying serial connection status
let serialStatusP; // created in setup()
receivedSerialDataP
object
The p5.js paragraph element displaying the last message received from the microcontroller
let receivedSerialDataP; // created in setup()
classificationSendInterval
number
Milliseconds to wait between sending the same classification label to serial—prevents flooding the microcontroller
let classificationSendInterval = 3000; // send every 3 seconds
lastClassificationSendTime
number
Timestamp of the last time a label was sent to serial—used to enforce the send interval
let lastClassificationSendTime = 0;
lastSentLabel
string
Stores the label sent most recently to avoid sending the same label repeatedly
let lastSentLabel = '';
debugChannel
object
The BroadcastChannel instance for sending predictions to other browser tabs
let debugChannel; // created in setup() if supported
debugSendCheckbox
object
The p5.js checkbox element that toggles whether to broadcast debug data to other tabs
let debugSendCheckbox; // created in setup()
receivedBroadcastDataP
object
The p5.js paragraph element displaying predictions received from other tabs via BroadcastChannel
let receivedBroadcastDataP; // created in setup()
videoMargin
number
Pixel spacing around the video preview and UI elements for consistent layout
let videoMargin = 20;