#include #include #include U8G2_SH1106_128X64_NONAME_1_HW_I2C U8G2(U8G2_R0, 5, 4, U8X8_PIN_NONE); int values[120]; // array for sine values int buffer[120]; // buffer array used to shift sine values void initArrays(void){ // fill arrays for (int i = 0; i < 120; i++){ float angle = i * 3; // 3 * 120 = 360 values[i] = (32 + (sin(angle * (M_PI / 180)) * 30)); // values shifted upwards by 32 for easier visualization buffer[i] = values[i]; // initialize buffer with the same values } } void setup(void) { U8G2.begin(); // initialize and clear display initArrays(); // initialize arrays } void loop(void) { // constantly repeating code U8G2.firstPage(); do { U8G2.drawVLine(0, 0, 64); // draw Y-axis U8G2.drawHLine(0, 63, 128); // draw X-axis for (int j = 0 ; j < 120; j++){ values[j] = buffer[j]; // transfer values from buffer to output array U8G2.drawPixel(j+4, values[j]); // draw the sine wave with values from the array shifted 4 pixels to the right } for (int x = 0 ; x < 120; x++){ // loop array via buffer if(x-1 < 0){ buffer[x] = values[119]; } else { buffer[x] = values[x-1]; } } } while ( U8G2.nextPage() ); delay(50); // control scroll speed of the sine wave }