Arduino teaching service..

int led = 13;

void setup ()
{
pinMode (led,OUTPUT);
}
void loop ()
{
digitalWrite (led, HIGH);
delay (100);
digitalWrite (led,LOW);
delay (100);
}

can anyone Explain how to use counter (using example) on this sketch?
so that ..
led off counts from 1-5 times and
led then counts back from 5-1.
thank you

lordstark:
led off counts from 1-5 times and
led then counts back from 5-1.

Hi,
What do you mean by that?
Regards

thanks for replying

each time LED is off

1st time led off = count 1
2nd time led off = count 2
3rd time led off = count 3
4th time led off = count 4
5th time led off = count 5

after count reaches 5
then
each time led is off
1st time led off = count 5
2nd time led off = count 4
3rd time led off = count 3
4th time led off = count 2
5th time led off = count 1

after count reaches 1
then
each time LED is off

1st time led off = count 1
2nd time led off = count 2
3rd time led off = count 3
4th time led off = count 4
5th time led off = count 5

thank you

Hi,
It is simple counter = counter +1 (counter = counter - 1).
Regards.

thank you ..

how do i tell counter so that it only counts led off cycle?
kind regards

Hi,
The instruction (counter = counter - 1) has to be just after the "led OFF" one. Do not use counter = counter + 1.
What is the counter purpose?.
Regards.

You can use digitalRead(led) to determine if it's on or off.

But in your code, you know when the led is on or off, so you can simply put the count statement after the statement that switches the led off.

As you want to count up and then immediately back down you will probably want something like:

// when LED is off
count = count + x   // where x is either 1 or -1

if (count > 5) x = -1;

if (count < 1) x = 1;

There are neater ways of doing it but that makes it fairly obvious what is going on.

Steve

thank you for taking the time to reply..

just two quick question?

does "count" acts as a predefined arduino function like (pinMode or digitalRead)
and whats the diffence between count and (int i; i++)..are they counts the same..
thanks

count is a variable that you need to declare first. Above setup()

byte count;

lordstark:
thank you for taking the time to reply..

just two quick question?

does "count" acts as a predefined arduino function like (pinMode or digitalRead)
and whats the diffence between count and (int i; i++)..are they counts the same..
thanks

Before asking for further help I'd try to understand, at least, everyone of the lines of the "blink" program. (Understand means "fully" understand).
Regards.

"vffgaston"
thanks for your comment..

please help me to "fully understand" the problem instead of sending me somewhere else..
im stupid and have zero knowledge about programming.

Regards

lordstark:
please help me to "fully understand" the problem instead of sending me somewhere else..
im stupid and have zero knowledge about programming.

Hi,

Sorry if the post is a bit rude.
Programming is not an easy task. Maybe it is attracting and funny, but you need some basics to progress.
The forum is not a "teaching service" but a place where you ask for guidance.
If you actually have no idea on programming then the best is to say it from the very beginning ... Frankly it has been such a long time that I cannot recommend a basic programming book. sure there are many tutorials in the Internet: perhaps another forer can give you a better advice.

Regards.

lordstark:
does "count" acts as a predefined arduino function like (pinMode or digitalRead)
and whats the diffence between count and (int i; i++)..are they counts the same..
thanks

There is no basic function called count, to my knowledge. You make a counter by coding what's above, ie. i++, or i = i + 1, or i = i + variable and controlling it with something like if(condition is true) count up/dn. Substitute a minus sign to decrement.

As mentioned, *count * is just an arbitrary name (identifier) you give to a memory location whose value is incremented/decremented.

You need to be careful that the counter only counts when the stimulus *goes * true - or false if that's your fancy. If your code is such that counting happens *when * the input is true it will count at program scan speed. Probably not what you want.

Thank you Mr DOUGP.. for taking the time and replying to my post with something valuable.

You explained that count concept excellently.
i am grateful for that..

You're welcome.