Simple Script not Working

This Script does not work somehow im an absolute beginner. Can someone help me?

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Check how to write a for loop in C/C++

For syntax uses ; not , as seperators.

Please note that "does not work" is not the same as "does not compile".
Your array is only in scope inside the setup function

Hi, @leo_1238
Welcome to the forum.

What error do you get?
What model Arduino are you using?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia: :santa:

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

Move the two lines beginning with int to the top of the sketch, outside of any functions. This will make them available in all functions.

google to learn "variable scope in C++"

Change the commas in the for loop to semicolons.

Review the syntax of the for statement.

HTH

a7

Thank you!

...and take the 'y' out of the brackets.

1 Like

Hi @leo_1238, Welcome to the forum!

Please post (using </> tags) your sketch when you get it working so we can see your handiwork!

Pat.

Good eye! Missed that.

TBC lose the 'y' in the declaration and initialisation of the x array:

 int x[ ] = {13, 12, 8, 7, 4, 2};

The length of the array will be automatically set to 6, the number of elements in the list of initial values you provide.

BTW since these are small numbers and not to be changed, you could say

const byte x[ ] = {13, 12, 8, 7, 4, 2};

google "C++ data types" when learning time rolls around. It does roll around, right? :expressionless:

a7

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.