code not working

I am during a project for my class and my code is not working properly. this is the beginning phase of project , i am currently loop with an led. the secaond loop is not working for some reason. why? by the way the project is suppose to warn a driver if a child is left in the car i am using an fsr sensor to detect the "child".

// constants won't change. They're used here to // set pin numbers: const int buttonPin = 7; // the number of the pushbutton pin const int ledPin_13 = 13; // the number of the LED pin const int LED_8 = 8; const int LED_12 = 12;

// Variables will change: int ledState = HIGH; // the current state of the output pin int buttonState; // the current reading from the input pin int lastButtonState = LOW; // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long lastDebounceTime = 0; // the last time the output pin was toggled long debounceDelay = 50; // the debounce time; increase if the output flickers

///////////////////////////////////////////////////// // the following variable are for the FSR sensor int FSR_sensor_0 = A0; int FSR_sensor_1 = A1; int FSR_sensor_2 = A2; int FSR_sensor_3 = A3; ////////////////////////////////////////////////////

void setup() { pinMode(buttonPin, INPUT); pinMode(ledPin_13, OUTPUT); pinMode (LED_8, OUTPUT); pinMode (LED_12, OUTPUT);

// set initial LED state digitalWrite(ledPin_13, ledState);

pinMode (FSR_sensor_0, INPUT); pinMode (FSR_sensor_1, INPUT); pinMode (FSR_sensor_2, INPUT); pinMode (FSR_sensor_3, INPUT); }

void loop() { // read the state of the switch into a local variable: int reading = digitalRead(buttonPin);

int FsrVal_0 = analogRead (FSR_sensor_0); int FsrVal_1 = analogRead (FSR_sensor_1); int FsrVal_2 = analogRead (FSR_sensor_2); int FsrVal_3 = analogRead (FSR_sensor_3);

// check to see if you just pressed the button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise:

// If the switch changed, due to noise or pressing: if (reading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); }

if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state:

// if the button state has changed: if (reading != buttonState) { buttonState = reading;

// only toggle the LED if the new button state is HIGH if (buttonState == HIGH) { ledState = !ledState; } } }

// set the LED: digitalWrite(ledPin_13, ledState);

// save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState = reading;

if ((ledState == LOW ) && (FsrVal_0 == 0))

{

if ( (FsrVal_2 > 10 && FsrVal_1== 0 && FsrVal_3 == 0 )|| ( FsrVal_3 > 10 && FsrVal_2 == 0 && FsrVal_1==0 ))

digitalWrite (LED_12, HIGH);

else

digitalWrite (LED_12, HIGH);

}

//digitalWrite (LED_8, HIGH);

else

digitalWrite (LED_8, LOW);

}

hard to read... please check your source formatting, and

//  use code tags!

thanks

Use Ctrl-T in the source code window of the IDE to format your code in a more readable format. Use code tags for posting source code. This is explained in two of Nick Gammon's posts at the top of this Forum.

This needs to be declared as ‘unsigned long’, not just as ‘long’:-

long lastDebounceTime = 0;  // the last time the output pin was toggled

‘long’ isn’t large enough to store ‘millis()’ values.

There’s no need to declare these as inputs. ‘analogRead()’ takes care of that:-

pinMode (FSR_sensor_0, INPUT);
pinMode (FSR_sensor_1, INPUT);
pinMode (FSR_sensor_2, INPUT);
pinMode (FSR_sensor_3, INPUT);

This is pretty pointless:-

if ( (FsrVal_2 > 10 && FsrVal_1 == 0 && FsrVal_3 == 0 ) || ( FsrVal_3 > 10 && FsrVal_2 == 0 && FsrVal_1 == 0 ))
    digitalWrite (LED_12, HIGH);
else
    digitalWrite (LED_12, HIGH);

Please edit your post and place code tags around your code as suggested. They can be generated by the </> button in the “Reply” window, or can be typed manually like this:-

[code]Place your code here[/code]
It will appear in a block like this

Also, as well as correct formatting, removing all superfluous blank lines will make your code far more readable.
(Auto Format doesn’t by default remove blank lines.)


my code is not working properly.

Be more specific - exactly what is happening compared with what is supposed to happen?

the secaond loop is not working for some reason. why?

What do you define as “the second loop”?