Printing variable on state change only
hello, have pretty simple question. need view output of several pots on lcd, not in continuous stream, when changes. have example code, i'm embarrassed it's not enough. can use in example me?
code: [select]
boolean previousvalue;
void loop( void )
{
boolean thisvalue;
thisvalue = digitalread( 7 );
if ( thisvalue != previousvalue )
{
// print goes here.
previousvalue = thisvalue;
}
}
a refactored version of code, added timestamp in print show when state change happened.
code: [select]
#define inputpin 7
int previousvalue = low;
void setup()
{
serial.begin(9600);
}
void loop( void )
{
int value = digitalread( inputpin );
if ( value != previousvalue )
{
serial.print(millis());
serial.print(" : ");
serial.println(value);
previousvalue = value;
}
// other things here
}
give try ..
Arduino Forum > Using Arduino > Displays > Printing variable on state change only
arduino
Comments
Post a Comment