My code will be used to measure the pulse of the user. If their pulse is below a certain threshold, the user will be shocked by a dog collar until they get their heart rate back up. Currently the code just repeatedly turns pin 9 on and off and does not stop.
Also thanks for the tips!
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;
// The SetUp Function:
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);
}