Can somebody help me out.

I made a

void Led(int X, int state){

{

DigitalWrite(Y, 0 or 1);

}

Now i need a Number on Y.

If X=1,37,73,109,145,181 Y=1

If X=2,38,74,110,146,182 Y=2

3,.,.,. Y=3

UNTIL Y=36.

Ik an anyone help me out.

Can somebody help me out.

I made a

void Led(int X, int state){

{

DigitalWrite(Y, 0 or 1);

}

Now i need a Number on Y.

If X=1,37,73,109,145,181 Y=1

If X=2,38,74,110,146,182 Y=2

3,.,.,. Y=3

UNTIL Y=36.

Ik an anyone help me out.

Do your own homework.

This is probably a good place to start.

```
Y=X % 36;
```

```
If X=1,37,73,109,145,181 Y=1
If X=2,38,74,110,146,182 Y=2
```

It looks like you need to check the syntax for the if command in C++ and how to spell other commands correctly too

Maybe you mean

```
if (X == 1 || X ==37 || X == 73 || X == 109 || X == 145 || X == 181)
{
Y = 1;
}
```

I note, however, that the values being checked are in a series with a fixed interval and only vary in their starting value for each value of Y. A perfect job for a computer program

When is our assignment due ?

Lol its not homework.

I am not in school sinds 30 years ago.

I, am building a 6x6x6 ledcube.

At this point i have for void Led 6x a if statement.

But i want to make it shorter.

```
void Led(int Y, int state) ;
{
If (Y >0 & & Y <37){
digitalWrite(Y, state) ;}
else if (Y >36 & & Y <73){
digitalWrite(Y - 36,state) ;}
And so on.
But i need space
```

Did you note the suggestion to try the modulo operator ?

Well i did my home work.

I noticed that arduino only use whole integers in int so 1,9=1 and 2.1=2

So this way it would work.

Y= Y- (Y-1)/36+1) *36
37=37 - (1*36)=1

38=38- (1

73=73-(2

But Now i don, 't know what is the right way to write the formula

Y-(Y-1)/36+1)*36??

i don, 't know what is the right way to write the formula

What have you tried ?

Jeroentje2212:

Well i did my home work.

I noticed that arduino only use whole integers in int so 1,9=1 and 2.1=2So this way it would work.

Y= Y- (Y-1)/36+1)3636)=1

37=37 - (1

38=38- (136)=236)=1

73=73-(2But Now i don, 't know what is the right way to write the formula

Y-(Y-1)/36+1)*36??

Did you note the suggestion to try the modulo operator ?

Whoa, weird echo in here.

I got some thing else.

]Y- (36* (Y+35)/36 - 1)

If Y = 36

36=36 - (36*(36+35)/36-1)

36=36 - (36*(integer 0)

36=36 - (36*0)

=36

37=37 - (36*(36+35)/36-1

37=37 - (36*(integer 1)

37=37 -(36*1)

=1

But Now how to formulate???

Jeroentje2212:

I got some thing else.]Y- (36* (Y+35)/36 - 1)

If Y = 36

36=36 - (36*(36+35)/36-1)

36=36 - (36*(integer 0)

36=36 - (36*0)

=3637=37 - (36*(36+35)/36-1

37=37 - (36*(integer 1)

37=37 -(36*1)

=1

But Now how to formulate???

Did you note the suggestion to try the modulo operator ? (Reply #2)

Yes i did but i do not understand de modulo operator because i, am noob.

Started arduino and code writing for Just a month now

Started arduino and code writing for Just a month now

Out of interest when did you start using mathematics ?

Jeroentje2212:

Yes i did but i do not understand de modulo operator because i, am noob.

Started arduino and code writing for Just a month now

The modulo or remainder operator (represented by %) returns the remainder of any integer division.

e.g. 37 % 36 returns 1, 41 % 36 returns 5, 14 % 36 returns 14.

Does this sound like what you require?

See the Arduino % reference page here:-

https://www.arduino.cc/reference/en/language/structure/arithmetic-operators/remainder/

Ian

I think it is but do not know how to use it

I need 2 things.

First one is

1 to 36== 1to 36

37to72==1 to 36

73 to 108==1 to 36.

DigitalWrite(formule 73, High=1, HIGH)

OK so i can use (int %36)

The second one is.

1 to 6= +0

7 to 12= +2

13 to 18=+4

19to 24=+6

DigitalWrite(formule 7=9)

Digitalwrite(formule 13=17)

Jeroentje2212:

1 to 36== 1to 36

37to72==1 to 36

73 to 108==1 to 36.

Y modulo 36 would not directly work, because that would give you 0 through 35.

Offsetting the input by 1, so you have 0 through 35, will allow you to do the modulo arithmetic, then adding 1 to the result will give you the desired answer.

( ( Y - 1 ) % 36 + 1 )

you can also do it as integer math without the modulo operator:

(y - 1) - ( (y - 1) / 36 * 36 ) + 1

or simplifying a bit:

y - ( (y - 1) / 36 * 36 )

The second one is.

1 to 6= +0

7 to 12= +2

13 to 18=+4

19to 24=+6DigitalWrite(formule 7=9)

Digitalwrite(formule 13=17)

Easier to offset the input by 1 on this problem also, so you have:

0 to 5 = +0

6 to 11 = +2

12 to 17 = +4

18 to 23 = +6

Every 6th number you are increasing by 2, so divine by 6, ignore any remainder, and multiply by 2 to get the desired result.

Jeroentje2212:

I think it is but do not know how to use itI need 2 things.

First one is1 to 36== 1to 36

37to72==1 to 36

73 to 108==1 to 36.DigitalWrite(formule 73, High=1, HIGH)

OK so i can use (int %36)The second one is.

1 to 6= +0

7 to 12= +2

13 to 18=+4

19to 24=+6DigitalWrite(formule 7=9)

Digitalwrite(formule 13=17)

For the first part just use the modulo of your value-1 divided by 36 and add 1 i.e.

*result* = (*value* - 1) % 36 + 1

For the second part take your value and add the value -1 divided by six then multiplied by two i.e.

*result* = *value* + (((*value*-1)/6)*2)

This works because integer division will return 0 if *value* -1 is in the range 0 to 5, 1 if it is in the range 6 to 11, 2 if it is in the range 12 to 17 and 3 if it is in the range 18 to 23.

Ian

```
///for pins 1 to 6 to (1 to 6) and 7 to 12 to (9 to 14)
void Col(int A, int state) ;
{
shift.writeBit(A +(((A - 1)/6)*2), state);
}
void Led(int L, int state)
{
/// for 1 - 36 to (1 - 36) and 37 - 72 to (1 - 36)
Col((L) %36 +1, state) ;
Layer((L+35)/36); //1-36= layer1 37-72=2
//Layer is also Functions Layer1 on 2-6 off and otherwise.
```

Like this

I'd probably have gone for:

```
Y = X % 36;
if(Y==0) Y=36;
```

Formula Y+(((Y - 1)/6)*2 is wrong.

36 becomes 47 and need to be 46.