Displaying random number on Nano builtin OLED

Have an arduino Nano V3 with built-in .91"OLED display, trying to get a random number from a dice roll to show on OLED. Using U8g2 library by Oliver. Don't see the code to print the digitalRead number on the OLED screen.
all I have so far:

#include <Arduino.h>
#include <U8g2lib.h>
#ifdef UX8xX8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef UX8xX8_HAVE_HW_I2C
#include <wire.h>
#endif
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, A5,A4, U8X8_PIN_NONE);
long randNumber;
int Button =2;
int buttonState=0;
void setup(void)
{
randomSeed(analogRead(0));
Serial.begin(9600);
pinMode(Button, INPUT);
u8g2.begin();
}
void loop(void) {
buttonState = digitalRead (Button);
if (buttonState ==HIGH){
randNumber = random(1, 7);
delay(100);
Serial.println(randNumber);randNumber = random(1, 7);
delay(100);
Serial.println(randNumber);
delay (1000);
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(0,10, "randNumber"); //does not print desired number
}}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Try

u8g2.drawStr(0,10, String(randNumber));

Sorry I am new to all this...found the "copy for forum" but still have no idea what to do. I am selecting autoformat and then copy and pasting, but??

C:\Users\the_c\Documents\Arduino\NanoIfButton\NanoIfButton.ino: In function 'void loop()':
C:\Users\the_c\Documents\Arduino\NanoIfButton\NanoIfButton.ino:34:43: error: no matching function for call to 'U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C::drawStr(int, int, String)'

                                       ^

In file included from C:\Users\the_c\Documents\Arduino\NanoIfButton\NanoIfButton.ino:2:0:
c:\Users\the_c\Documents\Arduino\libraries\U8g2\src/U8g2lib.h:292:17: note: candidate: u8g2_uint_t U8G2::drawStr(u8g2_uint_t, u8g2_uint_t, const char*)
u8g2_uint_t drawStr(u8g2_uint_t x, u8g2_uint_t y, const char s) { return u8g2_DrawStr(&u8g2, x, y, s); }
^~~~~~~
c:\Users\the_c\Documents\Arduino\libraries\U8g2\src/U8g2lib.h:292:17: note: no known conversion for argument 3 from 'String' to 'const char
'

exit status 1

Compilation error: no matching function for call to 'U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C::drawStr(int, int, String)'Use code tags to format code for the forum

Auto format, use Copy for Forum and paste into a new reply. The code tags will be added for you

Ok. Try

u8g2.drawStr(0,10, String(randNumber).c_str());

Thanks so much for your knowledge and your time and willingness to help! I am really enjoying this forum and peoples willingness to help without judging. I do try to find answers myself, but after days and sometimes weeks, I ask and this forum never fails. At the beginning of this hobby I said many times that I needed someone I could get help with (meaning in person) but this site is the very next best!

Thanks Bob. I thought I did that , but will be more aware next time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.