Skip to content

Instantly share code, notes, and snippets.

@rooty
Created February 3, 2013 00:07
Show Gist options
  • Save rooty/4699847 to your computer and use it in GitHub Desktop.
Save rooty/4699847 to your computer and use it in GitHub Desktop.
/*
Подключение AT2424C15 по I2C
*/
#define ADDR 0x50
void setup() {
Wire.begin();
Serial.begin(38400);
randomSeed(analogRead(0));
}
void readByte(unsigned int addr) {
Wire.beginTransmission(ADDR);
Wire.send( (byte) addr >> 8 );
Wire.send( (byte) addr & 0xff );
Wire.endTransmission();
Wire.requestFrom(ADDR, 1);
}
void writeByte(unsigned int addr, byte b) {
Wire.beginTransmission(ADDR);
Wire.send( (byte) addr >> 8 );
Wire.send( (byte) addr & 0xff );
Wire.send ( b );
Wire.endTransmission();
}
void loop() {
if (Wire.available()) {
Serial.println(Wire.receive(),HEX);
}
int cmd = Serial.read();
if (cmd != -1) {
if (cmd == 'R') {
readByte(0);
}
if (cmd == 'W') {
long b = random(0,255);
writeByte(0,b);
Serial.println(b,HEX);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment