Problem with a Function

I am new to Arduino and I have written the following function called shortC that doesn't perform quite as I want.

void shortC(){

do
{
digitalWrite(ledpin, HIGH);

}while (digitalRead(11) == HIGH);

digitalWrite(ledpin, LOW);
}

When it is called I want it to read Pin 11 and if it is High then turn the LED On. Then when Pin 11 goes Low I want it to turn the LED off and continue.

It works BUT it doesn't loop and the rest off the program carries on running. How can I make it loop while Pin 11 is High?

Thanks
Mark

We need to see all of the code, but before you post it, please read Nick Gammon's post on how to properly use this Forum, especially the use of code tags when posting source code.

Thanks for the reply I will look it up later.

I have just found out that my Do ... While command works perfectly when copied into the main loop but doesn't work when in the shortC function.

Like I say I will read up and repost.

Thanks again

I know this is obvious, but are you calling the shortC() function? We need to see all the code.

const uint8_t   pinLED      = 13;
const uint8_t   pinBUTTON   = 11;

const uint8_t   LED_OFF     = LOW;
const uint8_t   LED_ONF     = HIGH;

const uint8_t   BUTTON_UP   = LOW;
const uint8_t   BUTTON_DOWN = HIGH;

void shortC()
{   
    while ( BUTTON_DOWN == digitalRead(pinBUTTON) )
    {
        digitalWrite(pinLED, LED_ON);
    }

    digitalWrite(pinLED, LED_OFF);
}

void loop()
{
    digitalWrite(pinLED, ((BUTTON_DOWN == digitalRead(pinBUTTON)) ? LED_ON : LED_OFF));
//  shortC();
}

void setup()
{
    pinMode(pinLED, OUTPUT);
    pinMode(pinBUTTON, INPUT);
}

Your code doesn't match your description. This does:

void shortC() {
  if (digitalRead(11) == HIGH)
  {
    digitalWrite(ledpin, HIGH);
  }
  while (digitalRead(11) == HIGH);
  digitalWrite(ledpin, LOW);
}

Why do you use a variable name for one pin, but not the other?

How 'bout:
bitWrite(PORTB,5,(bitRead(PORTB,3))); :grin:

outsider:
How 'bout:
bitWrite(PORTB,5,(bitRead(PORTB,3))); :grin:

Fancy footwork, but it doesn't do the sequencing. :wink: