Light Timer

Hello,
I wish to make an LED go to the brightest setting (using PWM, obviously) for an interval of time as to save battery, and then to go down to a lower value of brightness.
Here's the snippet of code that does so:

void loop()
{
digitalRead(buton);
   if(buton == HIGH)
   {
   analogWrite(ledBrightness, 255);
   
   delay(5000);
   } 
   
   else
   {
   analogWrite(ledBrightness, 120);  
   }
}

Any help would be hugely appreciated.

Read the reference: digitalRead() - Arduino Reference
There is a pin number and there is the value that is read. Those are two different things.

An obvious error is there's a delay in
if then clause
but none in else

so if you skip round the loop fast your not going to see much..

Now digital read yes there' s a pin and value, but more importantly switches do not go high - low - high, they bounce so you can get number of problems, its on its off etc.. so your code has no real idea what state it is in ! You need at least some double check of value, but more realistically a debounce routine.

  1. read switch this time
    2 wait a time read switch
    3 if reading equal we think er know where it is goto 5
    4 different values on switch so reset and go back to 1
    5 after time again read if same as at step 3 update variable so we know what we read.
    if not same still bouncing go back to 1

Here’s the snippet of code that does so:

OK.

Any help would be hugely appreciated.

Help with what? You said the code was working.

LOL, I thought the exact same thing as Paul.

What the others are telling you is that you are reading the button but not using the results. Without seeing how buton is declared we can only guess that it is the pin number of the switch.

I've added comments to your code.

void loop()
{
digitalRead(buton); // this reads the pin at buton then does nothing with the result
   if(buton == HIGH) // this is, presumably, comparing a pin value to HIGH. 
   {
   analogWrite(ledBrightness, 255);
   
   delay(5000); // bad idea but a different topic
   } 
   
   else
   {
   analogWrite(ledBrightness, 120);  
   }
}

Here is how I'd fix what you have posted.

void loop()
{
   int buttonState = digitalRead(buton); // buttonState now has the result of the read
   if(buttonState == HIGH) // we use the read result for our condition not the pin number
   {
   analogWrite(ledBrightness, 255);
   
   delay(5000); // bad idea but a different topic
   } 
   
   else
   {
   analogWrite(ledBrightness, 120);  
   }
}

This all is based on the assumption that buton is a pin number. This is why you should post all your code. Buttons and switches often don't work because they are not handled properly in setup() but without all the code. Who knows?