Wich programing language to learn

Hi guyz, i'm new to programing and i've started to learn c++, now my question would be am i doing it the right way? Is it best to learn c++ and then start doing arduino programing, asking as eventualy i want to be able to write a program that has a user interface wich controls arduino depending on the user input.

Will C++ knowledge help me understand all about programing behind the hardware or would i would be better of to learn C. Just a sidenote, i want to be able to progress to more powerful hardware with time so looking for best programing language to achive that.

Much abliged

You can learn C++ by programming Arduino.

Dadorcp

Dadorcp:
Just a sidenote, i want to be able to progress to more powerful hardware with time so looking for best programing language to achive that.

First of all: I think there is no correct place to ask this question. As this is a arduino forum which is C++ oriented the answer here is C++ is a good start.
Go to a Bascom place and they will tell you bascom is a great start; go to a java place ....

As I have a pretty wide background I'll do an effort anyway:
As you are talking about "more powerful hardware" development and micro controller development at the same time I would say C++ (as a language and not as 'my first language') is the only qualifying language.
As far as I know C++ is the only language that has great support on PC/unix/linux -so not application servers;mainframes- and micro controller code development. You willing have to go with proprietary software for the PC part though (read pay license or use trial version of some kind).
Note that -even though you can use the same language- "more powerful hardware" development is majorly different from micro controller development.
This because languages are moving away from the underlying hardware to a higher level of programming closer to "business needs". Whereas on a micro controller you need full understanding of the hardware.

Dadorcp:
i want to be able to write a program that has a user interface wich controls arduino depending on the user input.

You need a way to communicate between the system that runs you user interface and your arduino. There is only a limited number of integrations.
The once I know are: serial; ethernet; bluetooth; xbee
Only serial is a protocol where C++ can be high on the list of advised languages. IMHO serial is mostly used but (because arduino IDE and serial monitor use it) but is IMHO hardly a preferred choice to put a GUI on top of Arduino.

Conclusion:
For what you want to do you can go with C++ only but it will be far more beneficial and productive to learn more than one language.
The languages to learn will be dependent on the project and tool chain you have in mind.

Best regards
Jantje

Thank you guyz for helping me out, i'm quite blury when it comes to this, thats becouse i dont have the big picture of how its all connected to eachother, software, languages, hardware(readymade souch arduino and alike), and electronics ofc.

Reason why your input is of souch importance to me before i go and learn stuff is, i'm acquainted enough to know learning this stuff is never ending process, so better start with right stuff.

Just to make it clear, i didn't ment to say that arduino is not powerful, merly that i would like to become quite a knowledgable person so i can work with more hardware platforms depending on what i need.

For instance, i was told that arduino can do anything you want, but when useing 2 arduino serial connection over longer distance ethernet cable, it is not recommended to use arduino base for video streaming onto small display (for this matter, handheld controller with display, no aditional computer). Not enough speed/memory or something like that, and thats something i really need for my ultimate project one day, but theres no rush, get my basics straight and slowly work my way up.

Also, i'm certantly gonna learn more languages, even from my beginer perspective it was obvious to me that this aint gonna happen if i learn just one thing and now when you advised me to learn more than one, i'm gonna do just that.

Again, thank you so much for helping me out.

Regards

Hi, The Arduino IDE and Arduino's subset of C/C++ is a good place to start.

Main thing is, DO it. After time it will all make sense and you will learn more than one language, especially if you end up writing Web stuff also.

READ other people's code. The EXAMPLES that come with Arduino (Click on FILE, hover over EXAMPLES) are good.

I have code examples up for a magazine article I wrote recently. Maybe look at the Template I start with:
http://arduino-info.wikispaces.com/SHED-Article2SOFTWARE-SketchTemplate

and here's a simple example of an automatic system:
http://arduino-info.wikispaces.com/SHED-Article2SOFTWARE+-+Automation+Example

That makes the point that thinking through the Structure of a program is as important as the code. With Arduino I like to think of every nontrivial program as doing these 3 things:

ReadSensors();
MakeDecisions();
TakeActions();

Those 3 things sort of happen (conceptually) from right to left on the diagram here:
http://arduino-info.wikispaces.com/StarterSet-Circuits-Pins-Bits

just add details for whatever you want to accomplish :slight_smile:

I'll be finishing a rewrite of the whole Arduino How-To this week and you'll find it on the ArduinoInfo WIKI here - http://arduinoinfo.info

Let us know what you think after getting started. And I'd like to hear about whatever you initially found confusing. terry@yourduino.com

and here's a simple example of an automatic system

Simple maybe, but it is fairly well packed with bad programming; globals that don't need to be and variables initialised in setup, when they might just as well have been initialized when declared, and an assignment in an "if".

it is fairly well packed with bad programming

I don't think so. IMHO it can be improved, but it has also good points.

I don't see any "globals the shouldn't be". Could you elaborate on that ?

I like the general structure (which is the main point of the example, IMHO). Read inputs, set internal state based on input values and previous state, drive outputs based on the newly calculated internal state.

