Still learning after years

What is wrong with this?


void setup() {
  // put your setup code here, to run once:

}

int light;
int LED;
int AnalogWrite;

void loop() {
  // put your main code here, to run repeatedly:
light = sin(PI * 2 * millis() / 1000.0) * 127 + 127;
AnalogWrite(LED, light);
}

I get a fault code like 'AnalogWrite' cannot be used as a function'

Thanks in advance
Jörgen

The problem is caused by this line:

I understand but what should I do instead?
If I put // in front of it I get 'AnalogWrite' was nit declared in this scope.

The function is analogWrite, not AnalogWrite.

1 Like

LED is also not initialized

Now it says
exit status 1
'int analogWrite' redeclared as different kind of symbol

I paste it as it looks now!

void setup() {
  // put your setup code here, to run once:

}

int light;
int LED;
int analogWrite;

void loop() {
  // put your main code here, to run repeatedly:
light = sin(PI * 2 * millis() / 1000.0) * 127 + 127;
analogWrite(LED, light);
}

Can I find a list of possible declarations?
I guess I have to declare analogWrite differently.

please use code tags. I fixed your first post but won't do that again...

1 Like
void setup() {
// put your setup code here, to run once:

}

int light;
int LED;


void loop() {
// put your main code here, to run repeatedly:
light = sin(PI * 2 * millis() / 1000.0) * 127 + 127;
analogWrite(LED, light);
}

Fixed it.

You declared a variable called analogWrite that I have removed.

1 Like

Ok Thank You!

But will it work when analogWrite is removed?

The IDE takes care of that. If you want to specifiy a function prototype, your code would look something like

void setup() {
// put your setup code here, to run once:

}

int light;
int LED;
int analogWrite(byte pin, byte value);

void loop() {
// put your main code here, to run repeatedly:
light = sin(PI * 2 * millis() / 1000.0) * 127 + 127;
analogWrite(LED, light);
}

As said, the IDE takes care of that (although it can make mistakes).

1 Like

Try it.

Thanks!
I does not give faults at least.

you have not fixed post #6.... please click on the pencil below the post and add code tags around the code.

I think I have now.

There was supposed to be a quote before my I thi......

1 Like

I think I have a few more things to fix.
It is supposed to dim a LED up and down but I have not set witch output. How do I do that?

I found out something myself!!!!!!!!

I changed int LED; to int LED=10;
Now it works.

Lets make it a day!

Thanks guys!
Jörgen

2 Likes

yes, it works better if you tell the compiler which pin you want to deal with :slight_smile:

1 Like

Aha!
I am getting forward!
This is dimming a RGB diod with different speeds.

void setup() {
  // put your setup code here, to run once:

}

int light;
int LED1=9;
int LED2=10;
int LED3=11;
//int analogWrite;

void loop() {
  // put your main code here, to run repeatedly:
  
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);
}