Az esztergámhoz szeretnék digitális kijelzőt csinálni Arduino Uno-val.
Idáig ott artok, hogy ki tudom írni egy tolómérő jeleit LCD-re. Itt meg állt a tudományom. A program magját a neten találtam.
Itt:https://sites.google.com/site/marthalpr ... al-caliper
Kód: Egész kijelölése
int i;
int sign;
long value;
float result;
int clockpin = 4;
int datapin = 5;
unsigned long tempmicros;
void setup() {
Serial.begin(9600);
pinMode(clockpin, INPUT);
pinMode(datapin, INPUT);
}
void loop () {
while (digitalRead(clockpin)==HIGH) {} //if clock is LOW wait until it turns to HIGH
tempmicros=micros();
while (digitalRead(clockpin)==LOW) {} //wait for the end of the HIGH pulse
if ((micros()-tempmicros)>500) { //if the HIGH pulse was longer than 500 micros we are at the start of a new bit sequence
decode(); //decode the bit sequence
}
}
void decode() {
sign=1;
value=0;
for (i=0;i<23;i++) {
while (digitalRead(clockpin)==HIGH) { } //wait until clock returns to HIGH- the first bit is not needed
while (digitalRead(clockpin)==LOW) {} //wait until clock returns to LOW
if (digitalRead(datapin)==LOW) {
if (i<20) {
value|= 1<<i;
}
if (i==20) {
sign=-1;
}
}
}
result=(value*sign)/100.00;
Serial.println(result,2); //print result with 2 decimals
delay(1000);
}Az egyik próba két tolómérőre:
Kód: Egész kijelölése
int i;
int n;
int sign;
int sign1;
long value;
long value1;
float result;
float result1;
int clockpin = 2;
int datapin = 3;
int clockpin1 = 4;
int datapin1 = 5;
unsigned long tempmicros;
void setup() {
Serial.begin(9600);
pinMode(clockpin, INPUT);
pinMode(datapin, INPUT);
pinMode(clockpin1, INPUT);
pinMode(datapin1, INPUT);
}
void loop () {
while (digitalRead(clockpin)==HIGH) {} //if clock is LOW wait until it turns to HIGH
tempmicros=micros();
while (digitalRead(clockpin)==LOW) {} //wait for the end of the HIGH pulse
if ((micros()-tempmicros)>500) { //if the HIGH pulse was longer than 500 micros we are at the start of a new bit sequence
}
while (digitalRead(clockpin1)==HIGH) {} //if clock is LOW wait until it turns to HIGH
tempmicros=micros();
while (digitalRead(clockpin1)==LOW) {} //wait for the end of the HIGH pulse
if ((micros()-tempmicros)>500) { //if the HIGH pulse was longer than 500 micros we are at the start of a new bit sequence
decode(); //decode the bit sequence
}
}
void decode() {
sign=1;
value=0;
for (i=0;i<23;i++) {
while (digitalRead(clockpin)==HIGH) { } //wait until clock returns to HIGH- the first bit is not needed
while (digitalRead(clockpin)==LOW) {} //wait until clock returns to LOW
if (digitalRead(datapin)==LOW) {
if (i<20) {
value|= 1<<i;
}
if (i==20) {
sign=-1;
}
}
}
sign1=1;
value1=0;
for (n=0;n<23;n++) {
while (digitalRead(clockpin1)==HIGH) { } //wait until clock returns to HIGH- the first bit is not needed
while (digitalRead(clockpin1)==LOW) {} //wait until clock returns to LOW
if (digitalRead(datapin1)==LOW) {
if (i<20) {
value1|= 1<<n;
}
if (n==20) {
sign1=-1;
}
}
}
result=(value*sign)/100.00;
result1=(value1*sign1)/100.00;
Serial.print(result,2); //print result with 2 decimals
Serial.print(" ");
Serial.println(result1,2); //print result with 2 decimals
delay(100);
}
Tudna valaki segíteni abban, hogyan lehet ezt a részt úgy átalakítani, hogy 3 tolómérőt dekódoljon.
Előre is köszönöm.