Still learning after years

try to follow best practices for coding

declare global variables and constant at the start of the code
PIN numbers are constant, so declare them as constant
don't create global variables when not necessary
if you have a led you want to drive attached to a pin, then make that pin an output
don't keep "stupid" comments
indent the code to make it more readable

it would look like this

const byte LED1 = 9;
const byte LED2 = 10;
const byte LED3 = 11;

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
}

void loop() {

  int light = sin(PI * 2 * millis() / 10000.0) * 127 + 127;
  analogWrite(LED1, light);
  
  light = sin(PI * 2 * millis() / 1000.0) * 127 + 127;
  analogWrite(LED2, light);
  
  light = sin(PI * 2 * millis() / 3000.0) * 127 + 127;
  analogWrite(LED3, light);
}

The loop loops quickly and your sin() function will likely deliver the same light value for probably 30 or 40 loop cycles meaning you are issuing commands that do not change anything. In this case this is not an issue, but refreshing a display when not necessary for example could create latency that makes a product not great to use)

2 Likes