A MOMENT OF CONFESSION: I fully appreciated your comments StephenL38 and took them to heart.
I realize that I was not qualified to attempt this project as it was a “road to far” and I was way over my head. I have a history of attacking an unknown area with brute force and effort and usually I gain some success. But my brother, who was a former HP programmer said I really had no business trying this unless I committed to fully learning coding in earnest.
I want to explain my reticence for being less forthcoming thus far. I’ve been too apprehensive about exposing my ignorance to an audience of perfect strangers, some of whom felt intimidating. I knew I would not be prepared to answer the technical questions.
PURPOSE: I started this project in order to mitigate a functional obstacle I increasingly face in my pastime joy of fishing from a boat. I use downriggers that set the depth at which your lines are running. These have very small mechanical digital counters seen through a small window. As the terrain changes constantly and you may be only 3-5 ft off the bottom, you have to be ready to make manual adjustments often and quickly.
Lately, my medical conditions have made it harder for me to recall the count settings so I have to go look at the settings every few minutes as the depths change and this is also harder due to neuropathy in my feet.
After stumbling on a YouTube of a teen who made a bidirectional people counter with Arduino, I thought it would be great to adapt this idea to make a highly visible digital display of the counters that could sit on the dash or even be carried around portably.
I had gotten the impression that Arduino technology was amenable to a novice with no programing experience. But when I started to explore this, it seemed this was really beyond my ability to even start. I bought a big starter kit and an Arduino Book and started the first 20 lessons in Paul McWhortor’s Tutorials. But I felt I would never gain the ability to make this, even if I completed all the 68 lessons, since many would not advance me toward this goal. Perhaps they are designed to impart all the requisite skills/knowledge, but I was losing enthusiasm. I also couldn’t find any sketches that addressed this particular problem, at least to a published solution. (I did see a very complex approach by a model train hobbyist who used a single 3D TMAG5170 sensor to calculate bilateral rotations to know the distance the train traveled on the tracks.)
I shifted to attacking the problem with non-programming approach: A mechanical lever that was moved back and forth by a fixed post on the rotor hub. Two microswitches juxtaposed on each side of the lever sent impulses to a Digital Totalizer Display that produced a net count of rotor rotations. This worked functionally but the pounding on the lever meant the mechanism would not likely survive very long.
So, I returned to the Arduino for a noncontact sensor solution. I thought about using an optical sensor but decided that the dusty environment would hinder this and I had become aware of the whole issue of debouncing. It seemed that digital Hall effect sensors had distinct advantages by using internal circuitry like Schmitt triggers to clean up their electrical output by introducing hysteresis, preventing rapid switching between states due to noise or small magnetic field fluctuations, ensuring a clean digital signal.
While I found sketches that would count rotations or RPMs, I couldn’t find one to help integrate the directional component needed to compute the “Net Total” rotational count. I started working with ChatGPT, Gemini and Copilot Pro to make basic sketches but they never could solve the “coding problems”. The counts were always highly chaotic and randomly changing and never improved, despite having adding more and more “Precise measures of coding”.
Finally, I disconnected the direct drive to a rotor and manually turned the rotor slowly (Duh!!). I saw the S1H S2L input occur as the magnet entered the field of the sensors, but to my surprise as the magnet left the field I would see S1HS2H readings. This explained why the Net Count was never accurate, as the directional component would be all screwy.
I had settled on using CopilotGitHub AI (as I already had the Copilot Pro subscription) and submitted this discovery. The AI immediately said he would filter out any HH or LL sensor inputs, since they had to be spurious. At this point I had achieved some success and the Absolute Count, Direction, Net Count and Sensor State changes all were correlating properly. I was a bit encouraged.
Looking forward, I felt the Arduino Uno probably would not be adequate, since its memory was expended when I just added U8g2 fonts. I was considering the Mega when I began to read about the ESP microprocessors and it seemed like these easily had the resources to process the data and then send the output wirelessly to cell phones. This solved a lot of difficulties including running wiring, connecting a display and protecting the display from a moist/dusty environment. The phone would be a ready-made display addressing these issues.
So, I started with the ESP2866 and then ESP32 S3 as mentioned previously and have given up on them, (although the ESP32 may still hold some hope.) It seemed that the process of transitioning from one platform to another always disrupted the processing, especially the handling of the directional input.
I could just cave, and proceed with a hard-wired design from microprocessor to a display module, but this would not be the preferred solution. So, I am going to ask for your help. I know, compared the sophisticated designs you encountered, this is probably not even a challenge for many of you.
Project Details:
AI Contributions: As mentioned, I relied heavily on AI input. I tried to use CopilotPro, ChatGPT and Gemini but settled on ChatCopilotGitHub because I already subscribed to Copilot Pro and this seemed the most helput.
Rotor: I am currently using two prototypes for testing. One is just a small motor with a rotating pulley that has a neodymium disc magnate (9mm x 3mm) glued to the circular face. The magnets pass two Unnamed Hall Effect Sensor Modules that use A3141 chipset. The larger rotor is a life-sized rotor removed from a broken downrigger that I turn with a rechargeable hand drill. It has the same sensor modules.
Display: A 1602 I2C generic display that has no potentiometer.
Microprocessor: Arduino Uno Rev3
HALL EFFECT SENSORS: I am using cheap modules bought on Amazon. I don’t have data sheet but they incorporate the 3144E switch type sensor. The data sheet for this is attached. I also bought some KY-024 Linear Magnetic Hall Effect Sensor Modules which use the same sensor but incorporate a potentiometer which I thought might be useful if problems stemmed from strength of magnetic field. But I never used as connecting wires of sensors were bent up.
Wiring: The two sensors on the small rotor unit are attached by 6 wires.
- The GND and VCC from all sensors are each combined and attached to the ground and 5 v pins of the Arduino.
- The DO sensor wires from the small rotor are attached to pins 2 and 3 of the Arduino.
- The DO sensor wires of the large rotor go to pins 6 and 7 of the Arduino.
- A Reset push button to GND is connected to pin 4
Rotational Frequency: The small rotor turns at a fixed rate of about 60 rpm. The Large rotor rate is highly variable, as it is controlled by a heavy-duty cordless hand drill attached to the spindle from below. The real unit rotates from barely turning to a maximum of about 480 rpm. (It went from 0-100 rotations in about 13 seconds.)
POWER SUPPLY: The prototype is powered by the USB B cable. The rotors and microprocessors will be powered by two large 12 volt AGM batteries (60 + 80 amp hour capacity) or possibly by two 12 volt, LiFePO4, 105 amp hour batteries. I have not yet considered which way I will reduce voltage to 5v or 3.3v. The cell phone will be charged normally by a USB 3 cable from a 12 volt adapter. It can be on batteries if mobility is required.
ATTACHMENTS: I will attach the following documents.
- Schematic of Bidirectional Rotor Counter
- 3144 Hall Effect Sensor Data Sheet
- KY-024 Data Sheet
- Pictures the generic 3144 Sensor and the KY-024
- Picture of Rotors and Setup
```cpp
//THIS IS REDO OF CopilotGitHub_Best_LCD_B4_OLED_4_42_V7_NOCOMMENTS
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_ROWS);
const int hallSensor1Pin1 = 2;
const int hallSensor2Pin1 = 3;
const int hallSensor1Pin2 = 6;
const int hallSensor2Pin2 = 7;
const int resetButtonPin = 4;
int lastStateSensor1_1 = LOW;
int lastStateSensor2_1 = LOW;
int currentStateSensor1_1 = LOW;
int currentStateSensor2_1 = LOW;
int lastStateSensor1_2 = LOW;
int lastStateSensor2_2 = LOW;
int currentStateSensor1_2 = LOW;
int currentStateSensor2_2 = LOW;
int netCount1 = 0; // NET COUNT FOR ROTOR 1 (CW ROTATIONS - CCW ROTATIONS)
long absoluteRotations1 = 0;
int netCount2 = 0;
long absoluteRotations2 = 0;
int lastButtonState = HIGH;
int currentButtonState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
bool rotationDetected1 = false;
bool rotationDetected2 = false;
String rotationDirection1 = "";
String rotationDirection2 = "";
void readSensors();
void detectRotation();
void handleButtonPress();
void updateDisplay();
String padZero(int num, int width);
void displayCount();
void saveCountToEEPROM();
void setup() {
Serial.begin(9600);
pinMode(hallSensor1Pin1, INPUT); // SET hallSensor1Pin1 AS INPUT
pinMode(hallSensor2Pin1, INPUT); // SET hallSensor2Pin1 AS INPUT
pinMode(hallSensor1Pin2, INPUT); // SET hallSensor1Pin2 AS INPUT
pinMode(hallSensor2Pin2, INPUT); // SET hallSensor2Pin2 AS INPUT
pinMode(resetButtonPin, INPUT_PULLUP);
lcd.begin(LCD_COLUMNS, LCD_ROWS);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Initializing...");
delay(2000);
lcd.clear();
netCount1 = EEPROM.read(0) | (EEPROM.read(1) << 8);
netCount2 = EEPROM.read(2) | (EEPROM.read(3) << 8);
displayCount();
}
void loop() {
readSensors();
detectRotation();
handleButtonPress();
updateDisplay();
delay(10);
}
void readSensors() {
currentStateSensor1_1 = digitalRead(hallSensor1Pin1);
currentStateSensor2_1 = digitalRead(hallSensor2Pin1);
currentStateSensor1_2 = digitalRead(hallSensor1Pin2);
currentStateSensor2_2 = digitalRead(hallSensor2Pin2);
}
void detectRotation() {
if (currentStateSensor1_1 == HIGH && lastStateSensor1_1 == LOW && currentStateSensor2_1 == LOW) {
rotationDirection1 = "CW";
netCount1++;
absoluteRotations1++;
rotationDetected1 = true;
saveCountToEEPROM();
} else if (currentStateSensor2_1 == HIGH && lastStateSensor2_1 == LOW && currentStateSensor1_1 == LOW) {
rotationDirection1 = "CCW";
if (netCount1 > 0) {
netCount1--;
absoluteRotations1++;
rotationDetected1 = true;
saveCountToEEPROM();
}
}
if (currentStateSensor1_2 == HIGH && lastStateSensor1_2 == LOW && currentStateSensor2_2 == LOW) {
rotationDirection2 = "CW";
netCount2++;
absoluteRotations2++;
rotationDetected2 = true;
saveCountToEEPROM();
} else if (currentStateSensor2_2 == HIGH && lastStateSensor2_2 == LOW && currentStateSensor1_2 == LOW) {
rotationDirection2 = "CCW";
if (netCount2 > 0) {
netCount2--;
absoluteRotations2++;
rotationDetected2 = true;
saveCountToEEPROM();
}
}
lastStateSensor1_1 = currentStateSensor1_1;
lastStateSensor2_1 = currentStateSensor2_1;
lastStateSensor1_2 = currentStateSensor1_2;
lastStateSensor2_2 = currentStateSensor2_2;
}
void handleButtonPress() {
currentButtonState = digitalRead(resetButtonPin);
if (currentButtonState == LOW && lastButtonState == HIGH && (millis() - lastDebounceTime) > debounceDelay) {
netCount1 = 0;
netCount2 = 0;
absoluteRotations1 = 0;
absoluteRotations2 = 0;
Serial.println(" Reset to 0");
lcd.clear();
lcd.print(" Reset to 0");
delay(1000);
lcd.clear();
saveCountToEEPROM();
lastDebounceTime = millis();
}
lastButtonState = currentButtonState;
}
void updateDisplay() {
if (rotationDetected1 || rotationDetected2) {
displayCount();
rotationDetected1 = false;
rotationDetected2 = false;
}
}
String padZero(int num, int width) {
String str = String(num);
while (str.length() < width) {
str = "0" + str;
}
return str;
}
void displayCount() {
String directionStr1 = rotationDirection1;
String line1_1 = padZero(absoluteRotations1 % 100, 2) + directionStr1 + padZero(abs(netCount1) % 100, 2);
String line2_1 = "S1" + String(currentStateSensor1_1 ? "H" : "L") + " S2" + String(currentStateSensor2_1 ? "H" : "L");
String directionStr2 = rotationDirection2;
String line1_2 = padZero(absoluteRotations2 % 100, 2) + directionStr2 + padZero(abs(netCount2) % 100, 2);
String line2_2 = "S1" + String(currentStateSensor1_2 ? "H" : "L") + " S2" + String(currentStateSensor2_2 ? "H" : "L");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(line1_1);
lcd.setCursor(0, 1);
lcd.print(line2_1);
lcd.setCursor(9, 0);
lcd.print(line1_2);
lcd.setCursor(9, 1);
lcd.print(line2_2);
Serial.print("Rotor 1 - Absolute Rotations: ");
Serial.print(absoluteRotations1);
Serial.print(" Direction: ");
Serial.print(rotationDirection1);
Serial.print(" Net Count: ");
Serial.print(netCount1);
Serial.print(" S1: ");
Serial.print(currentStateSensor1_1 ? "H" : "L");
Serial.print(" S2: ");
Serial.println(currentStateSensor2_1 ? "H" : "L");
Serial.print("Rotor 2 - Absolute Rotations: ");
Serial.print(absoluteRotations2);
Serial.print(" Direction: ");
Serial.print(rotationDirection2);
Serial.print(" Net Count: ");
Serial.print(netCount2);
Serial.print(" S1: ");
Serial.print(currentStateSensor1_2 ? "H" : "L");
Serial.print(" S2: ");
Serial.println(currentStateSensor2_2 ? "H" : "L");
}
void saveCountToEEPROM() {
EEPROM.write(0, netCount1 & 0xFF);
EEPROM.write(1, (netCount1 >> 8) & 0xFF);
EEPROM.write(2, netCount2 & 0xFF);
EEPROM.write(3, (netCount2 >> 8) & 0xFF);
}
3141 Hall Effect Sensor Data sheet.pdf (141.1 KB)
KY-024 Data Sheet.pdf (861.7 KB)
Since it looks like the sketch wasn't too long as I misunderstood what I was counting, I am including the sketch I was actually using as I had all the elements commented in CAPs so I could readily find and study individual elements.
```cpp
/*THIS IS REDO OF "CopilotGitHub_Best_LCD_B4_tried_OLED_4_42_V7_0112025"
It took the sketch and added 2nd rotor input and fixed th rising + count after reaching 0
Current resource demand:
Sketch uses 8872 bytes (27%) of program storage space. Maximum is 32256 bytes.
Global variables use 603 bytes (29%) of dynamic memory, leaving 1445 bytes for local variables. Maximum is 2048 bytes.
Change Total Count to Net Count
Add all Cap Commentary for each element of code
*/
#include <Wire.h> // INCLUDE THE WIRE LIBRARY FOR I2C COMMUNICATION
#include <LiquidCrystal_I2C.h> // INCLUDE THE LIQUIDCRYSTAL_I2C LIBRARY FOR LCD CONTROL
#include <EEPROM.h> // INCLUDE THE EEPROM LIBRARY FOR STORING DATA IN NON-VOLATILE MEMORY
// DEFINE THE LCD ADDRESS AND DIMENSIONS
#define I2C_ADDR 0x27 // THE I2C ADDRESS OF THE LCD (CHANGE IF NECESSARY)
#define LCD_COLUMNS 16 // NUMBER OF COLUMNS ON THE LCD
#define LCD_ROWS 2 // NUMBER OF ROWS ON THE LCD
// CREATE AN OBJECT FOR THE LCD WITH THE SPECIFIED PARAMETERS
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_ROWS);
const int hallSensor1Pin1 = 2; // ROTOR 1 HALL SENSOR 1 CONNECTED TO DIGITAL PIN 2
const int hallSensor2Pin1 = 3; // ROTOR 1 HALL SENSOR 2 CONNECTED TO DIGITAL PIN 3
const int hallSensor1Pin2 = 6; // ROTOR 2 HALL SENSOR 1 CONNECTED TO DIGITAL PIN 6
const int hallSensor2Pin2 = 7; // ROTOR 2 HALL SENSOR 2 CONNECTED TO DIGITAL PIN 7
const int resetButtonPin = 4; // RESET BUTTON CONNECTED TO DIGITAL PIN 4
// VARIABLES TO STORE THE STATES OF THE SENSORS FOR ROTOR 1
int lastStateSensor1_1 = LOW;
int lastStateSensor2_1 = LOW;
int currentStateSensor1_1 = LOW;
int currentStateSensor2_1 = LOW;
// VARIABLES TO STORE THE STATES OF THE SENSORS FOR ROTOR 2
int lastStateSensor1_2 = LOW;
int lastStateSensor2_2 = LOW;
int currentStateSensor1_2 = LOW;
int currentStateSensor2_2 = LOW;
// VARIABLES TO STORE THE COUNTS AND ROTATIONS FOR ROTOR 1
int netCount1 = 0; // NET COUNT FOR ROTOR 1 (CW ROTATIONS - CCW ROTATIONS)
long absoluteRotations1 = 0; // ABSOLUTE NUMBER OF ROTATIONS MADE IN BOTH DIRECTIONS FOR ROTOR 1
// VARIABLES TO STORE THE COUNTS AND ROTATIONS FOR ROTOR 2
int netCount2 = 0; // NET COUNT FOR ROTOR 2 (CW ROTATIONS - CCW ROTATIONS)
long absoluteRotations2 = 0; // ABSOLUTE NUMBER OF ROTATIONS MADE IN BOTH DIRECTIONS FOR ROTOR 2
// VARIABLES TO STORE THE BUTTON STATES
int lastButtonState = HIGH; // INITIALIZED TO HIGH BECAUSE OF PULL-UP RESISTOR
int currentButtonState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50; // DEBOUNCE DELAY TO AVOID FALSE TRIGGERS
// VARIABLES TO DETECT ROTATION AND DIRECTION
bool rotationDetected1 = false;
bool rotationDetected2 = false;
String rotationDirection1 = "";
String rotationDirection2 = "";
// FUNCTION DECLARATIONS
void readSensors();
void detectRotation();
void handleButtonPress();
void updateDisplay();
String padZero(int num, int width);
void displayCount();
void saveCountToEEPROM();
void setup() {
Serial.begin(9600); // START SERIAL COMMUNICATION AT 9600 BAUD RATE
pinMode(hallSensor1Pin1, INPUT); // SET hallSensor1Pin1 AS INPUT
pinMode(hallSensor2Pin1, INPUT); // SET hallSensor2Pin1 AS INPUT
pinMode(hallSensor1Pin2, INPUT); // SET hallSensor1Pin2 AS INPUT
pinMode(hallSensor2Pin2, INPUT); // SET hallSensor2Pin2 AS INPUT
pinMode(resetButtonPin, INPUT_PULLUP); // SET resetButtonPin AS INPUT WITH PULL-UP RESISTOR
lcd.begin(LCD_COLUMNS, LCD_ROWS); // INITIALIZE THE LCD WITH THE SPECIFIED COLUMNS AND ROWS
lcd.backlight(); // TURN ON THE BACKLIGHT
lcd.setCursor(0, 0); // SET CURSOR TO THE FIRST COLUMN, FIRST ROW
lcd.print("Initializing..."); // DISPLAY A WELCOME MESSAGE
delay(2000); // WAIT FOR 2 SECONDS
lcd.clear(); // CLEAR THE LCD
// LOAD THE LAST COUNT FROM EEPROM
netCount1 = EEPROM.read(0) | (EEPROM.read(1) << 8);
netCount2 = EEPROM.read(2) | (EEPROM.read(3) << 8);
// DISPLAY THE LAST COUNT ON THE LCD
displayCount();
}
void loop() {
readSensors(); // READ THE STATES OF THE SENSORS
detectRotation(); // DETECT THE DIRECTION OF ROTATION AND UPDATE COUNTS
handleButtonPress(); // HANDLE THE RESET BUTTON PRESS
updateDisplay(); // UPDATE THE LCD DISPLAY
delay(10); // SMALL DELAY TO STABILIZE SENSOR STATES
}
void readSensors() {
// READ THE CURRENT STATES OF THE SENSORS FOR ROTOR 1
currentStateSensor1_1 = digitalRead(hallSensor1Pin1);
currentStateSensor2_1 = digitalRead(hallSensor2Pin1);
// READ THE CURRENT STATES OF THE SENSORS FOR ROTOR 2
currentStateSensor1_2 = digitalRead(hallSensor1Pin2);
currentStateSensor2_2 = digitalRead(hallSensor2Pin2);
}
void detectRotation() {
// FOR ROTOR 1
if (currentStateSensor1_1 == HIGH && lastStateSensor1_1 == LOW && currentStateSensor2_1 == LOW) {
rotationDirection1 = "CW"; // SET DIRECTION TO CLOCKWISE
netCount1++; // INCREMENT NET COUNT
absoluteRotations1++; // INCREMENT ABSOLUTE ROTATIONS
rotationDetected1 = true; // SET ROTATION DETECTED FLAG
saveCountToEEPROM(); // SAVE THE UPDATED COUNT TO EEPROM
} else if (currentStateSensor2_1 == HIGH && lastStateSensor2_1 == LOW && currentStateSensor1_1 == LOW) {
rotationDirection1 = "CCW"; // SET DIRECTION TO COUNTER-CLOCKWISE
if (netCount1 > 0) { // ENSURE THE COUNT DOES NOT GO BELOW 0
netCount1--; // DECREMENT NET COUNT
absoluteRotations1++; // INCREMENT ABSOLUTE ROTATIONS
rotationDetected1 = true; // SET ROTATION DETECTED FLAG
saveCountToEEPROM(); // SAVE THE UPDATED COUNT TO EEPROM
}
}
// FOR ROTOR 2
if (currentStateSensor1_2 == HIGH && lastStateSensor1_2 == LOW && currentStateSensor2_2 == LOW) {
rotationDirection2 = "CW"; // SET DIRECTION TO CLOCKWISE
netCount2++; // INCREMENT NET COUNT
absoluteRotations2++; // INCREMENT ABSOLUTE ROTATIONS
rotationDetected2 = true; // SET ROTATION DETECTED FLAG
saveCountToEEPROM(); // SAVE THE UPDATED COUNT TO EEPROM
} else if (currentStateSensor2_2 == HIGH && lastStateSensor2_2 == LOW && currentStateSensor1_2 == LOW) {
rotationDirection2 = "CCW"; // SET DIRECTION TO COUNTER-CLOCKWISE
if (netCount2 > 0) { // ENSURE THE COUNT DOES NOT GO BELOW 0
netCount2--; // DECREMENT NET COUNT
absoluteRotations2++; // INCREMENT ABSOLUTE ROTATIONS
rotationDetected2 = true; // SET ROTATION DETECTED FLAG
saveCountToEEPROM(); // SAVE THE UPDATED COUNT TO EEPROM
}
}
// UPDATE LAST STATE VARIABLES TO CURRENT STATES
lastStateSensor1_1 = currentStateSensor1_1;
lastStateSensor2_1 = currentStateSensor2_1;
lastStateSensor1_2 = currentStateSensor1_2;
lastStateSensor2_2 = currentStateSensor2_2;
}
void handleButtonPress() {
currentButtonState = digitalRead(resetButtonPin); // READ THE CURRENT STATE OF THE RESET BUTTON
if (currentButtonState == LOW && lastButtonState == HIGH && (millis() - lastDebounceTime) > debounceDelay) {
// IF BUTTON IS PRESSED, RESET THE COUNTS AND ROTATIONS
netCount1 = 0;
netCount2 = 0;
absoluteRotations1 = 0;
absoluteRotations2 = 0;
Serial.println(" Reset to 0");
lcd.clear();
lcd.print(" Reset to 0");
delay(1000);
lcd.clear();
saveCountToEEPROM(); // SAVE THE RESET COUNT TO EEPROM
lastDebounceTime = millis(); // UPDATE THE DEBOUNCE TIME
}
lastButtonState = currentButtonState; // UPDATE LAST BUTTON STATE
}
void updateDisplay() {
if (rotationDetected1 || rotationDetected2) {
displayCount(); // IF A ROTATION IS DETECTED, UPDATE THE DISPLAY
rotationDetected1 = false;
rotationDetected2 = false;
}
}
String padZero(int num, int width) {
// FUNCTION TO PAD NUMBERS WITH LEADING ZEROS
String str = String(num);
while (str.length() < width) {
str = "0" + str;
}
return str;
}
void displayCount() {
// PREPARE THE STRINGS WITH THE REQUIRED FORMAT FOR ROTOR 1
String directionStr1 = rotationDirection1;
String line1_1 = padZero(absoluteRotations1 % 100, 2) + directionStr1 + padZero(abs(netCount1) % 100, 2);
String line2_1 = "S1" + String(currentStateSensor1_1 ? "H" : "L") + " S2" + String(currentStateSensor2_1 ? "H" : "L");
// PREPARE THE STRINGS WITH THE REQUIRED FORMAT FOR ROTOR 2
String directionStr2 = rotationDirection2;
String line1_2 = padZero(absoluteRotations2 % 100, 2) + directionStr2 + padZero(abs(netCount2) % 100, 2);
String line2_2 = "S1" + String(currentStateSensor1_2 ? "H" : "L") + " S2" + String(currentStateSensor2_2 ? "H" : "L");
// CLEAR THE LCD AND PRINT THE LINES FOR ROTOR 1
lcd.clear();
lcd.setCursor(0, 0); // SET CURSOR FOR line1_1 TO THE BEGINNING OF THE FIRST ROW
lcd.print(line1_1);
lcd.setCursor(0, 1); // SET CURSOR FOR line2_1 TO THE BEGINNING OF THE SECOND ROW
lcd.print(line2_1);
// PRINT THE COUNTS FOR ROTOR 2 STARTING AT COLUMN 9
lcd.setCursor(9, 0); // SET CURSOR FOR line1_2 TO THE 9TH COLUMN OF THE FIRST ROW
lcd.print(line1_2);
lcd.setCursor(9, 1); // SET CURSOR FOR line2_2 TO THE 9TH COLUMN OF THE SECOND ROW
lcd.print(line2_2);
// PRINT TO SERIAL MONITOR FOR DEBUGGING
Serial.print("Rotor 1 - Absolute Rotations: ");
Serial.print(absoluteRotations1);
Serial.print(" Direction: ");
Serial.print(rotationDirection1);
Serial.print(" Net Count: ");
Serial.print(netCount1);
Serial.print(" S1: ");
Serial.print(currentStateSensor1_1 ? "H" : "L");
Serial.print(" S2: ");
Serial.println(currentStateSensor2_1 ? "H" : "L");
Serial.print("Rotor 2 - Absolute Rotations: ");
Serial.print(absoluteRotations2);
Serial.print(" Direction: ");
Serial.print(rotationDirection2);
Serial.print(" Net Count: ");
Serial.print(netCount2);
Serial.print(" S1: ");
Serial.print(currentStateSensor1_2 ? "H" : "L");
Serial.print(" S2: ");
Serial.println(currentStateSensor2_2 ? "H" : "L");
}
void saveCountToEEPROM() {
// SAVE THE COUNTS TO EEPROM
EEPROM.write(0, netCount1 & 0xFF); // WRITE THE LOWER BYTE OF netCount1
EEPROM.write(1, (netCount1 >> 8) & 0xFF); // WRITE THE UPPER BYTE OF netCount1
EEPROM.write(2, netCount2 & 0xFF); // WRITE THE LOWER BYTE OF netCount2
EEPROM.write(3, (netCount2 >> 8) & 0xFF); // WRITE THE UPPER BYTE OF netCount2
}
Hope I can at least start with this. Sorry I used a sketch drawing I had already made to show someone. I hope its not so terrible that it won't suffice.
Thanks