/********* 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: prova2
- Source Code compiled for: Arduino Pro Mini 5V
- Source Code created on: 2023-10-18 18:52:55
- Source Code generated by: Francesco Alessandro
********* Pleasedontcode.com **********/
/********* User code review feedback **********
#### Feedback 1 ####
- If I don't press two times the button within 0.5s, so the button
PressCount will reach in any case the number 2, but I cannot ret
ry again because buttonPressCount will be always > 2.
********* User code review feedback **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
/****** SYSTEM REQUIREMENT 1 *****/
/* if button is pressed two times within 0.5 seconds, */
/* so display "hello" which scroll from left to right */
/* and then activate the LED for 2 seconds. */
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void displayHello(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t myButton_PushButton_PIN_D3 = 3;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t blueLed_LED_PIN_D2 = 2;
/***** 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;
// Global variables
unsigned long buttonPressTime = 0;
int buttonPressCount = 0;
Adafruit_SSD1306 display(display_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
void setup(void)
{
// put your setup code here, to run once:
pinMode(myButton_PushButton_PIN_D3, INPUT_PULLUP);
pinMode(blueLed_LED_PIN_D2, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, display_SSD1306OledDisplay_I2C_PIN_SDA_A4, display_SSD1306OledDisplay_I2C_PIN_SCL_A5);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Check if button is pressed
if (digitalRead(myButton_PushButton_PIN_D3) == LOW)
{
// Record the time of button press
if (buttonPressCount == 0)
{
buttonPressTime = millis();
}
// Increment button press count
buttonPressCount++;
// Check if button was pressed two times within 0.5 seconds
if (buttonPressCount >= 2 && millis() - buttonPressTime <= 500)
{
// Display "hello" scrolling from left to right
displayHello();
// Activate the LED for 2 seconds
digitalWrite(blueLed_LED_PIN_D2, HIGH);
delay(2000);
digitalWrite(blueLed_LED_PIN_D2, LOW);
// Reset button press count
buttonPressCount = 0;
}
else if (millis() - buttonPressTime > 500)
{
// Reset button press count if more than 0.5 seconds have passed
buttonPressCount = 0;
}
}
}
void displayHello(void)
{
display.clearDisplay();
display.setCursor(0, 0);
display.println("hello");
display.display();
int16_t scrollPos = display.width();
while (scrollPos >= -display.width())
{
display.clearDisplay();
display.setCursor(scrollPos, 0);
display.println("hello");
display.display();
delay(100);
scrollPos--;
}
}