How to understand this.. cant replace the the code

#int led = 13;
#int brightness = 0;
#int fadeAmount = 5;
#int thisisnew =0 ;
#void setup ()
#{
#pinMode (led, OUTPUT);
#}
#void loop()
#{
#analogWrite(led, brightness);
#brightness = thisisnew + fadeAmount; // brightness replaced with "thisisnew"
#if (brightness <= 0 || brightness >= 255) {
#fadeAmount = -fadeAmount;
#}
#delay(30);
#}

and the question is ?

why this one not working
#brightness = thisisnew + fadeAmount;

but must use this one
#brightness = brightness + fadeAmount;

Where did all the hashes come from ?

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

If you get errors when compiling please copy them from the IDE using the "Copy error messages" button and paste the clipboard here in code tags

what is not working?
post your sketch using the code tags </>

the code similar like this

int A = 0;
int B = 1;
int C = 2;

then i put at loop
A = B + C;
but this one not work

the working one, i must put
A = A+ B;
is it must repeat the "A" after "="?

If you use

A = B + C;

then every time the statement is executed the current value of A will be replaced by the sum of B and C

However, If you use

A = A + B + C;

Then the value of B will be added to the current value of A

Do you see the difference

1 Like

Please read the reference. The function analogWrite() needs a PWM pin and pin 13 on a Arduino Uno is not a PWM pin.
https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

With pin 11, this is your sketch in Wokwi simulation:

1 Like

thanks.. UKHeliBob dan koepel.. i saw the different