Skip to content

Instantly share code, notes, and snippets.

@sixtyfive
Last active October 16, 2019 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixtyfive/040a80efed06bba2610c5c19a5de6e7f to your computer and use it in GitHub Desktop.
Save sixtyfive/040a80efed06bba2610c5c19a5de6e7f to your computer and use it in GitHub Desktop.
#include <SPI.h>
#define PIN_LED GPIO_NUM_4
#define PIN_VREF GPIO_NUM_25
#define PIN_MOSI GPIO_NUM_23
#define PIN_CLOCK GPIO_NUM_18
#define PIN_GAIN_EN GPIO_NUM_12
#define PIN_OFFSET_EN GPIO_NUM_14
void StartSPI()
{
pinMode(PIN_GAIN_EN, OUTPUT);
digitalWrite(PIN_GAIN_EN, HIGH);
pinMode(PIN_OFFSET_EN, OUTPUT);
digitalWrite(PIN_OFFSET_EN, HIGH);
SPI.begin();
}
int resistance = 0;
void SetPotiResistance()
{
if (resistance == 255) {
resistance = 0;
} else {
resistance += 1;
}
Serial.print("Setting gain poti to ");
Serial.print(resistance);
digitalWrite(PIN_GAIN_EN, LOW);
delay(100);
int retval = SPI.transfer(resistance);
delay(100);
digitalWrite(PIN_GAIN_EN, HIGH);
Serial.print(" ... done (");
Serial.print(retval);
Serial.println(").");
delay(1000);
}
void setup()
{
Serial.begin(115200);
StartSPI();
}
void loop()
{
SetPotiResistance();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment