/********* 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: "Digital Control"
- Source Code compiled for: Arduino Nano
- Source Code created on: 2024-02-04 14:53:56
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* On LCD1602_LCD1602I2C_I2C display on the first */
/* line: CZERWONY "+resultC" on the second line: */
/* ZOLTY "+resultZ" the initial value of resultC and */
/* resultZ is 10000. */
/****** SYSTEM REQUIREMENT 2 *****/
/* Holding down the czerwonyP_PushButton subtracts */
/* from the resultC. Holding down the */
/* zielonyP_PushButton subtracts from the resultZ. */
/* Holding time subtracts value: 1 second subtracts */
/* randomly 10 to 40, until the button is released. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/evert-arias/EasyButton
#include //https://github.com/marcoschwartz/LiquidCrystal_I2C
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void onPressedForDuration(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t PUSHBUTTON_PIN_D2 = 2;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t L1_LED_PIN_D3 = 3;
const uint8_t B_ACTIVEBUZZER_OUTPUT_PIN_D4 = 4;
/***** DEFINITION OF I2C PINS *****/
const uint8_t LCD_I2C_PIN_SDA_A4 = A4;
const uint8_t LCD_I2C_PIN_SCL_A5 = A5;
const uint8_t LCD_I2C_SLAVE_ADDRESS = 0x27;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool L1_LED_PIN_D3_rawData = false;
bool B_ACTIVEBUZZER_OUTPUT_PIN_D4_rawData = false;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
int resultC = 10000;
int resultZ = 10000;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
EasyButton pushButton(PUSHBUTTON_PIN_D2);
LiquidCrystal_I2C lcd(LCD_I2C_SLAVE_ADDRESS, 20, 4); // Initialize LiquidCrystal_I2C object
void setup()
{
// put your setup code here, to run once:
lcd.begin(20, 4); // Initialize the LCD
lcd.backlight();
pinMode(PUSHBUTTON_PIN_D2, INPUT_PULLUP);
pinMode(L1_LED_PIN_D3, OUTPUT);
pinMode(B_ACTIVEBUZZER_OUTPUT_PIN_D4, OUTPUT);
pushButton.begin();
pushButton.onPressedFor(2000, onPressedForDuration);
}
void loop()
{
// put your main code here, to run repeatedly:
pushButton.read();
updateOutputs(); // Refresh output data
// Display values on LCD
lcd.setCursor(0, 0);
lcd.print("CZERWONY ");
lcd.print(resultC);
lcd.setCursor(0, 1);
lcd.print("ZOLTY ");
lcd.print(resultZ);
}
void updateOutputs()
{
digitalWrite(L1_LED_PIN_D3, L1_LED_PIN_D3_rawData);
digitalWrite(B_ACTIVEBUZZER_OUTPUT_PIN_D4, B_ACTIVEBUZZER_OUTPUT_PIN_D4_rawData);
}
void onPressedForDuration()
{
// Subtract from resultC
while (pushButton.isPressed())
{
resultC--;
delay(random(1000, 4000)); // Random delay between 1 and 4 seconds
}
// Subtract from resultZ
while (pushButton.isReleased())
{
resultZ--;
delay(random(1000, 4000)); // Random delay between 1 and 4 seconds
}
}