SMART LIGHT LAB — SUPPORT FILES

Student workspace
-----------------
SmartLightLab/
    StartLab.m       Connection helper. Do not edit or submit.
    SmartLight.m     Your own lab script. Edit and submit this.
    support/         Connection and simulation files. Do not edit or submit.

Get started
-----------
1. Unzip SmartLightLab.zip and open the SmartLightLab folder in MATLAB.
2. Browser-to-MATLAB pairing is temporarily unavailable. Contact your instructor
   to request access.
3. Run StartLab('local') in MATLAB's Command Window to open the offline board.
4. Write and run your own code in SmartLight.m, following the lab procedure.

No installer, savepath, hardware support package, or physical Arduino is needed.
StartLab sets up the support folder for the current MATLAB session only.
After restarting MATLAB, return to this folder and run StartLab('local').
Keep SmartLightLab together; do not move SmartLight.m away while working.
If you already wrote a script, copy your existing work into SmartLight.m instead
of overwriting it with this blank template. Keep an existing copy as a backup.
If upgrading from an older connector, extract to a new folder and move only your
own work into it. Do not copy old smartlight.m, arduino.m or +vsl files into it.

Connection and coding
---------------------
Your code can use a = arduino('COM4','Mega2560'), readVoltage and writeDigitalPin.
The COM port is simulated. Initialize a in your script as the lab requests;
StartLab does not create a workspace variable. Normal clear/clc commands are OK.
Use Ctrl+C to stop the loop. Clear your arduino object before creating another.
Run StartLab('disconnect') when finished.
StartLab('local') opens the original offline board if that is needed.

Deliverables
------------
Save your MATLAB script as SmartLight.m. Use Save circuit image on the website
and place SmartLight_Circuit.png beside it in this folder. If your instructor
requires a PDF of the code, export SmartLight.m as SmartLight.pdf using MATLAB.
Submit the files your instructor requests, not StartLab.m or the support folder.
Save circuit file creates SmartLight_Circuit.json, an optional editable backup;
it is not a substitute for the circuit image.

Compatibility
-------------
MATLAB R2021b or newer is recommended; tested with R2026b.
Public browser-to-MATLAB pairing is temporarily unavailable. Contact your
instructor to request access. StartLab('local') runs the offline board on this
computer; it does not use the public relay. Scripts and files remain local.

Light and saved circuits
------------------------
Move Hand over sensor gradually from uncovered to fully covered. Each new
circuit receives random room light (150–600 lux); a fully covering hand lets
1% through. Measure your own uncovered and covered readings and choose your
threshold between them. Example readings are not universal constants.
Room light is saved with the circuit and restored on reopening. Older circuit
files default to 300 lux. Clear board starts a new circuit with new room light.
The board now provides A0–A15; D2–D13 remain the connectable digital pins.
The browser and StartLab('local') use the same circuit and lighting behavior.
Old versions of the website cannot preserve A8–A15 connections or room light
when resaving new circuit files. Keep the original JSON when sharing backwards.
