)
+++++++++CALIPER DATA INTERFACE++++++++
-----FOOT SWITCH USED TO CAPTURE SINGLE MEASUREMENTS--------
-----LM339 VOLTAGE COMPARATOR FOR ACCURATE TTL---------------
-----CALIPER REGULATED VOLTAGE----------------------------------------
-----NO WEIRD LIBRARIES OR IDE'S TO DOWNLOAD----------------------
-----ALL FUNCTIONS ARE 100% VERIFIED----------------------------------
-----COMPLETE CODE AND SCHEMATIC ARE BELOW---------------------
** Schematic at: Schematic 05212013 Rev B1 | CALIPER DATA INTERFACE supertech… | Flickr**
======= HERE THEY ARE!!! ===========
(Cleaned up and Modified/Tested 05-27-2013)
/*
Caliper Data Output: Updated 05/27/2013
Code and Circuit Compiled by: J. Poston
Special Thanks To:
Forrest M. Mimms III Engineer's Notebook 1st Edition (pg 106)
David Cook's Website on Caliper Data
http://www.robotroom.com/Caliper-Digital-Data-Port-2.html
Rob Tillaart for code cleanup and insight (from the Arduino Forum)
*/
int dataIn = 4;
int clockIn = 2;
const int buttonPin = 5;
int buttonState =0;
const int i=10;
int isin=0;
int isfs=0;
int index;
unsigned long xData,oData;
long previousMillis = 0;
long interval = 500;
long previousGetMillis = 0;
long Timeout = 8;
void setup()
{
pinMode(buttonPin, INPUT);
digitalWrite(dataIn, 1);
digitalWrite( clockIn, 1);
pinMode(dataIn, INPUT);
Serial.begin(9600);
delay(500);
attachInterrupt(0,getBit,RISING);
index =0;
xData=0;
oData=999;
Print_Header();
}
void loop()
{
buttonState = digitalRead(buttonPin);
delay(5);
if (buttonState == HIGH) {
if ((index !=0) && (millis() - previousGetMillis > Timeout) ) {
index=0;
xData=0;
};
if (index >23) {
if (oData !=xData) {
if (isin == 1) //Inches
{
float val = xData * 0.5 /1000;
if (isfs == 1)
{val = -val; }
Serial.println(val, 4);}
else // mm
{ float val = xData / 100.0;
if (isfs == 1)
{val = -val;}
Serial.println(val, 2);
}}
oData =xData;
index=0;
delay(5);
xData=0;
}
if (millis() - previousMillis > interval) {
previousMillis = millis();
}}}
void getBit(){
previousGetMillis=millis();
if(index < 20){
if(digitalRead(dataIn)==1){
xData|= 1<<index;
}}
else {
if (index==20)
isfs=digitalRead(dataIn);
if (index==23)
isin=digitalRead(dataIn);
};
index++;
}
void Print_Header()
{ Serial.println("****************************************************************");
Serial.println(" Program: Digital Caliper Data SPC (Running) ");
Serial.println("****************************************************************");
}