Advertisement
pleasedontcode

"Vespa RPM" rev_01

Jul 19th, 2024
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Vespa RPM"
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2024-07-19 18:02:49
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* contagiri rmp */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* display scritta vespa 50 */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <Wire.h>
  27. #include <Adafruit_GFX.h>
  28. #include <Adafruit_SSD1306.h>  // https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
  29. #include <U8g2_for_Adafruit_GFX.h>  // https://github.com/olikraus/U8g2_for_Adafruit_GFX
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void displayRPM(int rpm);
  35. void displayVespa50();
  36.  
  37. /***** DEFINITION OF I2C PINS *****/
  38. const uint8_t display_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
  39. const uint8_t display_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
  40. const uint8_t display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C;  // I2C address for the display
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. #define OLED_RESET 4
  44. Adafruit_SSD1306 display(OLED_RESET);
  45. U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;
  46.  
  47. void setup(void) {
  48.   // Initialize serial communication
  49.   Serial.begin(9600);
  50.  
  51.   // Initialize the display with the I2C address
  52.   display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  53.  
  54.   // Initialize the U8g2_for_Adafruit_GFX library
  55.   u8g2_for_adafruit_gfx.begin(display);
  56.  
  57.   // Show the Adafruit splash screen
  58.   display.display();
  59.   delay(2000);
  60.  
  61.   // Clear the display buffer
  62.   display.clearDisplay();
  63.  
  64.   // Display "Vespa 50" text
  65.   displayVespa50();
  66.   delay(2000);
  67.   display.clearDisplay();
  68.  
  69.   // Display RPM (example value)
  70.   displayRPM(3000);
  71.   delay(2000);
  72.   display.clearDisplay();
  73. }
  74.  
  75. void loop(void) {
  76.   // Main code to run repeatedly
  77.   // Example: Update RPM value
  78.   int rpm = analogRead(A0); // Read RPM value from analog pin A0
  79.   displayRPM(rpm);
  80.   delay(1000);
  81. }
  82.  
  83. void displayRPM(int rpm) {
  84.   display.clearDisplay();
  85.   display.setTextSize(2);
  86.   display.setTextColor(WHITE);
  87.   display.setCursor(0, 0);
  88.   display.print("RPM: ");
  89.   display.println(rpm);
  90.   display.display();
  91. }
  92.  
  93. void displayVespa50() {
  94.   display.clearDisplay();
  95.   display.setTextSize(2);
  96.   display.setTextColor(WHITE);
  97.   display.setCursor(0, 0);
  98.   display.println("Vespa 50");
  99.   display.display();
  100. }
  101.  
  102. void testdrawline() {
  103.   for (int16_t i = 0; i < display.width(); i += 4) {
  104.     display.drawLine(0, 0, i, display.height() - 1, WHITE);
  105.     display.display();
  106.     delay(1);
  107.   }
  108.   for (int16_t i = 0; i < display.height(); i += 4) {
  109.     display.drawLine(0, 0, display.width() - 1, i, WHITE);
  110.     display.display();
  111.     delay(1);
  112.   }
  113.   delay(250);
  114.  
  115.   display.clearDisplay();
  116.   for (int16_t i = 0; i < display.width(); i += 4) {
  117.     display.drawLine(0, display.height() - 1, i, 0, WHITE);
  118.     display.display();
  119.     delay(1);
  120.   }
  121.   for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
  122.     display.drawLine(0, display.height() - 1, display.width() - 1, i, WHITE);
  123.     display.display();
  124.     delay(1);
  125.   }
  126.   delay(250);
  127.  
  128.   display.clearDisplay();
  129.   for (int16_t i = display.width() - 1; i >= 0; i -= 4) {
  130.     display.drawLine(display.width() - 1, display.height() - 1, i, 0, WHITE);
  131.     display.display();
  132.     delay(1);
  133.   }
  134.   for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
  135.     display.drawLine(display.width() - 1, display.height() - 1, 0, i, WHITE);
  136.     display.display();
  137.     delay(1);
  138.   }
  139.   delay(250);
  140.  
  141.   display.clearDisplay();
  142.   for (int16_t i = 0; i < display.height(); i += 4) {
  143.     display.drawLine(display.width() - 1, 0, 0, i, WHITE);
  144.     display.display();
  145.     delay(1);
  146.   }
  147.   for (int16_t i = 0; i < display.width(); i += 4) {
  148.     display.drawLine(display.width() - 1, 0, i, display.height() - 1, WHITE);
  149.     display.display();
  150.     delay(1);
  151.   }
  152.   delay(250);
  153. }
  154.  
  155. void testdrawrect(void) {
  156.   for (int16_t i = 0; i < display.height() / 2; i += 2) {
  157.     display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, WHITE);
  158.     display.display();
  159.     delay(1);
  160.   }
  161. }
  162.  
  163. void testfillrect(void) {
  164.   uint8_t color = 1;
  165.   for (int16_t i = 0; i < display.height() / 2; i += 3) {
  166.     display.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2);
  167.     display.display();
  168.     delay(1);
  169.     color++;
  170.   }
  171. }
  172.  
  173. void testdrawcircle(void) {
  174.   for (int16_t i = 0; i < display.height(); i += 2) {
  175.     display.drawCircle(display.width() / 2, display.height() / 2, i, WHITE);
  176.     display.display();
  177.     delay(1);
  178.   }
  179. }
  180.  
  181. void testdrawroundrect(void) {
  182.   for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
  183.     display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, WHITE);
  184.     display.display();
  185.     delay(1);
  186.   }
  187. }
  188.  
  189. void testfillroundrect(void) {
  190.   uint8_t color = WHITE;
  191.   for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
  192.     display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);
  193.     if (color == WHITE) color = BLACK;
  194.     else color = WHITE;
  195.     display.display();
  196.     delay(1);
  197.   }
  198. }
  199.  
  200. void testdrawtriangle(void) {
  201.   for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) {
  202.     display.drawTriangle(display.width() / 2, display.height() / 2 - i,
  203.                          display.width() / 2 - i, display.height() / 2 + i,
  204.                          display.width() / 2 + i, display.height() / 2 + i, WHITE);
  205.     display.display();
  206.     delay(1);
  207.   }
  208. }
  209.  
  210. void testfilltriangle(void) {
  211.   uint8_t color = WHITE;
  212.   for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) {
  213.     display.fillTriangle(display.width() / 2, display.height() / 2 - i,
  214.                          display.width() / 2 - i, display.height() / 2 + i,
  215.                          display.width() / 2 + i, display.height() / 2 + i, WHITE);
  216.     if (color == WHITE) color = BLACK;
  217.     else color = WHITE;
  218.     display.display();
  219.     delay(1);
  220.   }
  221. }
  222.  
  223. void testdrawchar(void) {
  224.   display.setTextSize(1);
  225.   display.setTextColor(WHITE);
  226.   display.setCursor(0, 0);
  227.  
  228.   for (uint8_t i = 0; i < 168; i++) {
  229.     if (i == '\n') continue;
  230.     display.write(i);
  231.     if ((i > 0) && (i % 21 == 0))
  232.       display.println();
  233.   }
  234.   display.display();
  235.   delay(1);
  236. }
  237.  
  238. void testscrolltext(void) {
  239.   display.setTextSize(2);
  240.   display.setTextColor(WHITE);
  241.   display.setCursor(10, 0);
  242.   display.clearDisplay();
  243.   display.println("scroll");
  244.   display.display();
  245.   delay(1);
  246.  
  247.   display.startscrollright(0x00, 0x0F);
  248.   delay(2000);
  249.   display.stopscroll();
  250.   delay(1000);
  251.   display.startscrollleft(0x00, 0x0F);
  252.   delay(2000);
  253.   display.stopscroll();
  254.   delay(1000);
  255.   display.startscrolldiagright(0x00, 0x07);
  256.   delay(2000);
  257.   display.startscrolldiagleft(0x00, 0x07);
  258.   delay(2000);
  259.   display.stopscroll();
  260. }
  261.  
  262. void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  263.   uint8_t icons[NUMFLAKES][3];
  264.  
  265.   // Initialize
  266.   for (uint8_t f = 0; f < NUMFLAKES; f++) {
  267.     icons[f][XPOS] = random(display.width());
  268.     icons[f][YPOS] = 0;
  269.     icons[f][DELTAY] = random(5) + 1;
  270.  
  271.     Serial.print("x: ");
  272.     Serial.print(icons[f][XPOS], DEC);
  273.     Serial.print(" y: ");
  274.     Serial.print(icons[f][YPOS], DEC);
  275.     Serial.print(" dy: ");
  276.     Serial.println(icons[f][DELTAY], DEC);
  277.   }
  278.  
  279.   while (1) {
  280.     // Draw each icon
  281.     for (uint8_t f = 0; f < NUMFLAKES; f++) {
  282.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
  283.     }
  284.     display.display();
  285.     delay(200);
  286.  
  287.     // Then erase it + move it
  288.     for (uint8_t f = 0; f < NUMFLAKES; f++) {
  289.       display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
  290.       // Move it
  291.       icons[f][YPOS] += icons[f][DELTAY];
  292.       // If it's gone, reinit
  293.       if (icons[f][YPOS] > display.height()) {
  294.         icons[f][XPOS] = random(display.width());
  295.         icons[f][YPOS] = 0;
  296.         icons[f][DELTAY] = random(5) + 1;
  297.       }
  298.     }
  299.   }
  300. }
  301.  
  302. #define LOGO16_GLCD_HEIGHT 16
  303. #define LOGO16_GLCD_WIDTH 16
  304. static const unsigned char PROGMEM logo16_glcd_bmp[] = {
  305.   B00000000, B11000000,
  306.   B00000001, B11000000,
  307.   B00000001, B11000000,
  308.   B00000011, B11100000,
  309.   B11110011, B11100000,
  310.   B11111110, B11111000,
  311.   B01111110, B11111111,
  312.   B00110011, B10011111,
  313.   B00011111, B11111100,
  314.   B00001101, B01110000,
  315.   B00011011, B10100000,
  316.   B00111111, B11100000,
  317.   B00111111, B11110000,
  318.   B01111100, B11110000,
  319.   B01110000, B01110000,
  320.   B00000000, B00110000
  321. };
  322.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement