I’m currently trying to figure out how to use millis to measure the time between each blink of an LED (the blink being caused by a pulse sensor plugged into an analog input) and take this information to trigger a digital pin if the interval between blinks is greater than 500.
Here’s my current code:
int PulseSensorPurplePin = 0;
int ledPin = 13;
int SHOCK = 9;
int Signal;
int Threshold = 550;
unsigned long previousMillis = 0;
unsigned long startMillis;
const unsigned long interval = 500;
void setup() {
pinMode(SHOCK,OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
Signal = analogRead(PulseSensorPurplePin);
unsigned long currentMillis = millis();
Serial.println(Signal);
if(Signal > Threshold){
digitalWrite(ledPin,HIGH);
} else {
digitalWrite(ledPin,LOW);
}
if(currentMillis - previousMillis > interval){
digitalWrite(SHOCK,HIGH);
} else {
digitalWrite(SHOCK,LOW);
}
delay(10);
}