This is the simple example of setting brightness of LED using PWM controller.
This hands-on lab guide is intended for the Beginners.
The user needs to know: Basic knowledge of ESP8266 NodeMCU v.2. ESP8266 Arduino programming, Basic knowledge of I2C Interface. Basic knowledge of I2C programming using Arduino I2C library.
All important information including the address of devices is enclosed in the description of the laboratory. In that scenario, the user should write a program in the Arduino platform which turns on and off LEDs for the specified time 15 seconds. The LEDs brightness can be controlled by setting variable “level” from 0 to 4095.
As a result user can control in cameras program execution.
In the beginning, both cameras must show that all LEDs are off.
Steps
First load an example project, include appropriate libraries and declare variable ledDriver:
#include <Wire.h> #include <PCA9685.h>
Instantiate PWM controler component:
#define PCA9685_ADDRESS 0x40 PCA9685 ledDriver;
or
#define PCA9685_ADDRESS 0x40 PCA9685 ledDriver(PCA9685_ADDRESS);
Initialize properly hardware, we suggest to do it in setup() function:
First, initialize I2C controller and join i2c bus to correct pins of NodeMCU:
... Wire.begin(D1, D2); /* join i2c bus with SDA=D5 and SCL=D4 of NodeMCU */ ...
and then enable PWM controller ( pin /EN of PCA9685 is connected to pin D0 of NodeMCU):
... pinMode( D0, OUTPUT ); // define pin D0 as output digitalWrite( D0, LOW); // enable PWM ...
Turn the desired led to any PWM level from 0 to 4095:
The diodes are numbered from 0 to 3
PWM level 0 means that LED is off and level value 4095 means that diode is full-on.
... ledDriver.setLEDDimmed( number , level); ...
Function setLEDDimmed cannot be used in a loop to give you a pleasant "turning-up" of the LED. This is because each time you set a level for a LED it will calculate random timing intervals for the PWM function in the chip This is done in order to distribute current consumptions of the full-time period.
Write a simple programme which:
Repeat step 5 ten times.
The only way for validation is to check display by the camera. Both cameras must show that LEDs are changing brightness in given periods of time.