Habe nun meine 4 IButtons ausgelesen
Das Programm läuft jetzt. Ich bearbeite es noch einmal und lade den Code später hoch.
#include <OneWire.h>
OneWire ibutton (2); // I button connected on PIN 2.
const byte SCHLUESSEL = 4; // Anzahl der gültigen Schlüssel
byte ibuttonid[SCHLUESSEL][10] = {{1,192,11,324,83,0,0,531}, {1,189,210,6,24,0,0,203}, {1,245,64,003,24,0,0,170}, {}};
//byte ibuttonid[SCHLUESSEL][10] = {{1,192,11,324,83,0,0,531}, {1,189,210,6,24,0,0,203}, {1,245,64,003,24,0,0,170}, {1,66,218,141,23,0,0,177}};
byte buffer[10]; //array to store the readed Ibutton ID.
boolean result; // this variable will hold the compare result
void setup(){
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop(){
if (!ibutton.search (buffer)){//read attached ibutton and asign value to buffer
ibutton.reset_search();
delay(200);
return;
}
for (int x = 0; x<8; x++){
Serial.print(buffer[x],HEX); //print the buffer content in LSB. For MSB: for (int x = 8; x>0; x--)
Serial.print(" "); // print a space
}
Serial.println("\n"); // print new line
// compare the ibutton id
result = false;
for (int b = 0; b < SCHLUESSEL; b++) {
result = true;
int x = 0;
do {
int compare1 = ibuttonid[b][x];// asign each index of arrays to test, one by one and compare
int compare2 = buffer[x];
if (compare1 != compare2) { // if any index comparison is not equal, then the arrays are not equal and result will be 0.
result = false;
}
x++;
} while (result && (x < SCHLUESSEL));
if (result) {
b = SCHLUESSEL;
result = true;
}
}
// RICHTIGER IBUTTON
if (result == true) { // if the arrays are equal, do something.
Serial.println("Tueroeffner ansteuern");
digitalWrite(13,HIGH); // Turn on LED on pin 13
digitalWrite(11,HIGH); // Turn on LED on pin 13
delay(5000); // wait five seconds. (1 second = 1000 milliseconds)
Serial.println("Tueroeffner ausschalten");
Serial.println("\n"); // print new line
digitalWrite(13,LOW); // turn off LED.
digitalWrite(11,LOW); // turn off LED.
}
// FALSCHER IBUTTON
if (result == false) { // if the arrays are equal, do something.
Serial.println("Falscher IButton");
for (int i=0; i<16; i++){
digitalWrite(12,HIGH);
delay(50); // wait seconds. (1 second = 1000 milliseconds)
digitalWrite(12,LOW);
delay(50);
}
Serial.println("Roter LED Flash beendet!");
Serial.println("\n"); // print new line
digitalWrite(12,LOW); // turn off LED.
}
//set buffer back to cero.
for (int x=0; x<10; x++){
buffer[x] = 0 ;
}
}
/* by Elimeléc
Jun-07-2013
*/
Vielen vielen Dank
Alex