diff options
Diffstat (limited to 'linz/oekofen_thermo/src/MCP42010.cpp')
| -rw-r--r-- | linz/oekofen_thermo/src/MCP42010.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/linz/oekofen_thermo/src/MCP42010.cpp b/linz/oekofen_thermo/src/MCP42010.cpp new file mode 100644 index 0000000..aa6de2b --- /dev/null +++ b/linz/oekofen_thermo/src/MCP42010.cpp | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include "MCP42010.h" | ||
| 2 | |||
| 3 | MCP42010::MCP42010(uint8_t ss_pin) | ||
| 4 | : _ss_pin(ss_pin), _spiset(10000000, MSBFIRST, SPI_MODE0) | ||
| 5 | {} | ||
| 6 | |||
| 7 | void MCP42010::setup() | ||
| 8 | { | ||
| 9 | pinMode(_ss_pin, OUTPUT); | ||
| 10 | SPI.begin(); | ||
| 11 | } | ||
| 12 | |||
| 13 | void MCP42010::setPot(MCP42010::Poti pot, uint8_t value) | ||
| 14 | { | ||
| 15 | SPI.beginTransaction(_spiset); | ||
| 16 | digitalWrite(_ss_pin, LOW); | ||
| 17 | SPI.transfer(0b00010000 | pot); | ||
| 18 | SPI.transfer(value); | ||
| 19 | digitalWrite(_ss_pin, HIGH); | ||
| 20 | SPI.endTransaction(); | ||
| 21 | } | ||
