-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdigipot.cpp
More file actions
31 lines (24 loc) · 790 Bytes
/
digipot.cpp
File metadata and controls
31 lines (24 loc) · 790 Bytes
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
#include <SPI.h>
#include "pins.h"
#include "digipot.h"
#define DIGIPOT_CHANNELS {4,5,3,0,1}
inline void digipot::write(byte address, byte value) // From Arduino DigitalPotControl example
{
digitalWrite(DIGIPOTSS_PIN,LOW); // take the SS pin low to select the chip
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(DIGIPOTSS_PIN,HIGH); // take the SS pin high to de-select the chip:
}
inline void digipot::setVoltage(byte driver, byte current)
{
byte digipot_ch[] = DIGIPOT_CHANNELS;
write(digipot_ch[driver], current);
}
void digipot::init() //Initialize Digipot Motor Current
{
const byte digipot_motor_current[] = {135,135,135,135,135};
SPI.begin();
pinMode(DIGIPOTSS_PIN, OUTPUT);
for(byte i=0; i<=4; i++)
setVoltage(i,digipot_motor_current[i]);
}