Arduino fan controller conundrum

I am making a fan controller that can be controlled by a reostat, or anything that can define an analog signal. My problem is that when I try to add a read of any kind on pins the fan stops working. I have it hooked up to a TIP120, and when it is just outputting signal it works like a charm on my old repurposed computer fan. The problem occurs when I try to use a potentiometer in an analog read. This completes some oddity which causes the entire thing to screw all and stop it like a heart attack. Below I will list the coding that I was trying to scavange from/combine with to make the fan interval speed run. I am using an idea that I have tried and proven of using a similar process to light up an LED and make it blink with different frequencies/brightnesses.

This code below here is the code that I found worked, and I pulled it offline. This is what allowed me to run a fan in the first place. Short and simple. Could have made it myself, but I decided it was quicker to ctrl+C/ctrl+P

// Define which pin to be used to communicate with Base pin of TIP120 transistor
int TIP120pin = 3; //for this project, I pick Arduino's PMW pin 11
void setup()
{
pinMode(TIP120pin, OUTPUT); // Set pin for output to control TIP120 Base pin
analogWrite(TIP120pin, 255); // By changing values from 0 to 255 you can control motor speed
}

void loop()
{
}

This is the LED code that I am trying to salvage from. I normally comment more in programs at least I try to, but these programs are short enough that they should be easily interpreted.

int led = 9;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int pot = analogRead(A0);
  int lumins = 257 - pot / 4;
  int reverse = 1025 - pot;
  Serial.println(pot);
  delay(20);
  analogWrite(led, LOW);
  delay(reverse);
  analogWrite(led, lumins);
  delay(reverse);
}

in here you will see some of the solutions that I have tried to improve the probability of it working. I thought at first if my sample rate was too slow and interferring with the writing, but I found that not to be the case. This on its own did stop the analog write, but it was not the only thing that caused a complete halt in the process. If I assigned a pin as an input this too would kill the fan.

int logic = 3;

void setup(){
  //Serial.begin(115200);



}
void loop(){
    pinMode(logic, OUTPUT);
  analogWrite(logic, A0 / 4);
    pinMode(A0, INPUT);
  analogRead(A0);

analogRead has to be read in a variable like pot = analogread(0);
A0 is constant referring to the pin number, like “0” , it is not the voltage of that pin.

void loop(){
   int x;
   pinMode(logic, OUTPUT);
    x = analogRead(A0);
   analogWrite(logic, x / 4);
 //  pinMode(A0, INPUT);   //default is input already
  }

didn't work

    pinMode(logic, OUTPUT);
  analogWrite(logic, A0 / 4);
    pinMode(A0, INPUT);
  analogRead(A0);

Why are you doing pinMode() in loop? The mode of the pin isn't changing, is it?

Setting the mode of an analog pin is NOT possible. They are INPUT only.

Post the code you are ACTUALLY using. Post the serial output, if you actually get any.

It wasn't originally, but when the analog in wasn't doing anything I figured I would check. This is just one of the many loop around works that I have tried, but i can't seem to get it to read whether or not I am using it in the setup or loop without killing the output. I never had this problem with the LEDs.

It is solved for now, I had completely cannibalized my LED program, and I am using it as a PWM for my fan. Now I have reconfigure it to run with a touch sensor. Here is the newish code that I am running with.

int led = 9;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int pot = analogRead(A0);
  int lumins = 257 - pot / 4;
  int reverse = 10 - pot / 100;
  Serial.println(pot);
  
  analogWrite(led, LOW);
  delay(reverse);
  analogWrite(led, 255);
  delay(reverse);
}