GithubHelp home page GithubHelp logo

esp32_analogwrite's Introduction

I'm looking for active maintainers for this project as I no longer have the time to support it. Please get in touch if you're interested

About

This library provides an analogWrite function polyfill for ESP32 Arduino framework by wrapping the ledc library.

Licensed under the MIT license.

Usage

The library will do all the timer setup and channel selection work behind the scene so you don't have to worry about that.

Fade Example

#include <Arduino.h>
#include <analogWrite.h>

int pin = LED_BUILTIN;
int brightness = 0;
int brightStep = 1;

void setup()
{
}

void loop()
{
  brightness += brightStep;
  analogWrite(pin, brightness);

  if (brightness == 0 || brightness == 255)
  {
    brightStep = -brightStep;
  }
  
  delay(10);
}

Default Value Range

Call the analogWrite function like in standard arduino framework:

analogWrite(LED_BUILTIN, 255); // value range 0-255 so 255 = 100%

Custom Value Range

You can also set the maximum value as third parameter:

analogWrite(LED_BUILTIN, 255, 1023); // value range 0-1023 so 255 = 25%

Timer Resolution

The default timer resolution is set to 13 bits in all the 16 channels, if you want to change that, use the analogWriteResolution function:

analogWriteResolution(10); // set resolution to 10 bits for all pins
analogWriteResolution(LED_BUILTIN, 10); // set resolution to 10 bits for LED pin

PWM Frequency

The default PWM frequency is set to 5000 Hz in all the 16 channels, if you want to change that, use the analogWriteFrequency function:

analogWriteFrequency(10000); // set frequency to 10 KHz for all pins
analogWriteFrequency(LED_BUILTIN, 10000); // set frequency to 10 KHz for LED pin

Please note that both timer resolution and PWM frequency should be calculated to get the expected results, if frequency is not set correctly, the output PWM signal wont be as expected, read more about Supported Range of Frequency and Duty Resolution in the official Espressif documentation website.

esp32_analogwrite's People

Contributors

cewbdex avatar erropix avatar izhanghui avatar ruffo324 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32_analogwrite's Issues

License

Which license covers this library? I'd be glad for MIT, because I reused your example for testing with Travis and I'd like it to stay as example (Our library is licensed under MIT and I would have to write my own library otherwise).

what pins can I use?

I thought the esp32 can use almost all pins for PWM but I made a program that needs 9 pins to analogWrite to. What pins can I use for this? Some are not working. I am using the WiFi library.

Not outputting correct voltage

#include <Arduino.h>
#include <analogWrite.h>

int brightStep = 1;
int brightness = 0;
uint8_t ledR = 34;
uint8_t ledG = 35;
uint8_t ledB = 32;
uint8_t ledW = 33;

void setup()
{

  // Set resolution for a specific pin
  analogWriteResolution(ledR, 12);
  analogWriteResolution(ledG, 12);
  analogWriteResolution(ledB, 12);
  analogWriteResolution(ledW, 12);

  analogWrite(ledR, 255);
  analogWrite(ledG, 255);  
  analogWrite(ledB, 255);
  analogWrite(ledW, 255);
 
}

void loop() {}

This outputs
ledR = 0 = GPIO34
ledG = 0 = GPIO35
ledB = 1.6 V = GPIO32
ledW = 1.6 V = GPIO33

Why?

docs should indicate about pins

I was working nearly half day to pinpoint why some of the my esp32 pins not working. when changing analogwrite to digital it suddenly start working. I think those pins dont support pwm.

How to install your library??

I just download and copy your library to ESP32 arduino library folder. like this : C:\Users\Administrator\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.1\libraries

But I can't find it in Arduino IDE. I really want to use this library. So can you tell me how to install your library? Thank you so much.

FADE EXAMPLE issue

Your fade example on the main page is defining "step", but the variable being used is called 'brightStep'. The example in the "examples' folder is correct - but if someone just does a simple cut-n-paste of the code as shown on the main page it will not compile.

little readme mistake

Hi,
thanks for the great pojekt.
There is a little mistake in the readme. Under the point PWM Frequency you mixt the function names analogWriteFrequency and analogWriteResolution:)

Lucas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.