pinMode(DS4, INPUT_PULLUP);
pinMode(DS5, INPUT_PULLUP);
pinMode(DS6, INPUT_PULLUP);
pinMode(DS7, INPUT_PULLUP);
pinMode(DS8, INPUT_PULLUP);
}
void loop()
{
int b8 = digitalRead(DS8);
int b7 = digitalRead(DS7);
int b6 = digitalRead(DS6);
int b5 = digitalRead(DS5);
int b4 = digitalRead(DS4);
int b3 = digitalRead(DS3);
int b2 = digitalRead(DS2);
int b1 = digitalRead(DS1);
// Hidupkan LED sesuai dengan tombol yang ditekan
if (b8 == LOW)
{
Serial.write('8');
}
else if (b7 == LOW)
{
Serial.write('7');
}
else if (b6 == LOW)
{
Serial.write('6');
}
else if (b5 == LOW)
{
Serial.write('5');
}
else if (b4 == LOW)
{
Serial.write('4');
}
else if (b3 == LOW)
{
Serial.write('3');
}
else if (b2 == LOW)
{
Serial.write('2');
}
else if (b1 == LOW)
{
Serial.write('1');
}
delay(20);
}
SLAVE
//SLAVE
int led[] = {2, 3, 4, 5, 6, 7, 8, 9};
char message;
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 8; i++)
{
pinMode(led[i], OUTPUT);
}
}
void loop()
{
if (Serial.available())
{
message = Serial.read();
if (message == '1')
{
digitalWrite(led[0], 1);
}
else if (message == '2')
{
digitalWrite(led[1], 1);
}
else if (message == '3')
{
digitalWrite(led[2], 1);
}
else if (message == '4')
{
digitalWrite(led[3], 1);
}
else if (message == '5')
{
digitalWrite(led[4], 1);
}
else if (message == '6')
{
digitalWrite(led[5], 1);
}
else if (message == '7')
{
digitalWrite(led[6], 1);
}
else if (message == '8')
{
digitalWrite(led[7], 1);
}
}
delay(20);
digitalWrite(led[0], 0);
digitalWrite(led[1], 0);
digitalWrite(led[2], 0);
digitalWrite(led[3], 0);
digitalWrite(led[4], 0);
digitalWrite(led[5], 0);
digitalWrite(led[6], 0);
digitalWrite(led[7], 0);
}