-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.h
More file actions
53 lines (43 loc) · 1.04 KB
/
Display.h
File metadata and controls
53 lines (43 loc) · 1.04 KB
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
47
48
49
50
51
52
53
#ifndef DISPLAY_H_
#define DISPLAY_H_
#include <Arduino.h>
#include <Wire.h>
template <typename T> unsigned int I2C_writeAnything (const T& value)
{
const byte * p = (const byte*) &value;
unsigned int i;
for (i = 0; i < sizeof value; i++)
Wire.write(*p++);
return i;
} // end of I2C_writeAnything
template <typename T> unsigned int I2C_readAnything(T& value)
{
byte * p = (byte*) &value;
unsigned int i;
for (i = 0; i < sizeof value; i++)
*p++ = Wire.read();
return i;
} // end of I2C_readAnything
class Display
{
private:
uint8_t _addr;
public:
Display(uint8_t addr){
_addr=addr;
}
bool begin(){
Wire.begin();
return true;
}
void write(int32_t value){
Wire.begintransmission(_addr);
I2C_writeAnything(value);
Wire.endTransmission();
}
void write(float value){
Wire.begintransmission(_addr);
I2C_writeAnything(value);
Wire.endTransmission();
}
}