Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: **Button Control**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-22 15:34:59
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 20*4 lcd i2c, ds3231 rtc, 3 switches to 3 outputs, */
- /* 1 switch to pump motor with low level and high */
- /* level input controls */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <RTClib.h>
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Constants for pin assignments
- const int switch1Pin = 2; // Pin for switch 1
- const int switch2Pin = 3; // Pin for switch 2
- const int switch3Pin = 4; // Pin for switch 3
- const int pumpSwitchPin = 5; // Pin for pump control
- const int output1Pin = 6; // Output pin for switch 1
- const int output2Pin = 7; // Output pin for switch 2
- const int output3Pin = 8; // Output pin for switch 3
- // Create LCD object
- LiquidCrystal_I2C lcd(0x27, 20, 4); // Change the address according to your LCD
- // Create RTC object
- RTC_DS3231 rtc;
- // Create EasyButton objects
- EasyButton button1(switch1Pin);
- EasyButton button2(switch2Pin);
- EasyButton button3(switch3Pin);
- EasyButton pumpButton(pumpSwitchPin);
- void setup(void)
- {
- // Initialize the LCD
- lcd.begin(20, 4);
- lcd.backlight();
- lcd.print("System Init...");
- // Initialize the RTC
- if (!rtc.begin()) {
- lcd.print("RTC not found!");
- while (1);
- }
- // Initialize buttons
- button1.begin();
- button2.begin();
- button3.begin();
- pumpButton.begin();
- // Set pin modes for outputs
- pinMode(output1Pin, OUTPUT);
- pinMode(output2Pin, OUTPUT);
- pinMode(output3Pin, OUTPUT);
- pinMode(pumpSwitchPin, OUTPUT);
- }
- void loop(void)
- {
- // Update button states
- button1.update();
- button2.update();
- button3.update();
- pumpButton.update();
- // Handle button presses
- if (button1.isPressed()) {
- digitalWrite(output1Pin, HIGH);
- lcd.setCursor(0, 1);
- lcd.print("Output 1 ON ");
- } else {
- digitalWrite(output1Pin, LOW);
- lcd.setCursor(0, 1);
- lcd.print("Output 1 OFF ");
- }
- if (button2.isPressed()) {
- digitalWrite(output2Pin, HIGH);
- lcd.setCursor(0, 2);
- lcd.print("Output 2 ON ");
- } else {
- digitalWrite(output2Pin, LOW);
- lcd.setCursor(0, 2);
- lcd.print("Output 2 OFF ");
- }
- if (button3.isPressed()) {
- digitalWrite(output3Pin, HIGH);
- lcd.setCursor(0, 3);
- lcd.print("Output 3 ON ");
- } else {
- digitalWrite(output3Pin, LOW);
- lcd.setCursor(0, 3);
- lcd.print("Output 3 OFF ");
- }
- // Handle pump control
- if (pumpButton.isPressed()) {
- digitalWrite(pumpSwitchPin, HIGH); // Activate pump
- lcd.setCursor(0, 0);
- lcd.print("Pump ON ");
- } else {
- digitalWrite(pumpSwitchPin, LOW); // Deactivate pump
- lcd.setCursor(0, 0);
- lcd.print("Pump OFF ");
- }
- delay(100); // Small delay to debounce
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement