Urgent help with programmation

HELLO! CAN SOMEONE EXPLAIN ME HOW THIS PROGRAM WORKS? IT IS COMPLICATED FOR MY LEVEL AND I NEED TO PRESENT A PROJECT ABOUT IT NEXT WEEK.

// digital pin 2 is the hall pin
int hall_pin = 2;
// set number of hall trips for RPM reading (higher improves accuracy)
float hall_thresh = 100.0;

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(115200);
// make the hall pin an input:
pinMode(hall_pin, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// preallocate values for tach
float hall_count = 1.0;
float start = micros();
bool on_state = false;
// counting number of times the hall sensor is tripped
// but without double counting during the same trip
while(true){
if (digitalRead(hall_pin)==0){
if (on_state==false){
on_state = true;
hall_count+=1.0;
}
} else{
on_state = false;
}

if (hall_count>=hall_thresh){
  break;
}

}

// print information about Time and RPM
float end_time = micros();
float time_passed = ((end_time-start)/1000000.0);
Serial.print(“Time Passed: “);
Serial.print(time_passed);
Serial.println(“s”);
float rpm_val = (hall_count/time_passed)*60.0;
Serial.print(rpm_val);
Serial.println(” RPM”);
delay(1); // delay in between reads for stability
}

THHHHHANKKKSSS

Do you have any examples to show that the program really does “work”?
Paul

I would doubt anyone is going to spare the time to write a line by line explanation of how the program works.

Presuambly if you have been asked to explain it, someone wants you to work it out for yourself.

A good start would be to try it, and see if it does what its supposed to do.

YES, IT DOES WORK PERFECTLY. I JUST CAN’T UNDERSTAND THE VOID LOOP PART

// the loop routine runs over and over again forever:
void loop() {
// preallocate values for tach
float hall_count = 1.0;
float start = micros();
bool on_state = false;
// counting number of times the hall sensor is tripped
// but without double counting during the same trip
while(true){
if (digitalRead(hall_pin)==0){
if (on_state==false){
on_state = true;
hall_count+=1.0;
}
} else{
on_state = false;
}

if (hall_count>=hall_thresh){
  break;
}

Hello
this sketch represents a RPM meter without using the loop.

When posting do not use capital letters, as this use means that you are screaming …

what do you mean by that?
Even though I can’t understand the functions

it sits in a while loop (while (true)) until hall_count exceeds a threshold where is reports on the total time and RPM that the hall device must be measuring

within that loop, it increments the counts each falling edge of the hall device.

which threshold? what’s that?

hall_thresh which is 100

OK, thanks.
But what do the functions of the program mean? What do they do?

float hall_count = 1.0;
float start = micros();
bool on_state = false;
while(true){
if (digitalRead(hall_pin)==0){
if (on_state==false){
on_state = true;
hall_count+=1.0;
}
} else{
on_state = false;
}

if (hall_count>=hall_thresh){
  break;
}

setup() is executed once on an Arduino and configured the Serial interface bit-rate and the digital pin as INPUT that the hall device connects to

loop() is repeatedly invoked on an Arduino. your version counts hall events and reports an RPM every 100 counts.

and what does true and false mean?

in this case simply two binary states. they have values of 1 and 0.

when the hall device output first changes value from HIGH (1) to LOW (0), an edge, it increments the count and sets state to true (1) so that it doesn’t repeatedly increment the count while the input remains LOW.

when the input goes HIGH it sets the state to false (0) so that is it can recognizes the next falling edge

ok. seems that none of this is familiar to you. could please explain what you’re doing with this code?

Because of your questions, it seems that you don’t know programming, so how can someone who doesn’t know programming do a project for a program?

RV mineirin

PS: I recommend …

I am trying to measure speed with the hall sensor in Arduino Hall

it’s obvious that you using the code to measure the RPM of something.

i’m curious what you’re measuring, why your using an Arduino when you know so little about it and why you want to know now?

OK, here’s the deal.
I am a student and I need to present a project next week to obtain my grade. My partner and I were working on another problem, but it was impossible. Now we have found this project and we don’t understand it, because it’s too difficult for us.
We have a basic level.

thanks

@mgarciav12 DON’T use code you don’t understand! What if your teacher asks you specifically to draw a flow diagram of your code! Also, if this was your job, you would be fired by now!

Remember - Your teacher will check your code is not plagerized - and that code is. I would not only give you a 0 score, I would fail you from the whole course.