 RF24 radio( 8, 7 );
 
 /* Radio pipe addresses for the 2 nodes to communicate (why LL) ? */
-const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
-
-/* number of clients who are voting */
+const uint64_t pipes[2] = { 0xF0F0F0F0AA, 0xF0F0F0F0BB };
+
+/* Number of clients who are voting */
 uint8_t client_count = 0;
-uint8_t clients[10];
 
 /*
  * function to get a client ID from the ID pool
- * return - 0 when successful
- * return - 1 when no more IDs left
- */
-uint8_t getClientID( uint8_t* id ) {
-  /* increase number of clients */
+ * @return - gives the new generated id
+ */
+uint8_t getNewClientID() {
+  /* Increase number of clients */
   client_count++;
-  /* generate a new ID for the client */
-  *id = client_id + client_count;
-  /* add the generated ID to the list */
-  clients[ client_count - 1 ] = *id;
-  debug_printf( "id %X was generated...", *id );
-  return SUCCESS;
+  /* Generate a new ID for the client */
+  uint8_t id = client_id + client_count;
+  debug_printf( "id %X was generated...", id );
+  return id;
+}
+
+/*
+ * function to switch status LEDS
+ * @param green - the green LED status (HIGH or LOW)
+ * @param yellow - the yellow LED status (HIGH or LOW)
+ * @param flash - to make the chosen LED blink every second
+ */
+void setStatusLEDs( boolean green, boolean yellow, boolean flash ) {
+  boolean green_led_status = green;
+  boolean yellow_led_status = yellow;
+  if ( flash ) {
+    /* Change status every second */
+    green_led_status = green && !((millis() / 1000) % 2);
+    yellow_led_status = yellow && !((millis() /1000) % 2);
+  }
+  /* Set the status of the LEDs */
+  digitalWrite( 10, green_led_status );
+  digitalWrite( 9, yellow_led_status );
 }
 
 /*
  * function to check which button was pressed
- * return - 0 when button was successfuly read
- */
-uint8_t getPressedButton( uint8_t* button ) {
-  *button = NO_BUTTON;
+ * @return - the pressed button or NO_BUTTON
+ */
+uint8_t getPressedButton() {
+  uint8_t button = NO_BUTTON;
   int i;
   /* Go trough all the button and check if one was pressed */
   for ( i = 0; i < BUTTONS_COUNT; i++ )
-    if ( digitalRead( buttons[i] ) ) *button = buttons[i]; else continue;
+    if ( analogRead( buttons[i] ) > 800 ) button = i + 1;
   /* When any of the buttons was pressed */
-  if ( *button != 0 )
-    debug_printf( "button %d was pressed...", *button );
+  if ( button != NO_BUTTON ) debug_printf( "button %d was pressed...", button );
   
-  return SUCCESS;
+  return button;
 }
 
 /*
  * function to receive datapacket
  * return - 0 when reception was successful
  */
-uint8_t receivePacket( boolean timeout ) {
-  int i;
-  for ( i = 0; i < PAYLOAD; i++ ) 
-    rx_message[i] = 0x00;
-  if ( !timeout ) {
-    boolean done = false;
-    while ( !radio.available() );
-    while ( !done )
-      done = radio.read( rx_message, radio.getPayloadSize() );
-  } else {
-    // Wait here until we get a response, or timeout (200ms)
-    unsigned long started_waiting_at = millis();
-    bool timeout = false;
-    while ( !radio.available() && !timeout )
-      if ( millis() - started_waiting_at > 200 )
-        timeout = true;
-
-    // Describe the results
-    if ( timeout ) {
-      debug_printf("Failed, response timed out.\n\r");
-      return TIMEOUT;
-    } else {
-      // Grab the response, compare, and send to debugging spew
-      radio.read( rx_message, radio.getPayloadSize() );
-    }
-  }
-  /* only receive packets which are for us */
-  if ( rx_message[DESTINATION] != role_id ) {
-    debug_printf( "different destination %X...", rx_message[DESTINATION] );
+uint8_t receivePacket( struct Packet rx_packet ) {
+  /* When we don't use timeout */
+  if ( !radio.available() ) return NO_DATA;
+  /* Read the data from the tranceiver */
+  radio.read( &rx_packet, radio.getPayloadSize() );
+  /* Only receive packets which are for us or broadcast packets for all clients */
+  if ( rx_packet.destination != role_id && rx_packet.destination != client_all_id ) {
+    debug_printf( "different destination %X source %X...", rx_packet.destination, rx_packet.source );
     return WRONG_DESTINATION;
   }
-  debug_printf( "source %X...", rx_message[SOURCE] );
+  debug_printf( "source %X...", rx_packet.source );
   return SUCCESS;
 }
 

/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
 Edit by (C) 2012 S. Kuusik <silver.kuusik@gmail.com>

  /* optionally, increase the delay(1) between retries(2) & # of retries */
  radio.setRetries( 15, 15 );

  /* Optionally, reduce the payload size, seems to improve reliability */
  radio.setPayloadSize( PAYLOAD );
  radio.setAutoAck( true );
  radio.setDataRate( RF24_2MBPS );
