Author Options:

Arduino Code? Answered

I would like to understand this piece of Arduino code.

            " delay(300L * 1000L); // 5 minutes. This can be changed to change increments "

This is supposed to be a 5 min time period. 1000 = 1 second. 60 sec per min. 300 sec / 60.  
Calculates by 300 / 60 = 5 minutes.

What is the  " L " supposed to do? What does it represent?



300L and 1000L aren't defined.

This program is AWFUL. Forget it. Start again !

Are you always selling 3 minute chunks ?

Correct i did not wright this. My skills are no ware close to be able to actually write a code. Best i have successively have been able to is manipulate them some.

Correct again, I sell 3 minute chunks of time on a pay fone. Monitored by me on a clock, but as you can imagine they mostly go overtime. Hard to regulate manually.

I would like a visual countdown of the time that the paying customer can see and know exactly how much time they hare remaining. Also will need to be able to add additional 3 chunks of time at any point in the countdown. At the end of there time i could terminate the call with a relay control.

If 12 LED's were used they could be at 15 seconds each making the 3 minutes.

Good, then I can be rude about the code. Its horrible. There, that feels a lot better ;-)

Are 10 increments too many ? Or would three LEDs work.

Green: Plenty of time.
Orange: 15 seconds to go
red:5 seconds to go ?


I am glad u feal so much better, ha.

I don't think 3 is the way to go. I would have to educate everybody on the 15 seconds then 5 seconds. Besides a lot of people don not know enough english to understand me explain that to them.

My thinking is if there was 12 LED's at 15 second intervals they could see there complete time and have a feal for the amount of time used and remaining. Plus that's more self explanatory.

They would come in and say " payfone ". Ok 5 pesos. Time clock here!

Easy to see, easy to understand.

I think Arduino has enough pins if the Analog pins could also be used here.

By the way mine are " ACEDUINO ". Philippines version. $15 US money.

If i can get the drivers for my cam i will post a pic of an Acedino. ASAP

I'd use a shift register to get many LEDs lit. Can you get the 74HC595 locally ?


Here's the connection you need.

The code samples there will get you going. The next "trick" is to make it do what you want, but that's not too hard.

How do you want the bar graph ? Start with no leds, and fill up, or countdown from all leds to none ?

Count down. From all to none.

I guess it would go like this: ?
Start button that sets the 3 minutes,
Reset button to cancel at any point,
Add time button, 3 minutes. To be added at any point in the count down.
Relay energize at end of count down.

I want to build that circuit from the link you sent me, I will be working on that.

Its going to be pretty easy honest ;-)

The first, and most important, part of writing a decent program is a really good description of what the ^^$&$ it has to do - you're there already.

I take it the "add 3" button is remote...... - you could do with it being a pocket radio thing couldn't you ?


I was thinking a small panel by my office/computer station. Down below the counter so the buttons could only be operated by me. LED's mounted on the close side pillar. Vertical.

Could / does the code work like this, we now have 16 LED's for our countdown. Will 16 always be divided into what ever time is set. 3 minutes divided by 16. 4 minutes divided by 16 with out having to recalculate the time intervals every time change?

Divide time [ X ] by 16.

I built the circuit and ran the sketches. I need to recheck connection again cuz it doesn't seam correct.

I am glad this going to be easy for you,ha. I just following you around.

Would you like me to rough out a bit more of it for you ? There are some nice wrinkles we can do to it, if you find the "timer1" library

Yes i would like more of your help.

This is my quest, to find the "timer1" library.

Circuit working now. Wiring issue as usual.

I am going to owe you lunch for all your work!

Do you want to drive it from your PC, via its USB port ?

Then you could just use a terminal to set the time and reset it ?


That is a great idea and i think that normally i would but,

This terminal is very busie now as it is. I control 19 rental PC, a PA system running through this PC, the lights and fan in my house, CCTV, I have a back computer room i can not see into directly so i use one of the cams to monitor in there, among other daily activities.
Sometimes i even squeeze in time to go and take a leek. ha

I think for this application an operator panel would be more efficient considering.

No mater what is happening with the PC i could always sell fone time separately.


Answer 5 years ago

Timer1 now installed in Arduino Library

Is it always going to be three minute chunks ?

For now its 3 minutes. Maybe in the future it changes.
If so would i beable to change the code to change the time?


Answer 5 years ago



The question is... Is the L a defined variable or is 300L a defined variable? This could be multiply 300 and 1000 by L or it could be whatever 300L and 1000L stand for being multiplied together. For all we know the 300L and 1000L could be a string or matrix being calculated here.

It would help if you would post the entire sketch so we can see what context this is being used.

I know Steve has been answering WWC's questions but I didn't see a direct response to your question so here goes:

The 'L's you are seeing in the code is telling the compiler to use LONG integers for the math. A normal Arduino INT variable can only hold values from -32,768 to 32,767 whereas the LONG integers can hold values from -2,147,483,648 to 2,147,483,647. The code sample provided did things like multiply 300 and 1000 which gives 300,000 which it too large to place into a normal INT, therefore you need to use LONGs.

Without the 'L's the compiler might treat the constants as INTs and then get an OVERFLOW during the computations. Adding the 'L's tells the compiler to treat the constants as LONGs and so no overflow.

Best Wishes

I was thinking i should of posted the complete code after i posted the message.
I appoligise i will do it now.

Also background on project. I have a pay fone that rents for 3 minutes at a time. I only just watch the time manually now but people tend to over run a lot. I wanted to put a count down timer for 3 minutes. Display could be in LED,s that turn off starting from top then when the bottom last one goes out then time is up. Could use a 7 seg displays and show in seconds. 120 count down to 1.
If using an LED count down, each LED would be a 15  seconds block of time.

I am just starting in coding so my skills are infantile.
This is not my code i am using the code from.  https://www.instructables.com/id/Arduino-Kitchen-Timer/


Answer 5 years ago

I have another addition i forgot to mention. This code has a 10 count output. To have a 3 minute timer displaying every 15 seconds, that is 12 outputs. I would need to add 2 outputs to the code. Would need to be able to add additional time, which i think the code does.