/********* 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: "Light Control+" - Source Code compiled for: Arduino Pro Mini 5V - Source Code created on: 2024-03-09 22:49:53 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Turns on on and off a light using a button */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include //https://github.com/SolderedElectronics/Soldered-OLED-Display-Arduino-Library /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Turns on and off a light using a button */ /****** FUNCTION PROTOTYPES *****/ void setup(); void loop(); void updateOutputs(); /***** DEFINITION OF DIGITAL INPUT PINS *****/ const uint8_t Button_PIN_D3 = 3; /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t Light_LED_PIN_D2 = 2; /***** DEFINITION OF OUTPUT RAW VARIABLES *****/ /***** used to store raw data *****/ bool Button_PIN_D3_rawData = 0; bool Light_LED_PIN_D2_rawData = 0; /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/ /***** used to store data after characteristic curve transformation *****/ float Light_LED_PIN_D2_phyData = 0.0; /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/ OLED_Display display; void setup() { // Initialize the OLED display if (!display.begin()) { Serial.println("Display init failed!"); while (1) ; } display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.println("Button State: "); display.println("Light State: "); display.display(); pinMode(Button_PIN_D3, INPUT_PULLUP); pinMode(Light_LED_PIN_D2, OUTPUT); } void loop() { // Read the button state Button_PIN_D3_rawData = !digitalRead(Button_PIN_D3); // Update the light LED state based on the button state Light_LED_PIN_D2_rawData = Button_PIN_D3_rawData; // Refresh the OLED display display.setCursor(0, 1); display.print(Button_PIN_D3_rawData); display.setCursor(0, 2); display.print(Light_LED_PIN_D2_rawData); display.display(); // Update the physical output updateOutputs(); delay(100); } void updateOutputs() { digitalWrite(Light_LED_PIN_D2, Light_LED_PIN_D2_rawData); }