Multiple Void and count every 10 second

Hello everyone, I'm currently doing some project that requires to count every 10 seconds, and there will be multiple calculation inside it (so i assume it will need multiple void inside it)
I've search some topics in this forum but I'm currently stuck on combining void and millis

int sensePin =A8;
unsigned int counter = 0;
unsigned int windspeed = 0;
int period = 10000;


void setup() {
  Serial.begin(9600);
}

void loop() {
  counting;
//  windtuing;
  Serial.println(counter);

  //Print every 10 second
  delay (10000);
}

void counting () {
 int valanemo = (analogRead(sensePin));

 if (valanemo<100){
  counter++;

 //Count every 10 seconds
 unsigned long millis();                     
 long startTime = millis();
 while(millis() < startTime + period) {
 }
 
 }
}

void windtuing (){
  int windspeed = counter * 100;
}

Really appreciate your help guys :smiley:

You do not need to redefine millis: unsigned long millis();

It seems you are missing the fundamentals for functional programming. Hit the books for a few hours.

What you are calling a 'void' is actually a function that returns nothing (void):
http://www.cplusplus.com/doc/tutorial/functions/

May other topics here:
http://www.cplusplus.com/doc/tutorial/

You may find some useful ideas in planning and implementing a program.

Ten seconds is a very long time for an Arduino so it should not be under any pressure.

...R

so i assume it will need multiple void inside it

Utter nonsense. Suppose that the functions returned ints. You wouldn't be talking about "multiple ints inside it", would you.

The code blocks are FUNCTIONS, not VOIDS!

Hello there I'm back thanks @pyro robin and paul for the feedback
I've read the links that you guys gave to me and its helpful

So I'm trying to simplified it by making it like this

int Value;
void setup(){
  Serial.begin(9600);
}

void loop (){
  sensorAnem();
  Serial.println(Value); // The result on this part is always 0 :(
  delay(1000);
}

// Read Sensor 1
void sensorAnem(){ // I've changed this between void and int
  int Value = analogRead(A8);
}

But why is the result is always 0 :frowning: From the things that I read from pyro's guide, on the loop it should call the function below and make it display the value of analogRead in A8 pin

thank you again, your help will be very appreciated

Now you need to Google "scope"

You have two variables called "Value", one of which has very limited scope.
If you made sensorAnem return it's value, that would make more sense.

This

void sensorAnem(){ // I've changed this between void and int
  int Value = analogRead(A8);
}

should be

void sensorAnem(){ // I've changed this between void and int
 Value = analogRead(A8);
}

notice that there is no "int"

Using int creates a new local variable that has nothing to do with the other variable called Value. The local variable disappears when the function ends.

...R

OH MY GOD IT WORKS!! Thanks Everyone!

int Value;
unsigned int counter = 0;

void setup(){
  Serial.begin(9600);
}

void loop (){

  sensorAnem();
  Serial.println(Value); // The result on this part is always 0 :(
  Serial.println(counter);
  delay(1000);
}

// Read Sensor 1
void sensorAnem(){ // I've changed this between void and int
  Value = analogRead(A8);
  if (Value <100) {
    counter++;
  }
  return;
}

Thanks AWOL and robin!
I'm currently figuring out how to use the millis function for the timing without using delay :wink:

The "return" in "sensorAnem" is pointless - there's nowhere else for the code to go but to return at that point.

Ah! okay then, I already deleted it. Thanks AWOL :wink:
anyway, problem solved! thanks guys!