Hi guys! (Sorry for my English)
Been strugging for quite a while, to get my (Dont know exact English word) "Meter Wheel Counter" to work correctly.
Basically (I strongly advice you to check out the attached image for graphical explanation) my prototype must be able to measure the cable length going through a "block" (used in Marine equipment to support the cables bending). I guess in some way, you could compare the function of my prototype with a speed-o-meter found in cars.
So far my prototype is able to count up and down, depending if the "block" is rolling forward or backwards (= Scientific cable is being pulled in or out) - but my real problem is this:
I cannot get my display to show the correct meter/minute (= how fast the cable is being rolled in or out from cable-winch). I've tried tons of examples, but none are close to my solution, so I've excluded it from my code below.
I'm sure some of you pros can fix it super fast - and yes, I know my way of writing code can seem strange. I'm still learning .. Hope you also can live without comments in code (I've got my own comments in Danish, in another sketch)
Code:
//***********************************************************************************************
#include <SoftwareSerial.h>
#include <Streaming.h>
//***********************************************************************************************
int sensor1 = 2; // Magnetsensor 1 input
int sensor2 = 3; // Magnetsensor 2 input
float sensor_count = 0.00;
int sensor_last_value = LOW;
int n = HIGH;
float inner_cable_distance;
float display_cable_rollout;
#define txPin 7
#define rxPin 255
#define inverted 1 // Inverted serial (like RS-232, but TTL)
#define noninverted 0 // Noninverted serial (like UART output)
#define SPOL inverted
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin, SPOL);
#if SPOL
#define STOPBIT LOW // For inverted serial, the output pin must be LOW when data is not being sent; for noninverted, HIGH.
#else
#define STOPBIT HIGH
#endif
#define CLS (char) (0x0C)
#define MOVETO (char) 16
#define LABEL0 (char) (0x0C)
#define LABEL1 (char) (32+64)
#define LABEL2 (char) (48+64)
#define LABEL3 (char) (41+64)
#define LABEL4 (char) (16+64)
//***********************************************************************************************
void setup() {
delay(500) ;
digitalWrite(txPin, STOPBIT);
mySerial.begin(9600); // Set the communication data rate for the display.
mySerial.write(0x0C); // Clear screen
attachInterrupt(0, sensor_counter, CHANGE);
attachInterrupt(1, sensor_counter, CHANGE);
mySerial.write(0x0C);
mySerial <<MOVETO <<LABEL0 <<"Magnetdist. 65cm"; //trying out serial text Streaming.
mySerial <<MOVETO <<LABEL1 <<"Meter =";
mySerial <<MOVETO <<LABEL2 <<"M/min =";
}
//***********************************************************************************************
void sensor_counter ()
{
n = digitalRead(sensor1);
if ((sensor_last_value == HIGH) && (n == LOW))
{
if (digitalRead(sensor2) == LOW)
{
sensor_count = sensor_count + 1;
}
else
{
sensor_count = sensor_count - 1;
}
inner_cable_distance = sensor_count * 0.65;
display_cable_rollout = inner_cable_distance;
}
sensor_last_value = n;
}
//***********************************************************************************************
void loop()
{
mySerial.write(16); // Experimenting with alternative to serial Streaming
mySerial.write(45+64);
mySerial.write(0x12);
mySerial.write(0x35);
mySerial.print(display_cable_rollout);
}
//***********************************************************************************************