LED Brightness Control with TFT

So I've been playing around with one of Adafruit's TFT displays, and I've been working on a menu that controls some functions for an LED, such as flashing frequency and brightness. I have gotten the LED to flash and I can control it's ON/OFF ability, but I'm looking to change the brightness of it now. I have found many pushbutton examples of code for selecting different brightness levels, which is exactly what I am looking for, however I am using the touchscreen instead of a pushbutton. The pushbutton code uses buttonState, and I am not sure if I need to use that too. I have tried using digitalWrite and analogWrite to control the brightness of the led using preset values, but the LED just seems to randomly flash and tweak out. Below is what I have been trying to adapt.

if ((p.x > 110) && (p.x < 235)) {
if ((p.y > 5) && (p.y < 95)) {
ledMode = ledMode + 1;
if (ledMode == 5) {
ledMode = 1;
}
}
}
if (ledMode == 1)
{
digitalWrite(led, LOW);
}

else if (ledMode == 2)
{
analogWrite(led, 64);
}

else if (ledMode == 3)
{
analogWrite(led, 128);
}

else (ledMode == 4);
{
digitalWrite(led, HIGH);
}

If anyone has any tips as to how to do this a little more simpler, or has done this in the past, I would appreciate any help! I have been working with Arduino for about a month, so I'm still a noob at this, my apologies, lol.

Regards,

  • GSTEC