Created
May 22, 2020 04:38
-
-
Save Satoshi-Hirazawa/44f2fcc0725989299a7fcbee52845174 to your computer and use it in GitHub Desktop.
Digital Potentiometer(AD5220) test for Arduino.
This file contains hidden or 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
#define UD 2 | |
#define Clock 3 | |
#define ledPin 13 | |
#define aInput 0 | |
int buttonState1 = 0; | |
int buttonState2 = 0; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(ledPin, OUTPUT); | |
pinMode(UD, OUTPUT); | |
pinMode(Clock, OUTPUT); | |
Serial.println("AD5220 Serian control."); | |
Serial.println("Send 'u' or 'd'"); | |
} | |
void loop(){ | |
if (Serial.available() > 0) { | |
int incomingByte = Serial.read(); | |
if (incomingByte == 'd') { | |
digitalWrite(ledPin, HIGH); | |
// for(int i=0; i<100; i++) | |
upVolume(); | |
Serial.println("==== DOWN ===="); | |
analogInPrint(); | |
} | |
else if (incomingByte == 'u') { | |
digitalWrite(ledPin, HIGH); | |
// for(int i=0; i<100; i++) | |
downVolume(); | |
Serial.println("===== UP ====="); | |
analogInPrint(); | |
} | |
} | |
delay(100); | |
digitalWrite(ledPin, LOW); | |
} | |
void analogInPrint(){ | |
int val = analogRead(aInput); | |
Serial.println(val); | |
} | |
void upVolume(){ | |
digitalWrite(Clock, HIGH); | |
digitalWrite(UD, HIGH); | |
digitalWrite(Clock, LOW); | |
} | |
void downVolume(){ | |
digitalWrite(Clock, HIGH); | |
digitalWrite(UD, LOW); | |
digitalWrite(Clock, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment