Here is the code so far.
const int sensorMin = 23; // sensor minimum, discovered through experiment
const int sensorMax = 1000; // sensor maximum, discovered through experiment
const int ledPin = 9; // VOL UP connected to digital pin 9 through 4016
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of 17 options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 16);
// do something different depending on the
// range value:
switch (range) {
case 0: // Pot turned full anticlock wise
Serial.println("Minimum Volume Level 0");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 1: // 0.6 approx of a turn
Serial.println("Volume Level 1");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 2: // 1.2 approx turns
Serial.println("Volume Level 2");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 3: // 1.8 approx turns
Serial.println("Volume Level 3");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 4: // 2.4 approx turns
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
Serial.println("Volume Level 4");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 5: // 3 approx turns
Serial.println("Volume Level 5");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 6: // 3.6 approx turns
Serial.println("Volume Level 6");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 7: // 4.2 approx turns
Serial.println("Volume Level 7");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 8: // 4.8 approx turns
Serial.println("Volume Level 8");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 9: // 5.4 approx turns
Serial.println("Volume Level 9");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 10: // 6 approx turns
Serial.println("Volume Level 10");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 11: // 6.6 approx turns
Serial.println("Volume Level 11");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 12: // 7.2 approx turns
Serial.println("Volume Level 12");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 13: // 7.8 approx turns
Serial.println("Volume Level 13");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 14: // 8.4 approx turns
Serial.println("Volume Level 14");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 15: // 9 approx turns
Serial.println("Volume Level 15");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
case 16: // 9.6 approx turns (fully turned clockwise)
Serial.println("Max Volume Level 16");
digitalWrite(9, HIGH); // set the VOL UP on
digitalWrite(9, LOW); // set the VOL UP off
break;
}
}
Not sure if i have gone about this in the right way but would appreciate any comments to getting this working!
I havent yet entered the code for the vol down switch and the code for vol up doesnt seem to work either.
Thanks