#include <Stepper.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
// --- Technical Specifications from Assignment 2 ---
const float V_REF = 5.0; // Reference Voltage
const long RESOLUTION = 65535; // 16-bit ADC Resolution (2^16 - 1)
const int FS = 150; // Sampling Rate 150Hz for Nyquist compliance [cite: 10, 36]
const float LYSIS_THRESHOLD = 1.0498; // Reconstituted Vcond from Binary Word [cite: 29]
// Hardware Setup
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo piezoStack;
const int buttonPin = 2;
const int stepPin = 9;
const int dirPin = 8;
unsigned long lastSampleTime = 0;
const unsigned long sampleInterval = 1000 / FS; // 6.66ms for 150Hz [cite: 110]
void setup() {
Serial.begin(115200);
lcd.init();
lcd.backlight();
piezoStack.attach(6);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
lcd.print("iCELLS OPTIMIZED");
delay(1000);
lcd.clear();
}
void loop() {
unsigned long currentTime = millis();
// 1. TEMPORAL SAMPLING VALIDATION (Nyquist Compliance [cite: 33])
if (currentTime - lastSampleTime >= sampleInterval) {
lastSampleTime = currentTime;
// 2. DATA ACQUISITION & RECONSTITUTION [cite: 20]
int rawValue = analogRead(A0);
// Simulating the 16-bit Binary Word: 0011010111000000 [cite: 23]
long binaryWord = map(rawValue, 0, 1023, 0, RESOLUTION);
float vCond = (float(binaryWord) / RESOLUTION) * V_REF; //
// 3. PRECISION INFUSION (NEMA 17 Control)
// Runs constantly to simulate nanometric media flow
digitalWrite(dirPin, HIGH);
digitalWrite(stepPin, HIGH);
delayMicroseconds(10); // Minimal pulse for smooth micro-stepping
digitalWrite(stepPin, LOW);
// 4. EXPERIMENT: MECHANICAL LYSIS STUDY
bool manualKill = (digitalRead(buttonPin) == LOW);
// Logic: Trigger if Vcond matches the assignment calculation (1.0498V) [cite: 29]
if (vCond >= LYSIS_THRESHOLD || manualKill) {
piezoStack.write(180); // Maximum displacement for membrane rupture
lcd.setCursor(0, 0);
lcd.print("!!! LYSIS !!! ");
lcd.setCursor(0, 1);
lcd.print("Vcond: "); lcd.print(vCond, 4); // Show 4 decimals for resolution [cite: 83]
Serial.print("CRITICAL DATA - Binary: 0011010111000000 | Vcond: ");
Serial.println(vCond, 4);
Serial.println("ALERT: Cell Membrane Rupture via Mechanical Resonance");
} else {
piezoStack.write(0); // Normal physiological mechanical cues
lcd.setCursor(0, 0);
lcd.print("STATUS: STABLE ");
lcd.setCursor(0, 1);
lcd.print("Vcond: "); lcd.print(vCond, 4);
}
}
}