Can the brightness of an LED be set without the use of a potentiometer?

Can the brightness of an LED be set without the use of a potentiometer?

I want to change the brightness of an LED with two buttons. The first button turns on the LED but at 50% brightness and when you push the other button momentary the LED go to 100% brightness for as long as the 2nd button is pushed. When the 2nd button is no longer pushed the LED drops back to 50%. If the 1st button is pushed again the LED goes off. below is an example of the code I have modified from other authors.

/* switch
 * 
 * Each time the runninglights pin goes from LOW to HIGH (e.g. because of a push-button
 * press), the runningbrakelights is toggled from LOW to HIGH or HIGH to LOW. 
 *in addition when the other switch (brake) is pushed the LEDs go to full brightness.
 **the runningbrakelights should only be at 1/2 brightness when the brake light is not pushed.
 * There's a minimum delay between toggles to debounce the circuit (i.e. to ignore
 * noise).
 * Scott Thompson
 * November 24, 2015
 */

int brake = 2;
int runningLights = 3;         // the number of the input pin
int runningbrakelights = 9;       // the number of the output pin 9 PWM
int onboardLed = 13;
int state = LOW;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = HIGH;    // the previous reading from the input pin
int buttonState = 0;         // variable for reading the pushbutton status

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  pinMode(runningLights, INPUT);
  pinMode(runningbrakelights, OUTPUT);     // initialize the LED pin as an output:
  pinMode(runningbrakelights, OUTPUT);
  
  pinMode(onboardLed, OUTPUT);              // initialize the pushbutton pin as an input:
  pinMode(brake, INPUT);}

void loop()
{
  digitalWrite(onboardLed,LOW)
  ,reading = digitalRead(runningLights);
    // read the state of the pushbutton value:
  buttonState = digitalRead(brake);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(runningbrakelights, HIGH);
  } else {
    // turn LED off:
    digitalWrite(runningbrakelights, LOW);
  }

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(runningbrakelights, state);

  previous = reading;
}

Thanks for the help and ideas.

Sure. When you get a button press on the button that should make it full brightness, digitalWrite(ledPin, HIGH). When you get a button press on the button that should make it half brightness, analogWrite(ledPin, 127);

This assumes the led is on a pin that supports PWM.

analogWrite(ledPin, 127) is 50% "on", 50% average LED power, not 50% perceived brightness. 50% perceived brightness is about analogWrite(ledPin, 50). Leo..

Wawa: analogWrite(ledPin, 127) is 50% "on", 50% LED current, not 50% brightness. 50% brightness is about analogWrite(ledPin, 50). Leo..

It is 50% average power (100% being 5V across the LED and resistor), not 50% current. This should translate into exactly 50% brightness, of course it's not perceived as 50% due to human eye's almost log response.

Thanks. I knew that, but posted early in the morning before the caffeine kicked in. Post corrected. Leo..