Go Down

Topic: Demonstration code for several things at the same time (Read 343455 times) previous topic - next topic

CrossRoads

Do you also find this update really fast so the outputs seem to be the same all the time?
I think I would add a time check and only update every 1/10 or 1/5 second or so.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

evancleary

was thinking that falling out of the stated sensorValue range would set the function back to when checked and found not to be

may use an else function stating that when not within range =   LOW

im gona be looking into some tutorials posted up by GrumpyMike to try get my head more around the logic required 

Robin2

What is all the digitalWrite(ledPinX, HiGH/LOW) stuff?

If these were put in named functions it would make the code much clearer.

It may also be possible to do them all in one function to reduce duplication of code.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

evancleary

its representing the degrees celcius in a 5 bit binary led setup

ie 26 degrees = 1 1 0 1 0

thus led 1 HIGH and so on

got some advice from GrumpyMike earlier saying that they can be given an array function which this page shows how to

http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

it would seem ive got a lot of ground to cover and not a whole lot of time to do it considering i have 2 exams in the next couple of weeks to boot, so it all systems are non stop.  This is why Ive been looking for a bit of direction, gona run through as much of Mikes tutorials as I can and hopefully Ill be able to work out this project

Robin2

I think we could help you much better if you give us a clear description (in english, not code) of what you want to do.

You have jumped into the middle of this Thread (which is fine) but you might have been better starting your own Thread. I suspect you are assuming we know a great deal more about your project than we actually do. Assume we know nothing!

It's not even clear to me how you are thinking of making use of my demo sketch (which, I assume, is the reason you have asked your question here).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Coding Badly

#50
Mar 15, 2014, 09:00 am Last Edit: Mar 27, 2014, 06:58 am by Coding Badly Reason: 1
...but you might have been better starting your own Thread.


He has.  Twice...
http://forum.arduino.cc/index.php?topic=225213.0
http://forum.arduino.cc/index.php?topic=224682.0

Quote
@CodingBadly Im not looking for anyone to clean up my mess...


Then stop posting obscenities, stop cross-posting, and stop hijacking.

Robin2


He has.  Twice...


Thanks, I hadn't spotted those.

@evancleary, over to you to sort things out ....

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

evancleary

ok so i made a post first time round which is the second link

after doing that i came across your post here which seemed extremely helpful because im going to have to integrate multiple functions into the one code , so i made a reply then explaining fully what it was i hoped to achieve and how i was planning to use your code in helping me learn what it was i needed to know, however that reply that i made to this post ended up being its own post? with its own new title,a title which i didnt give it.  Dont know how or why?

Apologies if my code dosnt seem neat or logical, yet again im very new to this and am just trying to find me feet with it

also yet again apologies for the obscenities but as already stated it was an absolute mistake

didnt know that i was hijacking or that posting on multiple links was a bad thing, i dont really use forums

how and ever thanks for the post it has given me an idea of how to go about getting a main loop to reference function loops, between this and GrumpyMikes stuff i should be on the right track

Robin2

The problem with multiple Threads on the same subject is that none of them has the full picture. And someone may waste his/her time giving advice on one Thread which has already been given on another.

From your own point of view the problem is that contributors will only have part of the picture and won't be able to give you the best advice.

Hijacking a Thread is slightly different - it usually means causing the Thread to wander off into a discussion that the person who started the Thread hadn't intended. In this case your interest seems to have been to adapt my code to your project. I think you lose most from using this Thread for that because readers won't expect your problem to appear here.

I suggest you ask the moderator to merge your other two threads and then continue your enquiries there, and not here.

And, as I said earlier, you need to provide a very clear description of what you are trying to do before you tell us how you are trying to do it.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

beefy23

Robin,

Keith here, you referred me to this thread a couple of days ago. Thanks again for doing something like this for irritating beginners like myself  :)

It's a bit brain frying for me at present but with a bit of repetitive studying I'm sure it will start coming together for me. One of the earlier responses was about the bracketing positioning. As a beginner the first thing that made it difficult for me to read through the code, was the positioning of the curly brackets.

I modified the bracket positioning to make the functions more graphically visible (if that's a way to put it). Now I can clearly see a function inside a function inside a function, so to speak, and it leaves my beginners brain more free to learn the coding.

Example:

void updateLed_A_State()
{
    if (led_A_State == LOW)
        {
        if (currentMillis - previousLed_A_Millis >= led_A_Interval)
               {
                 led_A_State = HIGH;
                 previousLed_A_Millis += led_A_Interval;
               }
        }
      else
        {
            if (currentMillis - previousLed_A_Millis >= blinkDuration)
              {
                 led_A_State = LOW;
                 previousLed_A_Millis += blinkDuration;
              }
        }   
}

I hope I did all that correctly LOL.

Opening and closing brackets of each function line up vertically. Brackets of "inner" functions have good distance on indentation. I realise as a proficient experienced programmer you may detest this for your own use, but seeing as your sketch is for beginners I thought I'd mention this.

Keith.

PeterH


I modified the bracket positioning to make the functions more graphically visible (if that's a way to put it). Now I can clearly see a function inside a function inside a function, so to speak, and it leaves my beginners brain more free to learn the coding.


That indentation is horrible. I recommend you use Tools / Autoformat to put it right.

Robin2

Indentation is a personal choice. Do it any way you like.

I like my way.

It is a good idea to use a system that is similar to what autoformat produces for stuff that you propose to post here. People find it easier to get a quick understanding if the format is familiar.

MUCH more important, @beefy23,    ALWAYS enclose code in CODE tags so that it displays properly. Read the stickies at the top of the Forum for instructions.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

beefy23

#57
Mar 25, 2014, 09:17 pm Last Edit: Mar 26, 2014, 03:43 am by beefy23 Reason: 1


I modified the bracket positioning to make the functions more graphically visible (if that's a way to put it). Now I can clearly see a function inside a function inside a function, so to speak, and it leaves my beginners brain more free to learn the coding.


That indentation is horrible. I recommend you use Tools / Autoformat to put it right.


Wow Pete,

that's highly constructive and educational. I love the explanation you give of why it's horrible. I was speaking as a beginner, saying what I personally find makes the code much easier to read for me. Robin started this for beginners so I simply said what aided me as a beginner to follow the code. I wasn't saying Robin or anyone else should coding should code like this themselves. I even said to Robin that he may detest that method himself.

I'll take note of your recommendation and see what results I get when I use the auto feature. For a beginner I may personally  find that result horrible. Then I can come back to you and say it's horrible and not say why.

As for my recommendation to you, don't comment if all you can say is something is horrible without giving any explanation as to why. Should I start being just as "constructive" as you and we can both start throwing rubbish at each other. Forums becomes a great place when that starts.

Edit:
I've just went at took a look at the way Jiggy Ninja (the one who said he prefers a different bracketing arrangement) does his code and remarkably it's very similar to what I did. Looks like there's 2 of us have a "horrible" arrangement. To me it's very clear and easy on the eyes. Functions stand out so clearly, perfect for a beginners eyes. I suspect I will find your personal method of bracketing much more horrible.

Keith.

beefy23

Hi Robin,

thanks for the explanation on why to use the autoformat, and I'll read the stickies about putting code in the threads.

Keith.

altimmons

I was just struggling with this myself (doing several things at once).  I will pick through the code tonight.  I appreciate it.

Go Up