3 #define MASTER_INT_PIN A2
10 #define SLAVE_ADDRESS 0x0A
12 void i2c_send_handler(void);
13 void button_handler(void);
15 volatile uint8_t dip_sw = 0;
16 volatile bool new_data = false;
20 pinMode(MASTER_INT_PIN, OUTPUT);
21 digitalWrite(MASTER_INT_PIN, LOW);
22 pinMode(INT_PIN, INPUT_PULLUP);
23 pinMode(SW0_PIN, INPUT_PULLUP);
24 pinMode(SW1_PIN, INPUT_PULLUP);
25 pinMode(SW2_PIN, INPUT_PULLUP);
26 pinMode(SW3_PIN, INPUT_PULLUP);
28 attachInterrupt(digitalPinToInterrupt(INT_PIN), button_handler, FALLING);
30 Wire.begin(SLAVE_ADDRESS);
31 Wire.onRequest(i2c_send_handler);
38 uint8_t tmp = digitalRead(SW0_PIN) |
39 (digitalRead(SW1_PIN) << 1) |
40 (digitalRead(SW2_PIN) << 2) |
41 (digitalRead(SW3_PIN) << 3);
46 digitalWrite(MASTER_INT_PIN, HIGH);
48 digitalWrite(MASTER_INT_PIN, LOW);
53 void i2c_send_handler(void)
55 Wire.write((uint8_t *) &dip_sw, sizeof(dip_sw));
58 void button_handler(void)