Hello, I hope everyone is doing well. I have a problem with my code and was hoping someone could help me out. If you could that'd be wonderful.
Here is my code:
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
void loop() {
const int trigPin = 9;
const int echoPin = 10;
float duration, distance;
}
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.print("Distance: ");
Serial.println(distance);
delay(100);
}
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
int ledPin = 3; // LED is plugged in at pin 3
int motionSensorValue;
int ypinacc = 0;
int low = 275; // the severity will be considered low when the motion detected is 2
int mild = 325; // the severity will be considered low when the motion detected is 4
int severe = 375; // the severity will be considered low when the motion detected is 8
int ledState = LOW;
long intervalLow = 1000;
long intervalMild = 5000;
long intervalSevere = 9000;
void setup()
pinMode (ypin, INPUT); // initialized motion sensor as input
pinMode (ledPin, OUTPUT); // initialized digital pin as output
Serial.begin(9600);
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop() {
ypinacc = analogRead(ypin);
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
//digitalWrite(ledPin, HIGH);
if (ypinacc < low) { //no seizure
digitalWrite(ledPin, LOW);
// the LED will remain off if no abnormal motion is detected
} else if (ypinacc >= low && ypinacc < mild) { //low
intervalLow = millis();
digitalWrite(ledPin, intervalLow);
/* If the value of the sensor is greater than low but less than mild, the LED will
* light up at a brightness of 1000 and stay on for 4 seconds.
*/
} else if (ypinacc >= mild && ypinacc < severe) { //mild
intervalMild = millis();
digitalWrite(ledPin, intervalMild);
/* If the value of the sensor is greater than mild but less than severe, the LED
* will light up at a brightness of 3000 and stay on for 7 seconds.
*/
} else if (ypinacc >= severe) { //severe
intervalSevere = millis();
digitalWrite(ledPin, intervalSevere);
/* If the sensor value is greater than the severe value, the LED will light
* up at a brightness of 3000 and stay on for 10 seconds.
*/
}