/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: "Vespa RPM" - Source Code NOT compiled for: Arduino Nano - Source Code created on: 2024-07-19 18:02:49 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* contagiri rmp */ /****** SYSTEM REQUIREMENT 2 *****/ /* display scritta vespa 50 */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include #include #include // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git #include // https://github.com/olikraus/U8g2_for_Adafruit_GFX /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); void displayRPM(int rpm); void displayVespa50(); /***** DEFINITION OF I2C PINS *****/ const uint8_t display_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4; const uint8_t display_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5; const uint8_t display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C; // I2C address for the display /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx; void setup(void) { // Initialize serial communication Serial.begin(9600); // Initialize the display with the I2C address display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS); // Initialize the U8g2_for_Adafruit_GFX library u8g2_for_adafruit_gfx.begin(display); // Show the Adafruit splash screen display.display(); delay(2000); // Clear the display buffer display.clearDisplay(); // Display "Vespa 50" text displayVespa50(); delay(2000); display.clearDisplay(); // Display RPM (example value) displayRPM(3000); delay(2000); display.clearDisplay(); } void loop(void) { // Main code to run repeatedly // Example: Update RPM value int rpm = analogRead(A0); // Read RPM value from analog pin A0 displayRPM(rpm); delay(1000); } void displayRPM(int rpm) { display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0, 0); display.print("RPM: "); display.println(rpm); display.display(); } void displayVespa50() { display.clearDisplay(); display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(0, 0); display.println("Vespa 50"); display.display(); } void testdrawline() { for (int16_t i = 0; i < display.width(); i += 4) { display.drawLine(0, 0, i, display.height() - 1, WHITE); display.display(); delay(1); } for (int16_t i = 0; i < display.height(); i += 4) { display.drawLine(0, 0, display.width() - 1, i, WHITE); display.display(); delay(1); } delay(250); display.clearDisplay(); for (int16_t i = 0; i < display.width(); i += 4) { display.drawLine(0, display.height() - 1, i, 0, WHITE); display.display(); delay(1); } for (int16_t i = display.height() - 1; i >= 0; i -= 4) { display.drawLine(0, display.height() - 1, display.width() - 1, i, WHITE); display.display(); delay(1); } delay(250); display.clearDisplay(); for (int16_t i = display.width() - 1; i >= 0; i -= 4) { display.drawLine(display.width() - 1, display.height() - 1, i, 0, WHITE); display.display(); delay(1); } for (int16_t i = display.height() - 1; i >= 0; i -= 4) { display.drawLine(display.width() - 1, display.height() - 1, 0, i, WHITE); display.display(); delay(1); } delay(250); display.clearDisplay(); for (int16_t i = 0; i < display.height(); i += 4) { display.drawLine(display.width() - 1, 0, 0, i, WHITE); display.display(); delay(1); } for (int16_t i = 0; i < display.width(); i += 4) { display.drawLine(display.width() - 1, 0, i, display.height() - 1, WHITE); display.display(); delay(1); } delay(250); } void testdrawrect(void) { for (int16_t i = 0; i < display.height() / 2; i += 2) { display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, WHITE); display.display(); delay(1); } } void testfillrect(void) { uint8_t color = 1; for (int16_t i = 0; i < display.height() / 2; i += 3) { display.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2); display.display(); delay(1); color++; } } void testdrawcircle(void) { for (int16_t i = 0; i < display.height(); i += 2) { display.drawCircle(display.width() / 2, display.height() / 2, i, WHITE); display.display(); delay(1); } } void testdrawroundrect(void) { for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) { display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, WHITE); display.display(); delay(1); } } void testfillroundrect(void) { uint8_t color = WHITE; for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) { display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color); if (color == WHITE) color = BLACK; else color = WHITE; display.display(); delay(1); } } void testdrawtriangle(void) { for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) { display.drawTriangle(display.width() / 2, display.height() / 2 - i, display.width() / 2 - i, display.height() / 2 + i, display.width() / 2 + i, display.height() / 2 + i, WHITE); display.display(); delay(1); } } void testfilltriangle(void) { uint8_t color = WHITE; for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) { display.fillTriangle(display.width() / 2, display.height() / 2 - i, display.width() / 2 - i, display.height() / 2 + i, display.width() / 2 + i, display.height() / 2 + i, WHITE); if (color == WHITE) color = BLACK; else color = WHITE; display.display(); delay(1); } } void testdrawchar(void) { display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); for (uint8_t i = 0; i < 168; i++) { if (i == '\n') continue; display.write(i); if ((i > 0) && (i % 21 == 0)) display.println(); } display.display(); delay(1); } void testscrolltext(void) { display.setTextSize(2); display.setTextColor(WHITE); display.setCursor(10, 0); display.clearDisplay(); display.println("scroll"); display.display(); delay(1); display.startscrollright(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrollleft(0x00, 0x0F); delay(2000); display.stopscroll(); delay(1000); display.startscrolldiagright(0x00, 0x07); delay(2000); display.startscrolldiagleft(0x00, 0x07); delay(2000); display.stopscroll(); } void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { uint8_t icons[NUMFLAKES][3]; // Initialize for (uint8_t f = 0; f < NUMFLAKES; f++) { icons[f][XPOS] = random(display.width()); icons[f][YPOS] = 0; icons[f][DELTAY] = random(5) + 1; Serial.print("x: "); Serial.print(icons[f][XPOS], DEC); Serial.print(" y: "); Serial.print(icons[f][YPOS], DEC); Serial.print(" dy: "); Serial.println(icons[f][DELTAY], DEC); } while (1) { // Draw each icon for (uint8_t f = 0; f < NUMFLAKES; f++) { display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE); } display.display(); delay(200); // Then erase it + move it for (uint8_t f = 0; f < NUMFLAKES; f++) { display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); // Move it icons[f][YPOS] += icons[f][DELTAY]; // If it's gone, reinit if (icons[f][YPOS] > display.height()) { icons[f][XPOS] = random(display.width()); icons[f][YPOS] = 0; icons[f][DELTAY] = random(5) + 1; } } } } #define LOGO16_GLCD_HEIGHT 16 #define LOGO16_GLCD_WIDTH 16 static const unsigned char PROGMEM logo16_glcd_bmp[] = { B00000000, B11000000, B00000001, B11000000, B00000001, B11000000, B00000011, B11100000, B11110011, B11100000, B11111110, B11111000, B01111110, B11111111, B00110011, B10011111, B00011111, B11111100, B00001101, B01110000, B00011011, B10100000, B00111111, B11100000, B00111111, B11110000, B01111100, B11110000, B01110000, B01110000, B00000000, B00110000 };