delay and millis

Can we use delay and millis() in the same program??

What happened when you tried?

Yes you can.

hlo guyss...i am doing a project that if i keep my fingerprint ,the sensor will detect myself and open the solenoid valve.i also have flow sensor to measure the flow and if the flow exceeds the level it will close solenoid valve..now my problem is i am unable to convert delay to millis..then it shows an error as pulsecounter did not declared in the scope...

raw.ino (13.9 KB)

psycho0:
hlo guyss...i am doing a project that if i keep my fingerprint ,the sensor will detect myself and open the solenoid valve.i also have flow sensor to measure the flow and if the flow exceeds the level it will close solenoid valve..now my problem is i am unable to convert delay to millis..then it shows an error as pulsecounter did not declared in the scope...

Advice:

Spend a few hours learning to understand and write code using Arrays

pulsecounter is not delared in the declared...this error is displayed..

raw.ino (13.9 KB)

Cross posted here: [MERGED] some one help me.. - Microcontrollers - Arduino Forum

Reported to mods

so is my program has error in array??

pulsecounter is not delared

You're absolutely correct.

Please post the exact error message you see - all of it.

psycho0:
so is my program has error in array??

No, you need to learn about arrays. When you do, you will see how to fix your program. If you just try to figure it out from what he said without going and learning about arrays then you will stay lost.

Arduino: 1.8.6 Hourly Build 2018/01/03 03:33 (Windows 10), Board: "Arduino Mega ADK"

C:\Users\imman\Desktop\raw\raw.ino: In function 'void setup()':

raw:83: error: 'pulseCounter' was not declared in this scope

attachInterrupt(sensorInterrupt, pulseCounter, FALLING); //you can use Rising or Falling

^

C:\Users\imman\Desktop\raw\raw.ino: In function 'uint8_t getFingerprintEnroll()':

raw:518: error: 'SetSolinoidValve' was not declared in this scope

SetSolinoidValve();

^

raw:524: error: 'pulseCounter' was not declared in this scope

attachInterrupt(sensorInterrupt,pulseCounter, FALLING);

^

raw:531: error: a function-definition is not allowed here before '{' token

