Advertisement
pleasedontcode

prova2 rev_03

Oct 18th, 2023
77
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: prova2
  13.     - Source Code compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2023-10-18 18:41:24
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Wire.h>
  21. #include <Adafruit_SSD1306.h>
  22.  
  23. /****** SYSTEM REQUIREMENT 1 *****/
  24. /* if button is pressed two times within 0.5 seconds, */
  25. /* so display "hello" which scroll from left to right */
  26. /* and then activate the LED for 2 seconds. */
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void displayHello(void);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t myButton_PushButton_PIN_D3 = 3;
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t blueLed_LED_PIN_D2 = 2;
  38.  
  39. /***** DEFINITION OF I2C PINS *****/
  40. const uint8_t display_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
  41. const uint8_t display_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
  42. const uint8_t display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 0x3C;
  43.  
  44. // Global variables
  45. unsigned long buttonPressTime = 0;
  46. int buttonPressCount = 0;
  47.  
  48. Adafruit_SSD1306 display(display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
  49.  
  50. void setup(void)
  51. {
  52.   // put your setup code here, to run once:
  53.  
  54.   pinMode(myButton_PushButton_PIN_D3, INPUT_PULLUP);
  55.   pinMode(blueLed_LED_PIN_D2, OUTPUT);
  56.  
  57.   display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_PIN_SDA_A4, display_SSD1306OledDisplay_I2C_PIN_SCL_A5);
  58.   display.clearDisplay();
  59.   display.setTextSize(2);
  60.   display.setTextColor(WHITE);
  61. }
  62.  
  63. void loop(void)
  64. {
  65.   // put your main code here, to run repeatedly:
  66.  
  67.   // Check if button is pressed
  68.   if (digitalRead(myButton_PushButton_PIN_D3) == LOW)
  69.   {
  70.     // Record the time of button press
  71.     if (buttonPressCount == 0)
  72.     {
  73.       buttonPressTime = millis();
  74.     }
  75.  
  76.     // Increment button press count
  77.     buttonPressCount++;
  78.  
  79.     // Check if button was pressed two times within 0.5 seconds
  80.     if (buttonPressCount == 2 && millis() - buttonPressTime <= 500)
  81.     {
  82.       // Display "hello" scrolling from left to right
  83.       displayHello();
  84.  
  85.       // Activate the LED for 2 seconds
  86.       digitalWrite(blueLed_LED_PIN_D2, HIGH);
  87.       delay(2000);
  88.       digitalWrite(blueLed_LED_PIN_D2, LOW);
  89.  
  90.       // Reset button press count
  91.       buttonPressCount = 0;
  92.     }
  93.   }
  94. }
  95.  
  96. void displayHello(void)
  97. {
  98.   display.clearDisplay();
  99.   display.setCursor(0, 0);
  100.   display.println("hello");
  101.   display.display();
  102.  
  103.   int16_t scrollPos = display.width();
  104.   while (scrollPos >= -display.width())
  105.   {
  106.     display.clearDisplay();
  107.     display.setCursor(scrollPos, 0);
  108.     display.println("hello");
  109.     display.display();
  110.     delay(100);
  111.     scrollPos--;
  112.   }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement