c++ - Multiple if statements and -


thanks in advance help.

so i'm working on pressure sensor. idea when pressure sensor gets value, 10 , decreases sharply after has gotten 10, activate buzzer. (so it's like, pump car tire 10 , want know if there leak)

i life of me can not make happen. know i'm missing small appreciate help.

below code:

    #include <liquidcrystal.h> liquidcrystal lcd(12, 11, 5, 4, 3, 2);        // these constants won't change: const int analogpin = a0;    // pin sensor attached const int ledpin = 13;       // pin led attached const int threshold = 5;   // arbitrary threshold level that's in range of analog input const int buzzer = 9;  // pin buzzer connected to.  void setup() {   // initialize led pin output:   pinmode(ledpin, output);  // initilizes pin output.   pinmode(buzzer, output); // set buzzer - pin 9 output    // initialize serial communications:   serial.begin(9600);   lcd.begin(16, 2);   lcd.print ("pressure in kpa"); }  void loop() {   // read value of pressure sensor:   float sensorvalue = analogread(analogpin);   // int kpa = (((sensorvalue*5)/1024)*(120/5)-116); // 116 subtracted equilibrate sensor   int kpa = ((sensorvalue * 5 / 1024) * (15 / 5) * (6.894 / 1) - 10); //   // if analog value greater whatever threshold use , turn on led:    if (kpa > threshold )      {     digitalwrite(ledpin, high);     digitalwrite(buzzer, high);     tone(buzzer, 1000); // controls picth of sound. (hz)     delay(1000);   } else {     digitalwrite(ledpin, low);     digitalwrite(buzzer, low);     notone(buzzer);     // stop sound...     delay(1000);   }     // print analog value:   serial.println(kpa);   delay(1);        // delay in between reads stability   lcd.setcursor (0, 1);   lcd.print (kpa);  }  thanks. 

i have edited code reflect trying do.

essentially need check if pressure increasing or decreasing. can take 2 readings , compare them; 1 reading taken before other. if latest reading higher previous going up, no cause alarm.

if latest reading less previous pressure going down. so, cause alarm not yet...

two conditions need met before alarm sounds, pressure needs on downward path , pressure needs below threshold value.

kpa must going down , below threshold:

(val < previous && val < threshold)

see if works, sorry rushed bit , haven't tested @ all:

#include <liquidcrystal.h>  liquidcrystal lcd(12, 11, 5, 4, 3, 2);  // these constants won't change: const int analogpin = a0;    // pin sensor attached const int ledpin = 13;       // pin led attached const int threshold = 5;   // arbitrary threshold level that's in range of analog input const int buzzer = 9;  // pin buzzer connected to. int val = 0;  // store value int previous; // previous reading  void setup() {   pinmode(ledpin, output);  // initialize led pin output:   pinmode(buzzer, output); // set buzzer - pin 9 output   serial.begin(9600);   // initialize serial communications:   lcd.begin(16, 2);   lcd.print ("pressure in kpa"); }  void loop() {   float sensorvalue = analogread(analogpin);   // read value of pressure sensor:   int kpa = ((sensorvalue * 5 / 1024) * (15 / 5) * (6.894 / 1) - 10);    // want check if going or down.   previous = val;   val = kpa;    if (val > previous) {     digitalwrite(ledpin, high);     delay(1000);     digitalwrite(ledpin, high);  // make led flashy-flashy if going     delay(1000);   }   else if (val < previous && val < threshold) {     digitalwrite(ledpin, low); // ... , switch off led     tone(buzzer, 1000);     // wee wah wee wah wee wah     delay(1000);   }  } 

i added flashing led code because flashing leds better. used else...if statement.

hopefully work.

cheers, ingwe.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -