Skip to content

analogWriteSetup doesn't work inside setup #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
faustinoaq opened this issue Nov 3, 2018 · 1 comment
Open

analogWriteSetup doesn't work inside setup #88

faustinoaq opened this issue Nov 3, 2018 · 1 comment

Comments

@faustinoaq
Copy link

Hi @me-no-dev thank you for this project!

I have an issue with analogWriteSetup:

#define PIN 18

void setup() {
  analogWriteSetup(250, 1024); // 250Hz and 1024 steps
}

void loop() {
  analogWrite(PIN, 260); // testing 260 steps
}

PIN 18 should output around 450mV but it outputs only 20mV

@faustinoaq
Copy link
Author

After checking your source code, I realize analogWriteInit() overwrites my setup, see:

_pwm_has_started = 1;
_pwm_wanted_freq = analogWriteSetup(1000, 256);

so I did this:

#define PIN 18

void setup() {
  analogWrite(PIN, 1); // executes analogWriteInit early 
  analogWriteSetup(250, 1024); // 250Hz and 1024 steps
}

void loop() {
  analogWrite(PIN, 260); // testing 260 steps
}

This way I can get the right analog setup and the expected output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant