I need help adding the ultrasonic distance to my Radio.send package. I want to send voltage and distance in the package. I only receive the voltage and not the distance
This is my ultrasonic code.
case ReadVoltage:
{
//Voltage
pinMode(VBAT_ADC_CTL, OUTPUT);
digitalWrite(VBAT_ADC_CTL, LOW);
voltage = analogRead(ADC) * 2;
pinMode(VBAT_ADC_CTL, INPUT);
//Ultrasonic
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin,
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
float distance = duration * 0.034 / 2;
Serial.println(distance);
state = TX;
break;
This is my Radio.send:
case TX:
{
sprintf(txPacket,"%s",“battery_distance: “);
sprintf(txPacket+strlen(txPacket),”%d”,voltage);
sprintf(txPacket+strlen(txPacket),"%2.2g",distance);
turnOnRGB(COLOR_SEND,0);
Serial.printf("\r\nsending packet “%s” , length %d\r\n",txPacket, strlen(txPacket));
Radio.Send( (uint8_t *)txPacket, strlen(txPacket) );
state=LOWPOWER;
break;
}