Created
February 3, 2013 00:07
-
-
Save rooty/4699847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Подключение 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