mirror of
https://github.com/soconnor0919/control-system-re25.git
synced 2026-02-04 15:56:33 -05:00
Initial commit
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
17
platformio.ini
Normal file
17
platformio.ini
Normal file
@@ -0,0 +1,17 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:uno_r4_minima]
|
||||
platform = renesas-ra
|
||||
board = uno_r4_minima
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
adafruit/Adafruit AS7341@^1.4.1
|
||||
adafruit/Adafruit BusIO@^1.16.2
|
||||
87
src/main.cpp
Normal file
87
src/main.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_AS7341.h>
|
||||
#include <Wire.h>
|
||||
|
||||
Adafruit_AS7341 as7341;
|
||||
|
||||
int measurement = -1;
|
||||
int baselineValue = 0;
|
||||
bool reactionComplete = false;
|
||||
unsigned long startTime = 0;
|
||||
const int triggerPin = 2;
|
||||
const int SIGNIFICANT_DECREASE = 5000;
|
||||
bool triggerArmed = false; // Add this to wait for pin to stabilize
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) delay(10);
|
||||
|
||||
Wire.begin();
|
||||
delay(100);
|
||||
|
||||
Serial.println("Looking for AS7341 sensor...");
|
||||
if (!as7341.begin()) {
|
||||
Serial.println("Could not find AS7341 sensor. Check wiring!");
|
||||
while (1) delay(10);
|
||||
}
|
||||
|
||||
Serial.println("AS7341 sensor initialized!");
|
||||
|
||||
// Configure sensor
|
||||
as7341.setATIME(100);
|
||||
as7341.setASTEP(999);
|
||||
as7341.setGain(AS7341_GAIN_256X);
|
||||
as7341.enableLED(false);
|
||||
|
||||
pinMode(triggerPin, INPUT_PULLUP);
|
||||
|
||||
// Wait for trigger pin to stabilize to HIGH
|
||||
delay(100);
|
||||
if (digitalRead(triggerPin) == HIGH) {
|
||||
triggerArmed = true;
|
||||
// Serial.println("Trigger armed and ready!");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(50);
|
||||
|
||||
if (!as7341.readAllChannels()) {
|
||||
Serial.println("Error reading channels");
|
||||
return;
|
||||
}
|
||||
|
||||
measurement = as7341.getChannel(AS7341_CHANNEL_630nm_F7);
|
||||
|
||||
// Print trigger state periodically
|
||||
static unsigned long lastTriggerDebug = 0;
|
||||
if (millis() - lastTriggerDebug > 500) {
|
||||
// Serial.print("Trigger pin state: ");
|
||||
// Serial.println(digitalRead(triggerPin));
|
||||
lastTriggerDebug = millis();
|
||||
}
|
||||
|
||||
// Start timer when trigger is pulled (goes from HIGH to LOW) and take baseline
|
||||
if (triggerArmed && !reactionComplete && digitalRead(triggerPin) == LOW && startTime == 0) {
|
||||
baselineValue = measurement;
|
||||
startTime = millis();
|
||||
Serial.println("Reaction started!");
|
||||
Serial.print("Baseline value: ");
|
||||
Serial.println(baselineValue);
|
||||
}
|
||||
|
||||
// Check for completion if reaction has started
|
||||
if (!reactionComplete && startTime > 0) {
|
||||
if (baselineValue - measurement >= SIGNIFICANT_DECREASE) {
|
||||
reactionComplete = true;
|
||||
float duration = (millis() - startTime) / 1000.0;
|
||||
Serial.print("Reaction complete! Duration: ");
|
||||
Serial.print(duration);
|
||||
Serial.println(" seconds");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print('>');
|
||||
Serial.print("630nm:");
|
||||
Serial.println(measurement);
|
||||
}
|
||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||
Reference in New Issue
Block a user