This is my first post here, so in the beginning I'd like to say 'Hi' to all of you
I'm trying to complete a simple project, which includes controlling LED brightness. I noticed, that using writeAnalog with linear values doesn't give me a linear increase/decrease of the brightness. Quick internet search gave me a few answers, and I decided to try one described here
I wrote a quick test, but was surprised when saw upload error related too using too much memory (I'm using ATtiny13a). After some investigation, this time on my Uno, I was able to prepare minimal program, where the issue occurs. This is of course some artificial code, which doesn't do anything useful - it just shows the problem.
#define LED_PIN 0
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
analogWrite(LED_PIN, getValue(1));
analogWrite(LED_PIN, getValue(2));
analogWrite(LED_PIN, getValue(3));
//analogWrite(LED_PIN, getValue(4));
}
int getValue(int value)
{
return pow(2, value);
}
This code compiles and according to info, uses 922 bytes. After uncommenting the last analogWrite, usage jumps to 2952 bytes. If I remove pow function from getValue, and just return value, issue doesn't occur.
In addition, I observed that changing the loop to:
void loop() {
for(int i = 0; i < 1; i++)
{
analogWrite(LED_PIN, getValue(i));
}
//analogWrite(LED_PIN, getValue(1));
}
compiles to 880 bytes. Changing 1 to 2 in for condition, causes usage jump to 2914 bytes, and then, uncommenting analogWrite, causes it to go to 922 bytes.
I have no idea what is going on here, and I really hope someone here can help me understand it...
I'm using Arduino IDE 1.8.13
Thanks!