-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMemory.cpp
46 lines (33 loc) · 870 Bytes
/
Memory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Arduino.h"
#include "Memory.h"
Memory::Memory(uint8_t i2c_address)
{
this->i2c_address = i2c_address;
}
void Memory::init()
{
}
uint8_t Memory::read(uint16_t memory_address)
{
uint8_t results = 0;
// Send the memory address
Wire.beginTransmission(this->i2c_address);
Wire.write(highByte(memory_address));
Wire.write(lowByte(memory_address));
Wire.endTransmission();
// Request 1 byte
Wire.requestFrom(this->i2c_address, (uint8_t) 1);
// Read from the memory address
if(Wire.available()) results = Wire.read();
return(results);
}
void Memory::write(uint16_t memory_address, uint8_t value)
{
Wire.beginTransmission(this->i2c_address);
// Send the memory address
Wire.write(highByte(memory_address));
Wire.write(lowByte(memory_address));
// Send the value to write
Wire.write(value);
Wire.endTransmission();
}