2013-02-12 11:34:56 +01:00
|
|
|
int potent = -1;
|
|
|
|
int tolerance = 4;
|
|
|
|
|
|
|
|
const int s0 = 10;
|
|
|
|
const int s1 = 9;
|
|
|
|
const int s2 = 8;
|
|
|
|
|
|
|
|
int pots[] = {-1,-1};
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
pinMode(s0,OUTPUT);
|
|
|
|
pinMode(s1,OUTPUT);
|
|
|
|
pinMode(s2,OUTPUT);
|
2013-02-12 11:48:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
//get Y0 of 4051
|
|
|
|
digitalWrite(s0, LOW);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
int read = analogRead(A1);
|
|
|
|
//only print value on change (tolerance of 4 out of 1024)
|
|
|
|
if (pots[0] < read - tolerance || pots[0] > read + tolerance) {
|
|
|
|
pots[0] = read;
|
|
|
|
Serial.print("pot 0: ");
|
|
|
|
Serial.print(pots[0]/8);
|
|
|
|
Serial.println();
|
|
|
|
}
|
2013-02-12 11:34:56 +01:00
|
|
|
|
2013-02-12 11:48:47 +01:00
|
|
|
//get Y1 of 4051
|
|
|
|
digitalWrite(s0, HIGH);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
read = analogRead(A1);
|
|
|
|
if (pots[1] < read - tolerance || pots[1] > read + tolerance) {
|
|
|
|
pots[1] = read;
|
|
|
|
Serial.print("pot 1: ");
|
|
|
|
Serial.print(pots[1]/8);
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
}int potent = -1;
|
|
|
|
int tolerance = 4;
|
|
|
|
|
|
|
|
const int s0 = 10;
|
|
|
|
const int s1 = 9;
|
|
|
|
const int s2 = 8;
|
|
|
|
|
|
|
|
int pots[] = {-1,-1};
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
pinMode(s0,OUTPUT);
|
|
|
|
pinMode(s1,OUTPUT);
|
|
|
|
pinMode(s2,OUTPUT);
|
2013-02-12 11:34:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2013-02-12 11:48:47 +01:00
|
|
|
//get Y0 of 4051
|
2013-02-12 11:34:56 +01:00
|
|
|
digitalWrite(s0, LOW);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
int read = analogRead(A1);
|
2013-02-12 11:48:47 +01:00
|
|
|
//only print value on change (tolerance of 4 out of 1024)
|
2013-02-12 11:34:56 +01:00
|
|
|
if (pots[0] < read - tolerance || pots[0] > read + tolerance) {
|
2013-02-12 11:48:47 +01:00
|
|
|
pots[0] = read;
|
2013-02-12 11:34:56 +01:00
|
|
|
Serial.print("pot 0: ");
|
2013-02-12 11:51:05 +01:00
|
|
|
//print value between 0 & 127 like MIDI velocity ;)
|
2013-02-12 11:34:56 +01:00
|
|
|
Serial.print(pots[0]/8);
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
2013-02-12 11:51:05 +01:00
|
|
|
//get Y1 of 4051, analog to Y0
|
2013-02-12 11:34:56 +01:00
|
|
|
digitalWrite(s0, HIGH);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
digitalWrite(s1, LOW);
|
|
|
|
read = analogRead(A1);
|
|
|
|
if (pots[1] < read - tolerance || pots[1] > read + tolerance) {
|
2013-02-12 11:48:47 +01:00
|
|
|
pots[1] = read;
|
2013-02-12 11:34:56 +01:00
|
|
|
Serial.print("pot 1: ");
|
|
|
|
Serial.print(pots[1]/8);
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
}
|