//Salman Taş 20191701044
#define led 9
int delaytime (int x){ //calculate the delay time
int time = 30 - 5*x;
time *= 100; // bring values back to ms || you can reduce this to 10 to see more cleary
return time;
}
void blink (int x){ //blink the led accordingly
digitalWrite(led, HIGH);
delay(x);
digitalWrite(led, LOW);
delay(x);
}
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(A0, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
long int a_in = analogRead(A0); // read the analog input
float V = a_in * (5.0 / 1023.0); //clip it between 0-5
int Voltage = int(V); //convert it into int
int time = delaytime(Voltage); //get the delay time
blink(time); //call blink function
}