Programming - "styles". Slightly to way off topic for Arduino specifically.

Folks,

Indulge me here. I am really seriously and honestly looking for help/assistance in .... undestanding things.

Disclaimer:
This isn't a go at anyone here or anywhere really. It is just a story of things which have sort of happened inspiring me to ask the question.

I am new to Arduino programming and the structure of the language. So I am really having trouble keeping it all together when writing programs/sketches.

So from my perspective, I can see a corralation between this and the other big program we are all writing/running:

LIFE{}

In the little time I have been playing with the Arduino, I have seen a few different styles of how to write programs. Sufice to say: The all "work"; as in: The program does what it is written to do.
So I guess from the outside, so long as it gets what is needed done, it doesn't matter HOW it does it - within reason ofcourse.
I used to be a fairly good typer. Though not the best at spelling, I could at least hit the keys for which I was aiming. Nowa days I am not doing that too well.
This has me wondering what is going on. Is it that I am doing something "wrong" causing this problem, or is it external?
To try and resolve this, I am trying different things to see what happens. Alas this causes just as many problems as I am trying to resolve.

(I'm now typing this in notepad because of this annoying screen jumping/jerking while I type)
So where am I going with this? I'm not really sure.

But in light of all this, I am trying to re-write a lot of my "life{}" stuff, but don't have the
slightest clue about the "structure" of things.

Becase the functions aren't exactly documented it is difficult to know how to write them, and their
"results" aren't always desireable.

I'm finding this is also with the routines/functions in the Arduino.

Strangly enough I have done one of these "Human factors" courses - for something else I do - which has
sort of thrown a whole lot of new things at me with which to deal:
Mistakes/errors.
They have these vogue names like LAPS, SLIP, MISTAKE and a couple of others I can't remember or find just now.

So if I am trying to write a function and am looking at the instructions "written in front of me" or
explained (sort of) to me by people here and I am not understanding a word of what is said:
Where is the problem? I'd guess it is "here" - with me. But I can't see anything I can "use" or
understand being given to me.
As much as I can see and read the words, that is about where it ends. They are JUST words.
It is like they are just jumbled on the page/screen and to everyone else they make sense, but not to me.
I don't think I am stupid, but it really "annoys" me that I am seeing these words and examples but can't
resolve how one leads to the next.

So back to the Arduino side of things:
All these lovely new commands to do all these things. Understandably there is a syntax to them, but I
just don't get it.

As I just said, I can have an idea, read about "how to do it" with the examples, but all I see is
"gobbldy gook" on the screen.

What can I do to remove this blockage allowing me to understand what I am seeing?

Just one quick example:
The other night I was frustrated as &^ because a simple digitalWrite(pin_number,HIGH) wasn't working.
I mentioned the specific pin and where I THOUGHT it was. Luckily someone pointed out I was looking at
THE WRONG PIN! So it works.

BUt how can I make such a SIMPLE MISTAKE?

I have the Arduino pinout sheet, but it would seem that it either isn't clear enough or it is confusing
to me.

Why the pin names are so "generic" that in one instance it is "analogue input 0" and another it is PIN 16
(for example.)?

I believe it's a left/right brain thing. I'm easily befuddled by the coding part of this deal but I really enjoy making crap. I'm sort of putting off the inevitable CODING by mostly using copy/paste code and tinkering with it. And soldering crap together...

I am pretty determined to accomplish some things with these IC's and I reckon If I want to do the things I want to do I'll have to pick it up eventually.

I have an Arduino book in my bathroom...

hoff70,

Thanks.

I pretty much do the same.

CUT/PASTE and hope.

Most of time time it works, but when it doesn't it really doesn't and seem to get frustrated because I can't find something which I can understand to explain why and show me how to do it.

Oh well, I guess one thing is I am not the only one with this "affliction".

Programming is something unusual... I over see some juniors at times... some of them have 'it' and some don't.

For me it's the other way around... I don't have much interest in building hardware... So I have a friend who looks after all the hardware, and I do the software. He takes more care with it than I ever would... but the code would eat him alive.

The best advice I can give is to try to appreciate what every part of your code does. If you don't understand certain lines, then do your best (whether by reading the documentation, or utilising forums like this) to find out what they're really doing. If you start treating certain blocks of code as 'magic', you're done for... there is no magic.

The IDE will prevent you from the simple mistakes... spelling, using the wrong data types, but the reason it gives you might be cryptic... When you get a cryptic message, try to get to the root of what it's telling you rather than just hacking away till it works. It'll be far far slower at first, but try and suck that up and fight past it, it's worth learning.

I remember as a kid, having friends with VIC 20's and COMMODORE 64's. We'd have sleepovers and they'd stay up all night coding in BASIC just to make a little ball bounce around the screen. I should have learned it back then but I just didn't see the payoff. Hours of typing and a little black and white ball bounces off a wall on the screen...

Anyway, this is different. This is PHYSICAL COMPUTING! Make motors turn, move stuff around. Make objects do things based on changes in the environment. Make lights blink!! Set stuff on FIRE! It's amazing to me...

lost_and_confused:
LIFE{}

LIFE () {
lol;
}

lost_and_confused:
They have these vogue names like LAPS, SLIP, MISTAKE and a couple of others I can't remember or find just now.

When I was fresh out of college, I worked for the largest pharmaceutical distributor in the UK (now defunct), the company had sort of bought some software from a company that they were using and expected to get sourcecode along with their purchase.. The original authors had different ideas. It took about 3 months of wrangling before the sourcecode arrived, some 400K of 6502 (Apple 2) assembler code that compiled down to about 6k, well, long story short but, YES, they supplied the sourcecode and every label, every subroutine was renamed to make reading the code impossible, I still remember what "paper:", "ruler:", "car:" and "stencil:" did, dang, took me a year to physically work out all the nuances of that code. The one think it has taught me is document the cr*p out of everything I write.

You'll find that once you immerse yourself in the environment, one day it will just click, you just have to bare with it

I kind of agree, "emursion" is good to a point.

But when you just don't get anywhere, it really gets frustrating fast.

I shall have to make my "cheat sheets" a lot better than they are - especially for pin numbers/names.
That was embarrasing.

I am warming to the idea of instead of writing a "progam" I write a lot of little functions which do their own little thing and then combine them to do the bigger thing.

But passing variables between them, and a few definitions are really getting me.

lost_and_confused:
I am warming to the idea of instead of writing a "progam" I write a lot of little functions which do their own little thing and then combine them to do the bigger thing.

But passing variables between them, and a few definitions are really getting me.

Ah so grasshopper, modular programming... you're learning already!
Variables that pertain only to what the function is doing should be local to each function, they don't have to be global

REMEMBER also, that functions CAN AND GENERALLY DO return values from whatever they do....

IMHO Your main loop should be as close to.. as possible! Minimal processing inside main loop, let the functions handle processing
void loop () {
function_a();
function_b();
function_c();
function_c()l;
if (function_d() == TRUE) function_e;
}

abrookfield:
You'll find that once you immerse yourself in the environment, one day it will just click, you just have to bare with it

And when it does eventually 'click' It's a great feeling, for me anyway. As is finally completing a project.

I'd strongly discourage copy & paste tinkering, read reference material and test bits of code till you get it.

It's a steep learning curve, but once you climb a bit it keeps getting easier.

I have a Nextbook3 a kindle and "A Book on C" in my bathroom, spend most of my time reading the C++ Primer 6th Ed. simply because even tho it's about C11 and the Arduino is somewhere in between the two, the Primer is easier to understand... The Examples make more sense to me... I suppose it is a more simplistic approach from the primer doing nearly identical things that makes the newer book easier to use... I think the C book was written for people with a good C background and the C++ book is covering similar ground from a different perspective as C11 is newer and changes a lot of the method of what can be done. My issues come from trying to fit what I find in the books into the Arduino environment. My approach is to go from the problem to this section, ask when I can't find the answer and when I get fairly good at that then start applying more of the knowledge learned as I go along. This is my retirement... I Refuse to go into the cold grey dark in front of the television...

Doc

Docedison:
This is my retirement... I Refuse to go into the cold grey dark in front of the television...

Doc

Wish I could retire to tinkering with H/W & S/W, I've a bit to go yet being 30 though :frowning:

Enjoy it now... all you are doing now is creating the memories that will be your old age company... So Do it to the best of your ability and do it often.

Doc

I kind of agree, "emursion" is good to a point.

Emulsion?
Immolation?

I was frustrated as &^

You can't dereference a pointer to the XOR operator and multiply it by nothing.
That probably explains your frustration.

They are JUST words.

No, they are a highly formalised and rigidly structured recipe or knitting pattern.

@lost_and_confused
It's just possible you don't have the mind set for programming, or at least original programming from a blank sheet. For example my wife has a bachelor of computer stuff but she can no more sit down and start a program from scratch than fly to the moon. She can however take an existing program and modify it to her needs.

I'm the opposite, I've not had a single day of formal training but worked in the job for 20 years and am quite happy to sit down and write 2000 lines of code from scratch with no hardware and then expect it to work when I get something to run it on, there will of course be bugs but I wouldn't expect anything major. OTOH I have a lot of trouble trying to figure out other people's code, I often search for an example of a particular algorithm, find one but can't work out how that hell they did it so write my own anyway.

As an example I'm currently porting a lot of the Arduino stuff to an LPC, I had maybe 20 files of code written and compiled before I got my boards, when I got them and started debugging I found that most things worked, at least with some reasonable single-step debugging. I did grab some example code and used that as a starting point for some things like the UART initialisation, but when I had a good look at what they'd done I didn't like and/or it didn't suite my needs so my current version looks totally different. I then moved on to the timers and couldn't find an example so started from scratch, I reckon I had it finished quicker than the UART where I supposedly had a leg up with an example.

So after that lengthy tome what I'm saying is that some people got it and some ain't, we all have different strengths. That said programming in C has never been easy, in my early days (and still to some extent) I spent hours bashing my head on the desk and threatening to throw the computer out the window because of a misplaced comma or full stop, as has everyone else here I'm sure so you're not alone.

EDIT: One reason I wrote such a long post is that I needed a break because I've just spent over an hour staring at some PHP code that refuses to work even though it's perfect. The frustration never ends. :slight_smile:

EDIT2: It was an extra / in a path string. Another programming lesson, when things aren't working take a break.


Rob