Simple Digital I/O Program and Optimization


hey all.. long time reader, first time poster.

i searched forums briefly, didn't find relevant problem. have simple program turns led on when high signal found on separate input signal pin. here code:

code: [select]

int ledpin = 13;                              /* led on pin 13         */
int sigpin = 8;                                /* input on pin 8         */

void setup()
{
 pinmode(ledpin, output);            /* digital pin output */
 pinmode(sigpin, input);               /* digital input pin       */
}

void loop()
{
 digitalwrite(ledpin, low);            /* turn off led           */
 
 /* if receive (high) signal, turn on led */
 while ( digitalread(sigpin) == high )
   digitalwrite(ledpin, high);
   
}



this compiles , runs fine, loop function seems take ridiculously long period of time. there i'm not understanding, or should doing differently? missing?

i had simple if statement in place of while loop, tested while in case.

any , suggestions , criticisms welcome :d

thanks!

the loop() function never exits.   not supposed to.  unlike programming desktop,  microcontroller applications typically run endless loops.

the reason use while instead of if statement if want led function indicator of how low signal on pin 8 active.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Simple Digital I/O Program and Optimization


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums