How to use a digital potenciometer with Arduino (MCP 4131-103)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* How to use a digital potenciometer with Arduino | |
* Link to article: https://www.gsampallo.com/?p=952 | |
*/ | |
#include <SPI.h> | |
byte address = 0x00; | |
int CS = 10; | |
void setup() { | |
pinMode (CS, OUTPUT); | |
SPI.begin(); | |
} | |
void loop() { | |
for (int i = 0; i <= 128; i++) { | |
digitalPotWrite(i); | |
delay(10); | |
} | |
delay(500); | |
for (int i = 128; i >= 0; i--) { | |
digitalPotWrite(i); | |
delay(10); | |
} | |
} | |
int digitalPotWrite(int value) { | |
digitalWrite(CS, LOW); | |
SPI.transfer(address); | |
SPI.transfer(value); | |
digitalWrite(CS, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment