Need help in my project...

I have written a code to display a value read from a potentiometer

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int potpin = 0;
int val;

void setup() {

lcd.begin(16, 2); // set up the LCD's number of columns and rows:

}

void loop() {
lcd.print("Pot Value");

lcd.setCursor(0, 1);
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 120); // prints number from 0 to 120

lcd.print(val); // prints the value read from the pot

delay(70);
lcd.clear();

}

Now what I want to do is I have connected an LED to PIN 9 and I want to control the blink of the LED with the same potentiometer...

Here the value which is printed on the LCD should be the seconds at which interval the led will blink like a heart beat pulse...

Please help me in doing this...

Well, you could load a counter with the current time and use an if statement, or that type of arrangement.. simplest way.

I am new to arduino...
So cannot make out how to write...
Will u plz write a code like an example...??

Will u plz write a code like an example...??

Do you want us to wipe your behind too? Why don't you try to learn how to do that on your own instead? Start on http://arduino.cc/en/Tutorial/HomePage and work through the tutorials until you understand them. It's no magic and it will teach you quite a lot of basics.

What you want to do is a very easy second program to implement and Focalist provided all necessary hints.

So please, show some initiative and use the available resources instead of asking to be spoon fed every little step.

Korman

I am new to arduino...
So cannot make out how to write...

Yet you wrote sketch to display the pot's mapped value on an LCD?

As Korman said, work through some examples, come to us when you are stuck, but don't expect us to write stuff for you.

have written this code...

so now I am able to blink the LED at a sequence of 200ms to 2000ms
and at the same time print the millisecond at which the led is blinking...

HERE IS THE CODE...I have checked ...Its working...

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int ledPin = 13;
int pot_Read;
int delay_in_ms;
int value = LOW;
long lastTime = 0;

void setup() {

lcd.begin(16, 2); // set up the LCD's number of columns and rows:
pinMode (ledPin, OUTPUT); // LED connected to pin 13
}

void loop()

{
lcd.setCursor(0, 0);
lcd.print("Pot Display");

{
lcd.setCursor(0, 1);

pot_Read=map(pot_Read, 0, 1023, 200, 2000);

lcd.print(pot_Read);

delay(100);
lcd.clear();
{

// while(1)
{

pot_Read=analogRead(0);
delay_in_ms=map(pot_Read, 0, 1023, 200, 2000); //Our pot will select from 200ms to 2000ms

if (millis() > lastTime + long(delay_in_ms))
{
if (value == LOW)
value = HIGH;
else
value = LOW;
digitalWrite(ledPin, value);
lastTime=millis();
}
}
}
}
}

In my program lets say if I set the pot to blink the LED at 1000ms rate what the LED does is it stays ON for 1000ms and then again stays OFF for 1000ms...THIS IS ALMOST LIKE A SQUARE WAVE PULSE

But now I want it to blink close to like a SAWTOOTH PULSE..
for example:- want to switch ON the LED for 5ms and then stay OFF for (time as set by the pot) say 1000ms...

How do I do it...??

Have a look at "analogWrite", but remember that it only works on certain pins.

well, in your timing routine, you could just have another if statement, if the difference between "now" and the beginning of the timing routine is equal to 5, then then switch off LED... just switch it on at the beginning of the delay.

Really this is awfully basic logic and programming.. you would really be doing yourself a favor to spend some time learning the language (Arduino). It's a simplified version of C, whose format and basic ideas carry forward into things like C++ and Java. The coding practices will carry forward. Consider Arduino to be C with training wheels.

I do not actually need a SAWTOOTH PULSE...

I want to blink the LED in this way...

void setup() {

pinMode(13, OUTPUT);
}

void loop() {
digitalWrite(13, HIGH);
delay(10);
digitalWrite(13, LOW);
delay(1000); // this is the time which I want to control with the pot...

analogWrite (13, map (analogRead (potPin), 0, 1023, 0, 255));

Will allow you to dim the LED with the pot.

I do not actually need a SAWTOOTH PULSE

But now I want it to blink close to like a SAWTOOTH PULSE..

Which?

This is how I want to flash the led...

I have attached a graph...

I want to keep the ON time of the LED constant...say 10milli second...
And want to control the OFF time of the LED with the POT

If you insist on using "delay", you could do it like this:

 digitalWrite(13, HIGH); 
 delay(10);             
 digitalWrite(13, LOW);   
 delay(map (analogRead (potPin), 0, 1023, 1, 1000)));

Still don't see where the sawtooth comes from.

I would assume that the person probably wants the LED to come on at full brightness, then fade out (aka,the sloped side of a sawtooth), wait a variable off delay, then repeat.

Sorry sorry...
I am sorry...

I DONT WANT SAWTOOTH...

THIS IS EXACT WHAT I WANT THE LED TO DO....

 digitalWrite(13, HIGH);
 delay(10);
 digitalWrite(13, LOW);
 delay(map (analogRead (potPin), 0, 1023, 1, 1000)));

But I cannot use this coz it has delay in it...
So it will blink the lCD too...

Have a look at the blink without delay example, it does almost exactly what you want.

yes I have seen that....

But how do I make the loop to set the ON time different from the OFF time...??

Like if I want to glow the LED for 35 millisecond and stay OFF for 1 second...??

Or I want to select the off time by a pot...??

IIRC the blink without delay (call to moderator: can we have that phrase as an editor macro?) uses the same value for the on and the off time.
So, just create another variable for the off time, and toggle between using that and the on time in your delay-less delay.