 
 const int analogInPin = I0; 
 
+uint16_t connection_interval = 798;
+uint16_t slave_latency = 0;
+uint16_t sampling_rate = 1;
+
 int sensorValue = 200;
 int buffer_limit = 19;
-int sleep_time = 1000;
+unsigned long sleep_time = 1000000;
 
 void printData(aci_evt_t * aci_evt) {
 	int i = 0;

	
	if (isChannelOpen())
	{
		Serial.println("Channel open");
		handleCommands();
		if(checkTransmissionCriteria()) {
			sendData();
		}
	}

	delay(sleep_time);
}


				break;
	 	    case ACI_EVT_DATA_RECEIVED:
		        Serial.println(F("DATA RECEIVED"));
		        // Serial.print(F("Pipe #: 0x"));
		        // Serial.println(aci_evt->params.data_received.rx_data.pipe_number, HEX);
		        
				uint16_t value;
		        switch(aci_evt->params.data_received.rx_data.pipe_number) {
		        	case PIPE_CONNECTIONCONTROL_CONNECTIONINTERVAL_RX_ACK_AUTO:
		        		Serial.print(F("CONNECTION_INTERVAL: "));
		        		// printData(aci_evt);

		        		// Two bytes
 						// big-endian !!!!
						value = aci_evt->params.data_received.rx_data.aci_data[1] + ((uint16_t)aci_evt->params.data_received.rx_data.aci_data[0] << 8);
						connection_interval = value;
		        		Serial.println(value);
		        		break;
		        	case PIPE_CONNECTIONCONTROL_SLAVELATENCY_RX_ACK_AUTO:
		        		Serial.print(F("SLAVELATENCY: "));
		        		// printData(aci_evt);

		        		// One byte
 						// big-endian !!!!
						value = aci_evt->params.data_received.rx_data.aci_data[0];
						slave_latency = value;
		        		Serial.println(value);
		        		break;	
		        	case PIPE_CONNECTIONCONTROL_SAMPLINGRATE_RX_ACK_AUTO:
		        		Serial.print(F("SAMPLING_RATE: "));
		        		// printData(aci_evt);
						
						// 4 Bytes
 						// big-endian !!!!
 						if(aci_evt->len - 2 > 1) {
							value = aci_evt->params.data_received.rx_data.aci_data[1] + ((uint16_t)aci_evt->params.data_received.rx_data.aci_data[0] << 8);
 						} else {
							value = aci_evt->params.data_received.rx_data.aci_data[0];
 						}
						sampling_rate = value;
		        		Serial.println(value);

						Serial.print(F("SLEEPING_TIME: "));
						sleep_time = ((1/ (double) sampling_rate) * 1000000);
		        		Serial.println(sleep_time);
		        		break;
		        	case PIPE_CONNECTIONCONTROL_BUFFERLIMIT_RX_ACK_AUTO:
						Serial.print(F("BUFFER_LIMIT: "));
		        		// printData(aci_evt);
						
						// 1 Byte
 						// big-endian !!!!
						value = aci_evt->params.data_received.rx_data.aci_data[0];
						if(value > 0) {
							buffer_limit = value;
		        			Serial.println(value);
						} else {
							Serial.println(F("<invalid>"));
						}
		        		break;
		        	default:
		        		printData(aci_evt);
