 }
 
 void loop () {
-	white = digitalRead(WHITE);
-	red = digitalRead(RED);
-	if(white == LOW && white_state == 0) {
+	white = analogRead(WHITE);
+	red = analogRead(RED);
+	if(white < 500 && white_state == 0) {
 		white_state = 1;
 		txButton(BUTTON_WHITE);
 		delay(200);
 	}
-	else if(white == HIGH && white_state == 1) {
+	else if(white > 500 && white_state == 1) {
 		white_state = 0;
 	}
-	if(red == LOW && red_state == 0) {
+	if(red < 500 && red_state == 0) {
 		red_state = 1;
 		txButton(BUTTON_RED);
 		delay(200);
 	}
-	else if(red == HIGH && red_state == 1) {
+	else if(red > 500 && red_state == 1) {
 		red_state = 0;
 	}
 	delay(50);

	Serial.print("#"); Serial.print(id); Serial.print(":");
	Serial.print(button);
	Serial.println(";");
}

#include <SoftwareSerial.h>
#define SSerialRX        4  //Serial Receive pin
#define SSerialTX        3  //Serial Transmit pin
#define SSerialTxControl 5
SoftwareSerial RS485(SSerialRX, SSerialTX); // RX, TX
#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define WHITE 1
#define RED 0
#define ID0 12
#define ID1 13
#define BUTTON_WHITE 0
#define BUTTON_RED 1

uint16_t white = 0, red = 0;
uint8_t white_state = 0, red_state = 0;
uint8_t id = 0;


