Created
May 21, 2019 08:20
-
-
Save samuelbles07/54bae75dc4ad93f4aac33de2d6e37bf6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the number of the LED pin | |
const int ledPin = 15; // 16 corresponds to GPIO16 | |
// setting PWM properties | |
const int freq = 5000; | |
const int ledChannel = 0; | |
const int resolution = 8; | |
void setup(){ | |
// configure LED PWM functionalitites | |
ledcSetup(ledChannel, freq, resolution); | |
// attach the channel to the GPIO to be controlled | |
ledcAttachPin(ledPin, ledChannel); | |
} | |
void loop(){ | |
// increase the LED brightness | |
for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){ | |
// changing the LED brightness with PWM | |
ledcWrite(ledChannel, dutyCycle); | |
delay(15); | |
} | |
// decrease the LED brightness | |
for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){ | |
// changing the LED brightness with PWM | |
ledcWrite(ledChannel, dutyCycle); | |
delay(15); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int ledPin = 15; | |
const int freq = 5000; | |
const int ledChannel = 0; | |
const int resolution = 12; | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(26, INPUT); | |
Serial.begin(115200); | |
ledcSetup(ledChannel, freq, resolution); | |
ledcAttachPin(ledPin, ledChannel); | |
} | |
void loop() { | |
int val = analogRead(26); | |
val = map(val, 0, 4096, 0, 255); | |
Serial.println(val); | |
ledcWrite(ledChannel, val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link RTC library : https://github.com/adafruit/RTClib