int Motor = 16; // declaramos las variables de tipo entero int Joystick = 32; uint16_t MotorDutyCycle; const int MotorPWMFreq = 5000; /* 5 KHz */ const int MotorPWMChannel = 0; const int MotorPWMResolution = 12; const int MOTOR_MAX_DUTY_CYCLE = (int)(pow(2, MotorPWMResolution) - 1); const int ADC_RESOLUTION = 4095; /* 12-bit */ void setup() { /* Initialize Serial Port */ Serial.begin(115200); /* Initialize PWM Channels with Frequency and Resolution */ ledcSetup(MotorPWMChannel, MotorPWMFreq, MotorPWMResolution); /* Attach the LED PWM Channel to the GPIO Pin */ ledcAttachPin(Motor, MotorPWMChannel); } void loop() { int Jspeed; int Mspeed; Jspeed = analogRead(Joystick); // Guardamos la lectura analogica en la variable (valor_entrada_analógica) // Mspeed =map(Jspeed,0, 1023,0,255); // guardamos el mapeo en la variable (valor salida) /* Read Analog Input from three ADC Inputs */ MotorDutyCycle = Jspeed; /* Map ADC Output to maximum possible dutycycle */ MotorDutyCycle = map(MotorDutyCycle, 0, ADC_RESOLUTION, 0, MOTOR_MAX_DUTY_CYCLE); /* Set PWM Output of Channel with desired dutycycle */ ledcWrite(MotorPWMChannel, MotorDutyCycle); Serial.println("MOTOR: "); Serial.print(MotorDutyCycle); Serial.print(" -- "); Serial.print("\n"); delay(1000); }