code init
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include <AT24C32.h>
|
||||
|
||||
void AT24C32::begin()
|
||||
{
|
||||
Wire.begin();
|
||||
};
|
||||
|
||||
uint8_t AT24C32::read(int address)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
bool read = true;
|
||||
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
|
||||
if (Wire.endTransmission() == 0)
|
||||
{
|
||||
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
|
||||
Wire.write(address >> 8);
|
||||
Wire.write(address & 0xff);
|
||||
if (Wire.endTransmission() == 0)
|
||||
{
|
||||
Wire.requestFrom(AT24C32_I2C_ADDRESS, 1);
|
||||
while (Wire.available() > 0 && read)
|
||||
{
|
||||
result = Wire.read();
|
||||
read = false;
|
||||
}
|
||||
|
||||
Wire.endTransmission();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AT24C32::write(int address, uint8_t data)
|
||||
{
|
||||
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
|
||||
if (Wire.endTransmission() == 0)
|
||||
{
|
||||
Wire.beginTransmission(AT24C32_I2C_ADDRESS);
|
||||
Wire.write(address >> 8);
|
||||
Wire.write(address & 0xff);
|
||||
Wire.write(data);
|
||||
Wire.endTransmission();
|
||||
delay(20);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef AT24C32_h
|
||||
#define AT24C32_h
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class AT24C32
|
||||
{
|
||||
public:
|
||||
void begin();
|
||||
uint8_t read(int address);
|
||||
void write(int address, uint8_t data);
|
||||
};
|
||||
|
||||
// I2C address
|
||||
#define AT24C32_I2C_ADDRESS 0x57
|
||||
|
||||
#define BRIGHTNESS_ADDRESS 0x0A00
|
||||
|
||||
#define COLOR_ADDRESS 0x0A01
|
||||
|
||||
#define VIEW_STATE_ADDRESS 0x0A02
|
||||
|
||||
#define TIME_MODE_ADDRESS 0x0A03
|
||||
|
||||
#define TEXT_SIZE_ADDRESS 0x0B00
|
||||
#define TEXT_ADDRESS 0x0B01
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user