Now my problem is I can’t go smaller than a 1 on the delay. I want to switch it faster if I can. Is there anyway to get it to switch at 2-100 kHz? Is there a better way to code this so it switches faster? I’m very new this is my first project and I could really use some help.
I think you can get four of the PWM pins up to 8 MHz . (yes, MEGAHertz) on the UNO by setting the Timer/Counter1 and Timer/Counter 2 registers. The oscillation is done in hardware so you have 100% of the CPU cycles available for other stuff.
How are you wiring the MOSFET? What are the specs on the FET?
I ask because while "ideal" MOSFETs technically have infinite gate resistance and draw no current, in reality they have properties that can make great demands on the circuit driving them. MOSFETs have internal capacitances and require charge to be transferred to turn them on and off. The output of a typical Arduino may be able to switch a small 2N7002 in a SOT23 fairly fast but if you're trying to switch a power MOSFET for controlling a motor (e.g.) you're probably going to need to consider a MOSFET driver IC between the Arduino pin and the gate.
Even then you'll still need to consider the maximum frequency possible and calculate the thermals for the MOSFET and driver. For most MOSFETs the maximum power dissipation Pd occurs due to switching losses, not their Rdson and the faster you switch them, the more power they'll dissipate and the hotter they'll get.
UKHeliBob:
Let's hope that there are no delay()s in it
If only the OP had posted a complete program instead of a snippet ...
Use millis or micros to generate required delays ( its a good practise.)
You can directly write a patch of code into same arduino ide which supports winAVR. WinAVR gives you better control. Atmega processors in arduino uses winavr which is open source.
I was able to get something 70Khz (if I remember correct) of PWM in one of my projects few years ago using winavr code with arduino.
Also you would need mosfet drivers for that high switching frequency. Although it depends on your circuit.