Skip to content

Commit

Permalink
Add analogWrite HAL for esp32 and its example (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleveHEX authored May 2, 2019
1 parent 1311e84 commit 59d4c3e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ git:
before_install:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
install:
- arduino --install-library "DHT sensor library","Adafruit Unified Sensor"
- arduino --install-library "DHT sensor library","Adafruit Unified Sensor","ESP32 AnalogWrite"
script:
- build_platform uno
- build_platform esp32
notifications:
email: false
email: false
31 changes: 31 additions & 0 deletions examples/ledFade/ledFade.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
ALKS faded LED example
Example with fading LED.
Source: https://github.com/ERROPiX/ESP32_AnalogWrite/blob/master/examples/ledFade/ledFade.ino
Modified by Kryštof Černý (@CornyjK) @RoboticsBrno
*/

#include <ALKS.h>

int brightStep = 1;
int brightness = 0;

void setup()
{
setupAll();
}

void loop()
{
brightness += brightStep;
if (brightness == 0 || brightness == 255)
{
brightStep = -brightStep;
}

analogWrite(L_RGB_R, brightness);

delay(10);
}
4 changes: 4 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
},
{
"name": "Adafruit Unified Sensor"
},
{
"name": "ESP32 AnalogWrite",
"platforms": "espressif32"
}
]
}
8 changes: 8 additions & 0 deletions src/ALKS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ void setupPiezo()
pinMode(PIEZO2, OUTPUT);
}

void setupAnalog(uint8_t resolution)
{
#ifdef ESP32
analogWriteResolution(resolution);
#endif
}

void setupAll()
{
setupLeds();
setupRgbLed();
setupButtons();
setupPiezo();
setupAnalog(8); // AVR uses 8-bit, so set the same for esp32
}
10 changes: 8 additions & 2 deletions src/ALKS.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ static const uint8_t S5 = 11;

#elif defined(ALKSESP32) // If ALKS ESP32 board variant is selected, do not map pins again

#include <analogWrite.h>

#elif defined(ESP32)

#include <analogWrite.h>

static const uint8_t D0 = 40;
static const uint8_t D1 = 41;
static const uint8_t D2 = 15;
Expand Down Expand Up @@ -137,7 +142,7 @@ static const uint8_t S4 = 19;
static const uint8_t S5 = 21;

#else
#error "Selected unsupported platform/processor!"
#error "Selected unsupported platform/processor!"
#endif

//alias for some pins/peripheries
Expand All @@ -159,4 +164,5 @@ void setupLeds();
void setupRgbLed();
void setupButtons();
void setupPiezo();
void setupAll();
void setupAnalog(uint8_t resolution);
void setupAll();

0 comments on commit 59d4c3e

Please sign in to comment.