volatile bool switch1_state = false;
volatile bool switch2_state = false;
volatile bool switch3_state = false;
volatile bool switch4_state = false;
void setup() {
// put your setup code here, to run once:
DDRF|=0xFF;//setting all pins to output
DDRK|=0x00;
PORTK|=0x00;//setting up pull down
}
void switch_1(){
volatile char *pin;
pin = 0x106; // Address of PIN register for PORTK
volatile char x;
x = *pin;
if (x&(1<<PK0)) {
switch1_state = true; // Set the state to "on"
}
if (switch1_state) {
PORTF|=0xFF;
}
}
void switch_2(){
// put your main code here, to run repeatedly:
volatile char *pin;
pin=0x106;
volatile char x;
x=*pin;
if(x&(1<<PK1)){
PORTF^=0xFF;
delay(500);
}
else{
PORTF=0x00;
}
}
void switch_3(){
volatile char *pin,x;
pin=0x106;
x=*pin;
volatile char *out;
out=0x31;
int i;
for(i=0;i<8;i++){
if(x&(1<<PK2)){
*out=(1<<i);
delay(500);
}
}
}
void switch_4(){
volatile char *pin,x;
pin=0x106;
x=*pin;
volatile char *out;
out=0x31;
int i;
for(i=7;i>=0;i--){
if(x&(1<<PK3)){
*out=(1<<i);
delay(500);
}
}
}
void switch_5(){
volatile char *pin,x;
pin=0x106;
x=*pin;
volatile char *out;
out=0x31;
if(x&(1<<PK4)){
*out=(1<<3)|(1<<5)|(1<<7);
}
}
void switch_6(){
volatile char *pin,x;
pin=0x106;
x=*pin;
volatile char *out;
out=0x31;
if(x&(1<<PK5)){
switch2_state=true;
}
if(switch2_state){
*out|=(1<<5);
}
if(x&(1<<PK6)){
switch3_state=true;
}
if(switch3_state){
*out|=(1<<6);
}
if(x&(1<<PK7)){
switch4_state=true;
}
if(switch4_state){
*out|=(1<<7);
}
}
void loop() {
switch_1();
switch_2();
switch_3();
switch_4();
switch_5();
switch_6();
}