{

^

raw:537: error: a function-definition is not allowed here before '{' token

{

^

Multiple libraries were found for "Adafruit_Fingerprint.h"
Used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\Adafruit_Fingerprint_Sensor_Library-1.1.1
Not used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\FingerPrint
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\hardware\arduino\avr\libraries\SoftwareSerial
Not used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\SoftwareSerial
exit status 1
'pulseCounter' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

You can't declare functions inside other functions, in this case, inside getFingerprintID.

I think you've got way too much code, which makes spotting problems like this much harder.

yaa..it has so many codes..my project is if i keep my fingerprint then the solenoid valve will open and flow sensor will detect the flow and closes the solenoid valve when the limit reaches..so i has 2 r 3 sensor reason for this messy codes..i want to mingle these 3 codes

Can we start again ?
Let's start with the basics

Arrays[]

int state[11];   or whatever [size] you need...

state[0] = 0;
state[1] = 0;
state[2] = 0;

Simpler...

#define NUM_MEMBERS 10
for (char x=0; x<NUM_MEMBERS; x++)
  state[x] = 0;

-- or if we're going to stay with discrete (HORRIBLE) variables ...

Switch () { case } blocks
As per your existing code...

 Switch (finger.fingerID) {
  case 1:
     digitalWrite(10,State1);
     State1=!State1;  
     break;
  case: 2
     digitalWrite(10,State2);
     State2=!State2; 
     break;
  case: 3
     digitalWrite(10,State3);
     State3=!State3;  
     break;
  case: 4
--- etc.
}

Let's try a simpler way to replace ALL that!

     digitalWrite(10, state[finger.fingerID]);
     state[finger.fingerID] = !state[finger.fingerID];

Now, we can change the ints to bools - just to be 'correct'.

bool state[11];   or whatever [size] you need...
... or with the above constant...
bool state[NUM_MEMBERS];

lastchancename:
Simpler...

#define NUM_MEMBERS 10

for (char x=0; x<NUM_MEMBERS; x++)
  state[x] = 0;

or even simpler:

int state[11];

globals are by default initialized to zero!

Yeah - I was trying to illustrate that he could initialise them to whatever value he needed

still got this my error..

Arduino: 1.8.6 Hourly Build 2018/01/03 03:33 (Windows 10), Board: "Arduino Mega ADK"

C:\Users\imman\Desktop\raw\raw.ino: In function 'void setup()':

raw:74: error: 'pulseCounter' was not declared in this scope

attachInterrupt(sensorInterrupt, pulseCounter, FALLING); //you can use Rising or Falling

^

C:\Users\imman\Desktop\raw\raw.ino: At global scope:

raw:262: error: expected constructor, destructor, or type conversion before '(' token

delay(1500);

^

raw:263: error: 'lcd' does not name a type

lcd.clear();

^

raw:264: error: 'lcd' does not name a type

lcd.setCursor(0, 0);

^

raw:265: error: 'lcd' does not name a type

lcd.print("Place");

^

raw:266: error: 'lcd' does not name a type

lcd.setCursor(0, 1);

^

raw:267: error: 'lcd' does not name a type

lcd.print("your Finger..!");

^

raw:268: error: 'Serial' does not name a type

Serial.print(" with confidence of "); Serial.println(finger.confidence);

^

raw:268: error: 'Serial' does not name a type

Serial.print(" with confidence of "); Serial.println(finger.confidence);

^

raw:269: error: expected unqualified-id before 'return'

return finger.fingerID;

^

raw:270: error: expected declaration before '}' token

}

^

Multiple libraries were found for "Adafruit_Fingerprint.h"
Used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\Adafruit_Fingerprint_Sensor_Library-1.1.1
Not used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\FingerPrint
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\hardware\arduino\avr\libraries\SoftwareSerial
Not used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\SoftwareSerial
exit status 1
'pulseCounter' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

raw.ino (13.1 KB)

Your opening and closing brackets for the different functions are not correct. I would put every bracket on its own line, and then use autoformat (ctrl +T) to line things up. Make sure everything matches. You can not setup a function within another function.

I can see that the pulseCounter isr and SetSolinoidValue() are both within getFingerprintEnroll().

#include <Adafruit_Fingerprint.h>
#include<Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal.h>
int getFingerprintIDez();
uint8_t getFingerprintEnroll();
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino (WHITE wire)
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
//Adafruit_Fingerprint finger = Adafruit_Fingerprint(&Serial1);
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
int sensorInterrupt = 0; // interrupt 0
int sensorPin = 2; //Digital Pin 2
int FingerMode = 0 ;
int SkipHead = 0;
int state[11];
uint8_t id;
unsigned int SetPoint = 400; //400 milileter

/The hall-effect flow sensor outputs pulses per second per litre/minute of flow./
float calibrationFactor = 4.5; //You can change according to your datasheet

volatile byte pulseCount = 0;

float flowRate = 0.0;
unsigned int flowMilliLitres = 0;
unsigned long totalMilliLitres = 0;

unsigned long oldTime = 0;
void setup()
{
pinMode(8, INPUT_PULLUP); //orange finger detect
pinMode(9, INPUT_PULLUP); //white enroll

pinMode(10, OUTPUT); //relay
digitalWrite(10, LOW);
lcd.begin(16, 2); // initialize the lcd
// lcd.backlight(); //default backlight on
lcd.clear();
// while (!Serial); // For Yun/Leo/Micro/Zero/...

Serial.begin(9600);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
attachInterrupt(sensorInterrupt, pulseCounter, FALLING); //you can use Rising or Falling
lcd.print("finger detect");
// delay(100);
// set the data rate for the sensor serial port
finger.begin(57600);

if (finger.verifyPassword()) {
// lcd.print("Found fingerprint!");
} else {
// lcd.print("Did not find fingerprint sensor :(");
while (1);
}
}

....

can u solve something in this,,,..

errorr is

Arduino: 1.8.6 Hourly Build 2018/01/03 03:33 (Windows 10), Board: "Arduino Mega ADK"

C:\Users\imman\Desktop\raw\raw.ino: In function 'void setup()':

raw:74: error: 'pulseCounter' was not declared in this scope

attachInterrupt(sensorInterrupt, pulseCounter, FALLING); //you can use Rising or Falling

^

C:\Users\imman\Desktop\raw\raw.ino: At global scope:

raw:263: error: expected constructor, destructor, or type conversion before '(' token

delay(1500);

^

raw:264: error: 'lcd' does not name a type

lcd.clear();

^

raw:265: error: 'lcd' does not name a type

lcd.setCursor(0, 0);

^

raw:266: error: 'lcd' does not name a type

lcd.print("Place");

^

raw:267: error: 'lcd' does not name a type

lcd.setCursor(0, 1);

^

raw:268: error: 'lcd' does not name a type

lcd.print("your Finger..!");

^

raw:269: error: 'Serial' does not name a type

Serial.print(" with confidence of "); Serial.println(finger.confidence);

^

raw:269: error: 'Serial' does not name a type

Serial.print(" with confidence of "); Serial.println(finger.confidence);

^

raw:270: error: expected unqualified-id before 'return'

return finger.fingerID;

^

raw:271: error: expected declaration before '}' token

}

^

Multiple libraries were found for "Adafruit_Fingerprint.h"
Used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\Adafruit_Fingerprint_Sensor_Library-1.1.1
Not used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\FingerPrint
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\hardware\arduino\avr\libraries\SoftwareSerial
Not used: C:\Users\imman\Desktop\arduino_flow\arduino-nightly\libraries\SoftwareSerial
exit status 1
'pulseCounter' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

raw:74: error: 'pulseCounter' was not declared in this scope

pulseCounter is not the same thing as pulseCount

I can't help noticing that there's no delay(1500) in the code you posted, yet code that isn't there gave you an error message. Amazing.