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;
}
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 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
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.
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