#include <Wire.h>
// Set I2C address for the slaves (ATtiny45)
#define SLAVE1_ADDRESS 0x04
#define SLAVE2_ADDRESS 0x05
#define SLAVE3_ADDRESS 0x06
// Define touch pin and Neopixels pin for each sensor
const int touchPin1 = A1;
const int touchPin2 = A2;
const int touchPin3 = A3;
const int neoSquare = PB3;
const int neoTriangle = PB4;
const int neoCircle = PB4;
// Threshold value for touch sensors
const int threshold = 20;
int touchValue1, touchValue2, touchValue3;
void setup() {
Wire.begin();
Serial.begin(115200);
delay(1000); // Give time to bring up the serial monitor
pinMode(neoSquare, OUTPUT);
pinMode(neoTriangle, OUTPUT);
pinMode(neoCircle, OUTPUT);
}
void loop() {
// Read the values from the touch sensors
touchValue1 = touchRead(touchPin1);
touchValue2 = touchRead(touchPin2);
touchValue3 = touchRead(touchPin3);
// Print the values to the serial monitor
Serial.print("Touch 1: ");
Serial.print(touchValue1);
Serial.print(" - Touch 2: ");
Serial.print(touchValue2);
Serial.print(" - Touch 3: ");
Serial.println(touchValue3);
// Send commands to the slaves based on the sensor values
sendCommandToSlave(SLAVE1_ADDRESS, touchValue1);
sendCommandToSlave(SLAVE2_ADDRESS, touchValue2);
sendCommandToSlave(SLAVE3_ADDRESS, touchValue3);
delay(500); // Small delay for stability
}
void sendCommandToSlave(int address, int touchValue) {
Wire.beginTransmission(address);
if (touchValue < threshold) {
Wire.write(1); // Turn on Neopixels if touch is detected
} else {
Wire.write(0); // Turn off Neopixels if no touch
}
Wire.endTransmission();
}