Hello, I am new here. I am trying to make a background sound alarm that shows the time on the oled display and makes noise when it is a certain time. I am on the first part which is getting the oled display to show time but i do not know how since our teacher never taught us how to use the oled display. I tried searching for videos on how one writes a program that will project time on the display but none of them are for arduino grove specifically and require extra parts not given with the grove kit so i can't use them. How do i write code that will display time?
There are probably tens of thousands of examples. The way the forum works is you do your best, and when you get stuck, we can help. We expect a wiring diagram (photo of hand drawn is fine) and all code in code tags after being auto formatted. I find the best approach is to look at the code examples for a library that sounds like it gives me what I want. Search the library manager for oled. I got 32 pages of matches.
I happened to have a sketch for Grove beginner kit. You need to install the library "U8g2" by Oliver.
/*
Test sketch for Grove 0.96" OLED screen.
*/
#include <Arduino.h>
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_F_HW_I2C oled(U8G2_R2, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // High speed I2C
// U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); //Low speed I2C
unsigned fontHeight;
void setup(void)
{
oled.begin();
}
unsigned line_pos (byte lineNum)
{
return (lineNum+1) * fontHeight - 4;
}
void loop(void)
{
oled.clearBuffer(); // clear the internal memory
// choose a suitable font for 4 lines
//oled.setFont(u8g2_font_helvR12_tr); // proportional spaced
oled.setFont(u8g2_font_crox2c_mr); // monospace, 24 chars per line
fontHeight = 16;
oled.drawStr(0,line_pos(0),"Hello World!"); // write something to the internal memory
oled.drawStr(0,line_pos(1),"[ My line 2");
oled.drawStr(0,line_pos(2),"[_My line 3");
oled.drawStr(0,line_pos(3),"12345678901234567890");
oled.sendBuffer(); // transfer internal memory to the display
delay(1000);
}
