-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDirectInteract.h
More file actions
61 lines (49 loc) · 1.37 KB
/
Copy pathDirectInteract.h
File metadata and controls
61 lines (49 loc) · 1.37 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
54
55
56
57
58
59
60
61
/*
*
* DirectInteract this is a helper class to direct interaction with a set of Arduino pins.
*
* @author Valeriy V Dmitriev aka valmat <ufabiz@gmail.com>
* @coauthor Nikolai Tikhonov aka Dragon_Knight <dubki4132@mail.ru>, https://vk.com/globalzone_edev
* @licenses MIT https://opensource.org/licenses/MIT
* @repo https://github.com/valmat/LedMatrix
*
*/
#pragma once
#include "DirectPin.h"
class DirectInteract
{
public:
DirectInteract(uint8_t dataPin, uint8_t clockPin, uint8_t csPin) :
_data(dataPin, OUTPUT),
_clock(clockPin, OUTPUT),
_cs(csPin, OUTPUT)
{}
// Simplified constructor. For hardware SPI.
DirectInteract(uint8_t csPin) :
_cs(csPin, OUTPUT)
{}
// Empty constructor
DirectInteract() {}
// Enable the line
void enable() const
{
_cs.off();
}
// Latch the data into chip
void latch() const
{
_cs.on();
}
void transfer(uint8_t data) const
{
_data.shiftOut(_clock, data);
}
private:
// A pin on the Arduino where data gets shifted out (DIN).
// Data is shifted out of this pin
DirectPin _data;
// The clock is signaled on this pin (CLK)
DirectPin _clock;
// This one is driven LOW for chip selection (CS)
DirectPin _cs;
};