Hello, I hope you're fine.

My name is Jérôme, I'm a complete beginner with Arduino programmation.

I've already posted my question in the french forum, but nobody seems to be able to help me.

Here is my problem :

I have an analog input (IN1) which receive different voltages from pushbuttons.

The value of IN1 (val_IN1) is "analysed" and is converted to the value of bf1 from 0 to 7.

When no button is pressed, the value of bf1 is 0.

The value of the variable f1 memorize the value of bf1.

Here is the expected behaviour : if bf1 == 1, f1 = 1, if bf1 == 2, f1 = 2, if bf1 == 2 again, f1 = 0.

Basically, I want to toggle the value of f1 depending on the value of bf1.

My problem is the value of f1 does a loop between 0 and the value of bf1 as you can see here :

I would like to be able to use the rising edge of the variable bf1, is it possible ?

Here is the code :

```
const int IN1 = A5;
int val_IN1 = 0;
int bf1 = 0;
int f1 = 0;
int f1_prec = 0;
long time = 0; // the last time the output pin was toggled
long debounce = 200;// the debounce time, increase if the output flickers
void setup()
{
Serial.begin(9600);
pinMode(IN1, INPUT);
}
void loop()
{
int sensorValue = analogRead(IN1);
float volt = sensorValue * (5.0 / 1023.0);
float val = sensorValue;
Serial.println(f1);
val_IN1 = analogRead(IN1);
if (val_IN1 > 950 && millis() - time > debounce) {bf1 = 1;}
if (val_IN1 > 750 && val_IN1 < 850 && millis() - time > debounce) {bf1 = 2;}
if (val_IN1 > 570 && val_IN1 < 670 && millis() - time > debounce) {bf1 = 3;}
if (val_IN1 > 430 && val_IN1 < 530 && millis() - time > debounce) {bf1 = 4;}
if (val_IN1 > 310 && val_IN1 < 410 && millis() - time > debounce) {bf1 = 5;}
if (val_IN1 > 200 && val_IN1 < 300 && millis() - time > debounce) {bf1 = 6;}
if (val_IN1 > 80 && val_IN1 < 180 && millis() - time > debounce) {bf1 = 7;}
if (val_IN1 < 50 && millis() - time > debounce) {bf1 = 0;}
if (bf1 == 1) {f1 = 1;} if (bf1 == 1 && f1_prec == 1) {f1 = 0;}
if (bf1 == 2) {f1 = 2;} if (bf1 == 2 && f1_prec == 2) {f1 = 0;}
if (bf1 == 3) {f1 = 3;} if (bf1 == 3 && f1_prec == 3) {f1 = 0;}
if (bf1 == 4) {f1 = 4;} if (bf1 == 4 && f1_prec == 4) {f1 = 0;}
if (bf1 == 5) {f1 = 5;} if (bf1 == 5 && f1_prec == 5) {f1 = 0;}
if (bf1 == 6) {f1 = 6;} if (bf1 == 6 && f1_prec == 6) {f1 = 0;}
if (bf1 == 7) {f1 = 7;} if (bf1 == 7 && f1_prec == 7) {f1 = 0;}
if (f1 == 0){f1_prec = 0;}
if (f1 == 1){f1_prec = 1;}
if (f1 == 2){f1_prec = 2;}
if (f1 == 3){f1_prec = 3;}
if (f1 == 4){f1_prec = 4;}
if (f1 == 5){f1_prec = 5;}
if (f1 == 6){f1_prec = 6;}
if (f1 == 7){f1_prec = 7;}
}
```

Thank you very much in advance for you help and have a wonderfull day !

Jérôme.