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