Go Down

Topic: Project 6 ledpin and more (Read 1 time) previous topic - next topic

vikan

Hello! I just got my first arduino and doing my first project. I have a few questions.

1. line 4 in the book says "const int ledPin = 13;" I understand its an indicator that my sensor is finished calibrating. But it says "for this project, use the on-board LED connected to pin 13"
whats pin 13? and how do I use the on-board LED? The picture dont show anything connected in the 13 slot on the arduino board.

2. stupid question but.. can I write like in C, C++ a loops and if cases without theese "{}" if I only have a single statement after? like..

for(something)
   doThis();

3. the piezzo is very big and dont fit with other components on the same row on my breadboard. any smart tricks to make all things fit in place?

thanx :)

Claa

#1
Jun 16, 2015, 03:14 am Last Edit: Jun 16, 2015, 04:02 am by Claa
From what I understood, pin 13 is just the led right next to the number 13 on your Adruino. When you upload the code to your adruino you will see it light up.

Also, you can write loops without {} only if there is one line below the condition

for example :
for (int i=1; i< 3; i++)
    one line instructions, its ok to not have it


if there is more than a single line, then you need to put {}
for (int i=1 ; i<3; i++)
{

do this; //there are 3 lines of instructions here so {} are needed
do this;
do this;

}

hope this helps..

PS: I have been working on project 6 as well and asked a question yesterday on the forum but nobody answered so if you figure it out it would be nice if you let me know :) thanks

gmaker0507

Yeah the Piezo did seem a little large for the breadboard. I had to make sure i place my wires down first, and to use the shorter wires so they can squeeze under the Piezo.

wired67

2. stupid question but.. can I write like in C, C++ a loops and if cases without theese "{}" if I only have a single statement after? like..

for(something)
   doThis();

Hi vikan,

The language that is used to write the sketches is C++ (see this post: https://forum.arduino.cc/index.php?topic=97455.0) so anything you can do in C++ (or C for that matter) you can do in a sketch.

These: "{}" are commonly called "braces" or "curly brackets", just so you know what they are called for next time.

as for usage, what Claa said above is correct, you can leave them out, however, in my opinion, this is bad practice, especially for beginners.  You may save yourself a few seconds by omitting them, but what I often see happen is that at some point, you come back and try to add a second line, and you forget to add the braces in.

For example, say you have written this code:

if(someCondition)
    doSomething();

then you need to make it do more, so you come back and add another line, but you forget the braces:

if(someCondition)
    doSomething();
    doSomethingElse();

then this code will cause a bug in your program, it essentially the equivalent of having:

if(someCondition)
{
    doSomething();
}
doSomethingElse();

Which is not what you intended, but may not be immediately apparent.

If you get into the habit or taking the time to always add the braces, it helps to cut down on mistakes like this.

As for the piezo, I found that mounting it in the 5th hole of a row of 5 holes, it left just enough room to connect wires to the first holes in the group of 5. (I hope that makes sense)


I apologise for the wall of text, but I hope that helps  :)

Go Up