Arduino timer with potentiometer

Hi i tried to set a time with the potentiometer of blinking the led.
I was successful to 32 sec but 33 and later not.
Here is the code :
/* Analog Read to LED


  • turns on and off a light emitting diode(LED) connected to digital
  • pin 13. The amount of time the LED will be on and off depends on
  • the value obtained by analogRead(). In the easiest case we connect
  • a potentiometer to analog pin 2.
  • Created 1 December 2005
  • copyleft 2005 DojoDave http://www.0j0.org
  • http://arduino.berlios.de

*/

int potPin = 2; // select the input pin for the potentiometer
int ledPin = 4; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}

void loop() {
val = analogRead(potPin)*32; // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
}

Sorry for my bad english I am from Serbia…
Thank you ! :slight_smile:

I was successful to 32 sec but 33 and later not.

int val = 0;       // variable to store the value coming from the sensor
...
Val = analogRead(potPin)*32;    // read the value from the sensor

What is the max value of an int? Could that be a problem?

:slight_smile:

(Have a look at Unsigned long type and use 32UL instead of 32 to force unsigned long calculation or cast the result of digitalRead to an unsigned long value)

Can you please write me that code here I don't understand what to do..
I did this :

Val = analogRead(potPin)*32UL;
It wotking but 33 not.
Please help me I'am newbie in arduino.

The variable val must be defined as unsigned long

When you make changes to your program please post the complete new program so we can compare it with the earlier version.

…R

I was trying to have him understand his mistake and read some doc

Jovica did you read the links I sent? What is the max value of an int? Do you see why this is a pb? And why your code works up until a certain point and not after?

Thank you J-M-L and Robin I got it..
SOLVED