Skip to content

Commit a4cac98

Browse files
committed
Writing text and number together
1 parent 18c0839 commit a4cac98

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

examples/raspberrypi/rp2xxx/src/ssd1306_oled.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ pub fn main() void {
5252
var counter: u8 = 0;
5353
while (true) : (time.sleep_ms(1000)) {
5454
var allocator = fba.allocator();
55+
var temp_buf: [7]u8 = undefined;
56+
const str = std.fmt.bufPrint(&temp_buf, "{s}{}", .{ "Try #", counter }) catch unreachable;
5557
var counter_buf: [80]u8 = undefined;
56-
const text_centered = center(&counter_buf, counter);
58+
const text_centered = center(&counter_buf, str);
5759

5860
const text = font8x8.Fonts.drawAlloc(allocator, text_centered) catch continue;
5961
defer allocator.free(text);
@@ -68,10 +70,7 @@ pub fn main() void {
6870
}
6971
}
7072

71-
fn center(buf: []u8, value: anytype) []u8 {
72-
var temp_buf: [2]u8 = undefined;
73-
const str = std.fmt.bufPrint(&temp_buf, "{}", .{value}) catch unreachable;
74-
73+
fn center(buf: []u8, str: []u8) []u8 {
7574
const to_be_added = @divTrunc(16 - str.len, 2);
7675
@memcpy(buf[0..64], four_rows);
7776
for (0..to_be_added) |i| {

0 commit comments

Comments
 (0)