Skip to content

Instantly share code, notes, and snippets.

@samuelbles07
Created May 21, 2019 08:20
Show Gist options
  • Save samuelbles07/54bae75dc4ad93f4aac33de2d6e37bf6 to your computer and use it in GitHub Desktop.
Save samuelbles07/54bae75dc4ad93f4aac33de2d6e37bf6 to your computer and use it in GitHub Desktop.
// 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);
}
}
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);
}
@samuelbles07
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment