void setup() {
// put your setup code here, to run once:
volatile char* dir,*dir_in;
dir=0x30;
*dir=0xFF; //set all pins as output
dir_in=0x107;
*dir_in=0x00; //direction set=input
volatile char* outF,*inK;
volatile char x;
volatile int i=0,j;
outF=0x31;
inK=0x106;
while(1){
x=*inK;
if ((x & 0x01) == 0x01) {
// delay(50); // Simple debounce (optional)
// Confirm the switch is still pressed after debounce
i++;
if (i % 2) {
*outF = 0x01; // Turn on LED1
} else {
*outF = 0x02; // Turn on LED2
}
delay(500); // Avoid multiple presses due to bounce
}
}
}
void loop() {
// put your main code here, to run repeatedly:
}