Finding programming tutorials not basic enough

Hi All, I bought an Arduino Uno build kit from Adeept on Amazon for my son to learned building and coding. We built and coded an LED and then a buzzer which both used two simple lines of code. I'm hitting a wall with this third project, LED with a button. The actual build is very simple with the photos provided, but anything I find regarding coding isn't clear. What I mean in many of the examples, what is code? What is instructional? Which symbol is needed and which isn't? The example say buttonState, do I type buttonState or is it asking for a button number to be inserted from the Arduino board. It'd be nice to find code that is written verbatim to copy, not examples. Any advice or web links are appreciated. Thanks, One Frustrated Noob PS- here's an example: // constants won't change. They're used here to set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }

void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); }

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

FrustratedNoob:
It’d be nice to find code that is written verbatim to copy

You’ll find plenty in the Arduino IDE at File > Examples. There are tutorial pages to go with them here:

If there are parts of the code you don’t understand you can start by looking here:
http://www.arduino.cc/reference/en
if you don’t find it there then just do some searching on Google.

FrustratedNoob:
PS- here’s an example:

You’re missing the closing brace at the end (}).

What do you not understand in your example?

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop()
{
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH)
  {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

https://www.youtube.com/watch?v=CbJHL_P5RJ8

The example assumes the pushbutton is wired between +5 volts and pin 2 and a pulldown resistor is wired between pin 2 and ground. Is that the case?

int buttonState = 0; // variable for reading the pushbutton status

Is a variable to hold the state of pin 2 if it is needed later in the sketch, not really needed here, and since global variables are initialized to "0" at startup you could just write:

int buttonState;

Also, this whole block:

 if (buttonState == HIGH)
  {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }

Could be replaced with:

digitalWrite(ledPin,digitalRead(buttonPin));

@FrustratedNoob, I think the message in Replies #2, #4 and #5 is that it will be easier to help if you focus on understanding a single program.

Ask as many questions as you like about that program and I reckon when you understand it then you will also be able to make sense of many of the Tutorials.

IMHO the alternative is to put your project to one side for the moment and find an Arduino tutorial that you are comfortable with and work through that tutorial from beginning to end.

...R

Yes, the Arduino Playground is a treasure trove of easy to understand info and example sketches of nearly every instruction. Playground Also the reference page gives details of the more common commands. Reference

Examples like the one you posted contain EXACTLY what is intended to be typed (or copied) in. But perhaps you haven't yet worked out how to distinguish working code from what programmers call "comments".

Any line starting with // is just comment, usually instructional. If you're laboriously typing things in from a printed book or similar these lines don't NEED to be typed in. Anything on a line after // is the same and can be left out. They're only for us humans not for the computer.

But they aren't in there just to instruct or annoy you. Good programmers put lots of comments in their programs to tell them what they were doing in the code. It sounds pointless until you revisit a program after some time when you'll find it makes it much easier to recall what that odd bit of code was doing in there.

Steve

See if you can find a [u]real[/u] person nearby that can spend an hour or two each week for a freshly baked cake! Not [u]too[/u] experienced, or possibly a mature person that has patience - as it only takes about 4 sessions for most kids to light up like a bulb and start grasping concepts.

Of course a student can help, but often passes on bad habits they haven't corrected in themselves.

The problem with teaching goto is exactly the same as starting with delay()-based Blink

Blink is a perfect way to introduce a newcomer to the Arduino. What do all newcomers want ? They want something to work and Blink provides an instant hit. Load it, compile it and it runs. No extra hardware required, the LED just turns on and off at regular intervals. First objective achieved.

Now the fun starts The problem is that people learn at different rates and online tutorials really don't have any way of getting feedback from the user and responding appropriately unlike when being trained by a person. I showed my Granddaughter the Arduino when she asked what all that "electronic stuff" was on my desk. I first showed her Blink. She was not impressed, but as soon as I showed her how to change the period her interest was sparked and she started asking questions and we progressed to her copy/pasting more delay/on/delay/off sequences into loop(). Introducing for loops to cut down the code was a struggle and her eyes glazed over when I tried to explain how arrays could be used to hold delay values and she lost interest. Programming is certainly not for her.

We only got as far as we did because I could see what she was doing, could ask her leading questions and push her in a direction that I thought would be useful. I certainly would not have started off with BlinkWithoutDelay because it would have taken more time to explain, time for her to understand and would have seemed difficult for such a meagre result. It is, after all, a convoluted way to turn an LED on and off if that is all you need to do.

If Delay is the wrong place to start because you could do the same thing a better way then why not start by teaching OOP or even assembler. It is surely a case of horses for courses and even then the horse must go at the appropriate speed and the "jockey" must be able to get feedback and give input as appropriate. I am afraid that online tutorials are a long way from being able to provide such a service. Mind you, this forum is not much better some times as it often takes a few iterations of question/reply to ascertain how much the OP knows/understands and what the problem really is.

I imagine the OP has given up all hope by now and decided that programming is for squabbling "experts" and not something that normal people like him should venture near. Shame but I'm sure that is the impression this forum gives sometimes.

Having lots of knowledge and being able to write complex clever programs is great. But being able to explain basic things to people with little or no background in the subject is a very different skill. At the moment we seem to be a bit short of people with the second skill set, though thankfully there are a number of notable exceptions.

Steve

slipstick:
Having lots of knowledge and being able to write complex clever programs is great. But being able to explain basic things to people with little or no background in the subject is a very different skill.

+1

However the OP must take a little responsibility for not having responded to the earlier Posts. This sort of “expert squabble” usually seems to happen when the OP leaves a vacuum to be filled.

…R

I am sure that you are right about the OP.

The main problem that I have when answering here is how to pitch my first reply when the OP is an unknown quantity.

Should I

(a) ask questions to elicit a response to give more information
(b) point out obvious errors but suggest no solutions
(c) link to appropriate tutorials/threads
(d) plunge in with a solution
(e) simply write the code
(f) something else

I have done all six and combinations of them but it is guessing game.

Then there is the problem of several people responding to a post in slightly different ways so the replies overlap and appear to give conflicting or at least different advice. I am always wary of joining in an active thread but do so if I think that I can add to the discussion. Of course, that is a matter of opinion.

It is so much easier when you are teaching people in person.

Spot on UKHB…
Another variation, is when a genuinely helpful amateur chimes in with half-truth or simply incorrect advice.
They’re trying to be helpful, but it just muddies the water for theoriginal question.
It’s unkind to slap them down, but equally unhelpful to let the incorrect advice stay alive.

Just correct them politely. If they can't handle that then they're probably not going to last long on the forum anyway.

I do think it's important to maintain an environment that welcomes reasonable participation. The path of least resistance is to ask questions on the forum when you need help or lurk for entertainment purposes. It requires extra effort and confidence to actually try to make a contribute to the forum. If someone with good intentions gets the feeling their participation is not welcome that may result in the loss of someone who would eventually grow to be an asset to this community.

For quite a long time I just lurked on this forum. I like to play a game where I make a private guess what the answer to a question would be and then watch to see if I was correct. It seems like a good learning technique. At some point I decided to start actually posting, for better or worse.

Some forum members have been kind enough to send me a private message informing me when I've made incorrect statements but I don't think it's wrong to make a public correction. In fact, a correction right on the thread might be better in the big picture because it could take some time to see a private message and fix the error and that's just more time for it to mislead people.

pert: In fact, a correction right on the thread might be better in the big picture because it could take some time to see a private message and fix the error and that's just more time for it to mislead people.

When I make error (note "when" rather than "if" :) ) I prefer if someone points it out in the public Thread. Then I can acknowledge it and correct it. And if, for whatever reason, I am slow to follow-up the Thread the OP will see the correction.

...R