Atualizar tachometer_v1.ino
This commit is contained in:
parent
95e19ffc20
commit
87a06ecc65
1 changed files with 30 additions and 11 deletions
|
@ -39,6 +39,7 @@ unsigned long lastTime = 0; // To store the last time when RPM was calculated
|
|||
unsigned long currentTime = 0; // To store the current time
|
||||
float rpm = 0; // Variable to store the RPM value
|
||||
float speed_m_min = 0; // Variable to store the speed in meters per minute
|
||||
float lastSpeed_m_min = -1; // Variable to store the last speed value
|
||||
|
||||
// Constants for encoder and roller
|
||||
const int pulsesPerRevolution = 1000; // Pulses per revolution of the encoder
|
||||
|
@ -53,6 +54,14 @@ void setup() {
|
|||
lcd.init();
|
||||
lcd.backlight();
|
||||
|
||||
// Display fixed text on the LCD
|
||||
lcd.setCursor(2, 0);
|
||||
lcd.print("CONVEYOR SPEED");
|
||||
lcd.setCursor(5, 1);
|
||||
lcd.print("CONTROLLER");
|
||||
lcd.setCursor(5, 2);
|
||||
lcd.print("VELOCIDADE");
|
||||
|
||||
// Set up interrupts for encoder signal changes
|
||||
attachInterrupt(digitalPinToInterrupt(ENCODER_CLK), ai0, CHANGE);
|
||||
attachInterrupt(digitalPinToInterrupt(ENCODER_DT), ai1, CHANGE);
|
||||
|
@ -74,17 +83,17 @@ void loop() {
|
|||
// Reset counter for the next measurement
|
||||
counter = 0;
|
||||
|
||||
// Display RPM and speed on the LCD
|
||||
lcd.clear();
|
||||
lcd.setCursor(2, 0);
|
||||
lcd.print("CONVEYOR SPEED");
|
||||
lcd.setCursor(5, 1);
|
||||
lcd.print("CONTROLLER");
|
||||
lcd.setCursor(5, 2);
|
||||
lcd.print("VELOCIDADE");
|
||||
lcd.setCursor(5, 3);
|
||||
lcd.print(speed_m_min);
|
||||
lcd.print(" m/min");
|
||||
// Display speed on the LCD only if it has changed
|
||||
if (speed_m_min != lastSpeed_m_min) {
|
||||
lcd.setCursor(5, 3);
|
||||
lcd.print(" "); // Clear previous value
|
||||
lcd.setCursor(5, 3);
|
||||
lcd.print(speed_m_min);
|
||||
lcd.print(" m/min");
|
||||
|
||||
// Update the last speed value
|
||||
lastSpeed_m_min = speed_m_min;
|
||||
}
|
||||
|
||||
// Update the last time reference
|
||||
lastTime = currentTime;
|
||||
|
@ -106,3 +115,13 @@ void ai1() {
|
|||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Interrupt service routine for encoder channel B
|
||||
void ai1() {
|
||||
// If both signals are different, the encoder is rotating forward
|
||||
if (digitalRead(ENCODER_CLK) != digitalRead(ENCODER_DT)) {
|
||||
counter++;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue