03-09-2015, 11:17 AM
(03-09-2015, 10:52 AM)chucketn Wrote: I get a compile error adding that bit of code...
Chuck
The recommendation was "to add the highlighted line of code to the original program", not "this is the entire program". Sorry about the confusion.
This would be the original program with the line added ...
//Simple Digital Calliper Reader
//See http://j44industries.blogspot.com/
// Pin Declarations
int dataIn = 11;
int clockIn = 12;
// Variables
int clock = 1;
int lastClock = 1;
unsigned long time = 0;
unsigned long timeStart = 0;
int out = 0;
void setup() {
// Pin Set Up
pinMode(dataIn, INPUT);
pinMode(clockIn, INPUT);
Serial.begin(115200);
Serial.println("Ready: ");
}
void loop(){
lastClock = clock;
clock = digitalRead(clockIn);
if (lastClock == 1 && clock == 0){
out = digitalRead(dataIn)+digitalRead(dataIn)+digitalRead(dataIn); // Tripple sampling to remove glitches
Serial.println(micros());
if((micros() - time) > 800){
Serial.println(" ");
}
else if((micros() - time) > 400){
Serial.print(" ");
}
if (out > 1){
Serial.print("1");
}
else{
Serial.print("0");
}
Serial.print(",");
time = micros();
}
}
Give it another try and see what comes happens.
And I do agree with your assessment of the existing "level converter" as even the author of the instructable says "it is a bit of a bodge". I would not think that it would be a good long term solution ... may not even be a short term solution, depending on the individual IC that is being used ... and would seem to be very susceptible to noise in all cases.