#include <OneWire.h> #define pin 2 OneWire ibutton (pin); byte addr[8]; int writeByte(byte data){ int data_bit; for(data_bit=0; data_bit<8; data_bit++){ if (data & 1){ digitalWrite(pin, LOW); pinMode(pin, OUTPUT); delayMicroseconds(60); pinMode(pin, INPUT); digitalWrite(pin, HIGH); delay(10); } else { digitalWrite(pin, LOW); pinMode(pin, OUTPUT); pinMode(pin, INPUT); digitalWrite(pin, HIGH); delay(10); } data = data >> 1; } return 0; } void setup() { Serial.begin(9600); } void loop() { if ( !ibutton.search(addr) ) { return; } ibutton.skip(); ibutton.reset(); ibutton.write(0x33); ibutton.skip(); ibutton.reset(); ibutton.write(0xD1); digitalWrite(pin, LOW); pinMode(pin, OUTPUT); delayMicroseconds(60); pinMode(pin, INPUT); digitalWrite(pin, HIGH); delay(10); byte newID[8] = {0x44, 0x0F, 0xC8, 0x0B, 0x00, 0x00, 0x00, 0x2C}; newID[0] = 1; newID[1] = 1; newID[2] = 1; newID[3] = 1; newID[4] = 1; newID[5] = 1; newID[6] = 1; newID[7] = 1; Serial.println(); ibutton.skip(); ibutton.reset(); ibutton.write(0xD5); for (byte x = 0; x<8; x++){ writeByte(newID[x]); Serial.print("*"); } ibutton.reset(); ibutton.write(0xD1); digitalWrite(pin, LOW); pinMode(pin, OUTPUT); delayMicroseconds(10); pinMode(pin, INPUT); digitalWrite(pin, HIGH); delay(10); Serial.print(" "); ibutton.skip();ibutton.reset();ibutton.write(0x33); Serial.print("Code recorded:"); for (byte x=0; x<8; x++){ Serial.print(" "); Serial.print(ibutton.read()); } Serial.println(" ok"); delay(2000); }
Открыть пример: Online ArduBlock
#include <OneWire.h> int x = 0; long NaN = 0; #define pin 2 OneWire ibutton (pin); byte addr[8]; int writeByte(byte data){ int data_bit; for(data_bit=0; data_bit<8; data_bit++){ if (data & 1){ digitalWrite(pin, LOW); pinMode(pin, OUTPUT); delayMicroseconds(60); pinMode(pin, INPUT); digitalWrite(pin, HIGH); delay(10); } else { digitalWrite(pin, LOW); pinMode(pin, OUTPUT); pinMode(pin, INPUT); digitalWrite(pin, HIGH); delay(10); } data = data >> 1; } return 0; } void setup() { Serial.begin(9600); } void loop() { if ( !ibutton.search(addr) ) { return; } ibutton.skip(); x = addr[0]; NaN = addr[1]; NaN = addr[2]; NaN = addr[3]; NaN = addr[4]; NaN = addr[5]; NaN = addr[6]; NaN = addr[7]; Serial.println(x); if (x == 1) { pinMode(13, OUTPUT); digitalWrite(13, 1); delay(3000); pinMode(13, OUTPUT); digitalWrite(13, 0); delay(100); } }
Открыть пример: Online ArduBlock
Видеоурок: