PWM di pin GPIO-14 NodeMCU
from machine import Pin, PWM
from time import sleep
frequency = 1000
led = PWM(Pin(14), frequency)
while True:
for duty_cycle in range(0, 1024):
led.duty(duty_cycle)
sleep(0.005)
PWM output dengan value dari pin analog
from machine import Pin, ADC, PWM #importing Pin and ADC class
from time import sleep #importing sleep class
potentiometer = ADC(0) #creating potentiometer object
frequency = 1000
PWM_Pin = PWM(Pin(14), frequency)
while True:
potentiometer_value = potentiometer.read() #reading analog pin
print(potentiometer_value) #printing the ADC value
//potentiometer_voltage = potentiometer.read() * 3.3 / 4095 #voltage value
PWM_Pin.duty(potentiometer_value) # max value 1023
sleep(0.25)
from time import sleep #importing sleep class
potentiometer = ADC(0) #creating potentiometer object
frequency = 1000
PWM_Pin = PWM(Pin(14), frequency)
while True:
potentiometer_value = potentiometer.read() #reading analog pin
print(potentiometer_value) #printing the ADC value
//potentiometer_voltage = potentiometer.read() * 3.3 / 4095 #voltage value
PWM_Pin.duty(potentiometer_value) # max value 1023
sleep(0.25)