Skip to content

Commit c6415b9

Browse files
committed
Changes conversion function
* Changes initiation check * Removes extraneous const
1 parent 9e4e186 commit c6415b9

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

examples/Example4_OLED_Distance/Example4_OLED_Distance.ino

+6-7
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,16 @@ void setup()
4848
Serial.println("Ultrasonic Distance Sensor - Example 4 - Distance on an OLED Display");
4949
Wire.begin();
5050

51-
if (myOLED.begin() == false) {
51+
while (myOLED.begin() == false) {
5252
Serial.println("OLED sensor not connected, check your wiring and I2C address!");
53-
while (1)
54-
;
53+
delay(1000);
5554
}
56-
if (myUltrasonic.begin(deviceAddress) == false)
55+
while(myUltrasonic.begin(deviceAddress) == false)
5756
{
5857
Serial.println("Ultrasonic sensor not connected, check your wiring and I2C address!");
59-
while(1)
60-
;
58+
delay(1000);
6159
}
60+
6261
String hello = "Hello, Ultrasonic!";
6362

6463
// This is good for the narrow OLED screen. You can also just remove this
@@ -82,7 +81,7 @@ void loop()
8281
myUltrasonic.getDistance(distance);
8382

8483
// Convert distance, which is an integer, to char so that we can print it.
85-
itoa(distance, distanceBuff, 10);
84+
snprintf(distanceBuff, 4, "%d", distance);
8685

8786
// Put the distance in a string so that we can also print "mm".
8887
distanceStr = distanceBuff;

src/sfeQwiicUltrasonic.h

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const uint8_t kQwiicUltrasonicDefaultAddress = 0x2F;
2121
const uint8_t kQwiicI2CAddressMin = 0x08;
2222
const uint8_t kQwiicI2CAddressMax = 0x7F;
2323
// Available I2C addresses of the Qwiic Ultrasonic
24-
const uint8_t kQwiicUltrasonicDefaultAddress = 0x2F;
2524
const uint8_t kQwiicUltrasonicAddresses[] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
2625
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F};
2726
const uint8_t kQwiicUltrasonicNumAddresses = sizeof(kQwiicUltrasonicAddresses) / sizeof(uint8_t);

0 commit comments

Comments
 (0)