The assignment inside if() is a bad error, indeed. But we all know it can come up as a typo.

MakeDecisions() is missing IMHO a hysteresis threshold.

void MakeDecisions()
{
    if (photoValue > potValue + thresh)
    {    
        lightsOn = true;   
    }
    else if (photoValue < potValue - thresh)
    {    
        lightsOn = false; 
    }
}

I would also rename showValues as debugMode, but that's just a matter of personal taste.

Finally, I don't like that delay(1000) in loop(). I would replace that with the usual "blink without delay" technique. But maybe the author didn't want to increase the complexity of the example.

I don't see any "globals the shouldn't be". Could you elaborate on that ?

There are four globals.
Only the debug print flag should be, the rest should be passed to and returned from functions, otherwise it looks like we haven't progressed past BASIC.

There are free readers with code examples which might help "to learn by example"
e.g. - http://www.earthshineelectronics.com/files/ASKManualRev5.pdf -

AWOL:

I don't see any "globals the shouldn't be". Could you elaborate on that ?

There are four globals.
Only the debug print flag should be, the rest should be passed to and returned from functions, otherwise it looks like we haven't progressed past BASIC.

Hey, your not the boss of my globals. :wink:

Hi Guys,

I am remembering something I once wrote that included the phrase "Egoless Programming" :stuck_out_tongue:

Very valid criticisms of "Good programming Techniques", and I certainly didn't follow some in the desire to Keep It Simple.

Globals: I wanted to have the Newbie at least see and understand VARIABLES. TYPES, OMG...

delay: Again in the interest of simplicity.. Non-blocking code is a great subject for a later excercise.

I will change the assignment inside the if: You're right, and it will actually be clearer.

@tuxduino, I LIKE that example of using hysteresis, and I'll steal that for a later example.

Variable initialization in the declaration may be a good standard, but it's not obvious to the Newbie. I was trying to make it clear What Goes Where.

There are free readers with code examples which might help "to learn by example"
e.g. - http://www.earthshineelectronics.com/files/ASKManualRev5.pdf -

Mike McRoberts has done some excellent work for sure, and I recomment his book "Starting Arduino" to many people.

In the spirit of Niklaus Wirth, and "Stepwise Refinement", I will look at several incarnations of this simple example, incorporating those better programming techniques and WHY they matter. (I'd have loved it if Arduino had started off with PASCAL as a base).

BASIC was structurally inadequate, but it could be CLEAR to the newbie. My kids learned to program in Dartmouth BASIC on the phone line, starting in 1972. These days, my wife is the head librarian at Hanover High School, 1/2 a mile from Kurtz and Kemeny's old offices where they developed it in 1964.

I'd be really interested in ideas you 'young' guys have about presenting each of these CS concepts to the almost-newbie. I don't want to start by showing them the guts of one of Rob's libraries in C++ and have them turn to watching the Destructors on TV football :slight_smile:

..On Second Thought: What's Bad aboot this??

if (photoValue > potValue)
{
lightsOn = true;
}
else
{
lightsOn = false;
}

AWOL:

I don't see any "globals the shouldn't be". Could you elaborate on that ?

There are four globals.
Only the debug print flag should be, the rest should be passed to and returned from functions, otherwise it looks like we haven't progressed past BASIC.

I think you didn't understand the concept behind that code. The debug print flag is a state variable as all the others are. Just as an object methods freely access its data members without having them passed as arguments, so in that example the three main program entry points act directly on program state variables.

Of course this is just my opinion.

I'd be interested in seeing how you'd modify the sketch to make it global-less, as you have just described. Thanks.

terryking228:
..On Second Thought: What's Bad aboot this??

if (photoValue > potValue)
{
lightsOn = true;
}
else
{
lightsOn = false;
}

You're comparing two analog values, which could fluctuate by some units. If the test is done "fast", you can have flickering.
In fact your 1s delay between each run prevents this from happening even if you haven't any hysteresis.

I think you didn't understand the concept behind that code.

You are, of course, entitled to your opinion, but I believe, with any due respect that I do understand the concept.

I'm a very good 7000km from my laptop at the moment, so I'm not going to be editing any code on an 18cm tablet screen, sorry.

(Hmm.. did I forget a couple of smileys in my last post ? Maybe... :stuck_out_tongue: )

You're comparing two analog values, which could fluctuate by some units. If the test is done "fast", you can have flickering.
In fact your 1s delay between each run prevents this from happening even if you haven't any hysteresis

OK, thanks.. I agree that Hysteresis is the right practical approach here, I thought there was some other problem with the basic code construct...

Thank you guyz for the links, its great to see your code and code comments. Thx for the offer to help with arduino once i start Terry, i will let you know when i get stuck, ty.

I see its quite important to write code efficiently. I've just finished Class and Variables with multiple parameters so i still got whole heap of stuff to learn, but now i will definitely give extra attention for writing code properly, and practice it from begining.

the best language you should learn is c and c++. and if you are interested in computer programming. go for Java