From 457b147001875d2c440b5e6b120d97c8d7e9320f Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Feb 2013 11:48:47 +0100 Subject: [PATCH] 4051 test sketch --- sketches/testing/_4051_test.ino | 47 +++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/sketches/testing/_4051_test.ino b/sketches/testing/_4051_test.ino index a64cb46..789468d 100644 --- a/sketches/testing/_4051_test.ino +++ b/sketches/testing/_4051_test.ino @@ -12,27 +12,70 @@ void setup() { pinMode(s0,OUTPUT); pinMode(s1,OUTPUT); pinMode(s2,OUTPUT); +} + +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(); + } + //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); } 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] = analogRead(A1); + pots[0] = read; Serial.print("pot 0: "); Serial.print(pots[0]/8); Serial.println(); } + //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] = analogRead(A1); + pots[1] = read; Serial.print("pot 1: "); Serial.print(pots[1]/8); Serial.println();