Fading up LED PWM with fade down on button press. Delay problem

Hi guys, getting annoyed with this now. I want to add a debounce to the switch, but trying to use the example hasnt worked out. Can someone show me the right code to add where?

The idea of the code is to fade up a transistor that has a load of leds on it. However, I want to be able to turn if off while it is still fading up. Thats why i havnt just used for(i=0;i=256;i++); delay(30); .

So basically. Button press > Fade up ... full brightness stop... Button press > Fade down .. Button press>Fade up from where the fade down got to.

Thanks for any help.

int LEDpwmPIN = 9;    // LED connected to digital pin 9
int Switch1 = 8;
int powerup = 0;
int Switch1state = 0;
int PWMfullon = 255;
int PWMfulloff = 0;
int PWMstepping = 5;
int PWMcurrent = 0;
int delaytime = 40;

void setup()  {
  Serial.println("Arduino Connected");

void loop()  { 
  delay(delaytime); //This is just to stop the up/donw LED power being too fast

void switchcheck(){

int PWMcontrollerLED(){
  if(powerup==1 && PWMcurrent != PWMfullon){
    PWMcurrent = PWMcurrent + PWMstepping;
  else if(powerup==0 && PWMcurrent != PWMfulloff){
    PWMcurrent = PWMcurrent - PWMstepping; 

Where does Switch1state get set?

Missing a ( here?


Should this be 'void' instead of 'int'? int PWMcontrollerLED(){