Hello everyone!
I am carrying out a project that includes three buttons, which turn on three LEDs and activate 2 potentiometers and 2 soft potentiometers.
I'm having problems reading the soft potentiometer values, I would like the serial port to print the last value I touched on the soft potentiomter, while when I lift my finger the serial port reads the lowest value of the range, such as 1 .
These values of the soft potentiometer will then be read also on Max msp.
I attach the code below. (I only write the code related to the activation button of the led and the soft potentiometer).
bool lastValue3; // white button
bool toggleStatus3 = false;
bool digitalValueConfirmed3 = false;
unsigned longtimePast3 = 0;
const byte whitebutton = 7;
const byte ledBianco = 10;
const byte analogPin3 = A2; // softpot
const byte analogPin4 = A1; // potentiometer
int currentValue;
void setup () {
pinMode (whitebutton, INPUT);
pinMode (ledBianco, OUTPUT);
Serial.begin (9600);
}
void loop () {
unsigned longtimeActual = millis ();
// debounce and toggle white button
if (digitalRead (whitebutton) == 1) {
timePast3 = timeActual;
digitalValueConfirmed3 = 1;
} else {
if (timeActual - timePast3> 50) // Has some time passed?
digitalValueConfirmed3 = 0;
}
if ((lastValue3 == 0) && (digitalValueConfirmed3 == 1)) {
toggleStatus3 =! toggleStatus3;
// so that I touch, I reverse the toggle
}
digitalWrite (ledBianco, toggleStatus3);
lastValue3 = digitalValueConfirmed3;
int val4 = analogRead (analogPin4);
int gran = map (val3, 0, 1023, 1, 100);
currentValue = map (val3, 0, 1024, 0, 1000);
int lastVal = map (currentValue, 0, 1000, 0, 50);
int gran2 = map (val4, 0, 1023, 0, 50);
if ((toggleStatus3 == HIGH) and (currentValue != gran)) {
Serial.print ("gran1");
Serial.println (lastVal);
Serial.print ("gran2");
Serial.println (gran2);
}
}
}