// GFS_button 3/5/25
// this is NOT beginner code
// written for Uno Rev 3, uses port register read and mask of board pin 7
// for https://forum.arduino.cc/t/simulator-which-one-is-better/1359552/10
const byte buttonPin = 7; // PIND bit 7
byte pin7history = 0xFF;
void setup()
{
Serial.begin( 115200 );
Serial.println( F( "\n\nButton\n " ));
pinMode( buttonPin, INPUT_PULLUP );
}
void button()
{
static byte prevMillis = 0xFF;
if ( prevMillis != (byte) millis())
{
pin7history = pin7history << 1;
pin7history += (( PIND & 0x80 ) ? 1 : 0 );
prevMillis = (byte) millis();
}
}
void loop()
{
button();
switch ( pin7history )
{
case 0x7F :
Serial.print( F( "button release " ));
Serial.println( millis());
pin7history = 0xFF;
break;
case 0x80 :
Serial.print( F( "button press " ));
Serial.println( millis());
pin7history = 0;
break;
}
}