Advertisement
pleasedontcode

"Light Control+" rev_01

Mar 9th, 2024
106
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: "Light Control+"
  13.     - Source Code compiled for: Arduino Pro Mini 5V
  14.     - Source Code created on: 2024-03-09 22:49:53
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turns on on and off a light using a button */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <OLED-Display-SOLDERED.h> //https://github.com/SolderedElectronics/Soldered-OLED-Display-Arduino-Library
  25.  
  26. /****** SYSTEM REQUIREMENTS *****/
  27. /****** SYSTEM REQUIREMENT 1 *****/
  28. /* Turns on and off a light using a button */
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup();
  32. void loop();
  33. void updateOutputs();
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t Button_PIN_D3 = 3;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t Light_LED_PIN_D2 = 2;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool Button_PIN_D3_rawData = 0;
  44. bool Light_LED_PIN_D2_rawData = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float Light_LED_PIN_D2_phyData = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  51. OLED_Display display;
  52.  
  53. void setup()
  54. {
  55.     // Initialize the OLED display
  56.     if (!display.begin())
  57.     {
  58.         Serial.println("Display init failed!");
  59.         while (1)
  60.             ;
  61.     }
  62.  
  63.     display.clearDisplay();
  64.     display.setTextSize(1);
  65.     display.setTextColor(SSD1306_WHITE);
  66.     display.setCursor(0, 0);
  67.     display.println("Button State: ");
  68.     display.println("Light State: ");
  69.     display.display();
  70.  
  71.     pinMode(Button_PIN_D3, INPUT_PULLUP);
  72.     pinMode(Light_LED_PIN_D2, OUTPUT);
  73. }
  74.  
  75. void loop()
  76. {
  77.     // Read the button state
  78.     Button_PIN_D3_rawData = !digitalRead(Button_PIN_D3);
  79.  
  80.     // Update the light LED state based on the button state
  81.     Light_LED_PIN_D2_rawData = Button_PIN_D3_rawData;
  82.  
  83.     // Refresh the OLED display
  84.     display.setCursor(0, 1);
  85.     display.print(Button_PIN_D3_rawData);
  86.     display.setCursor(0, 2);
  87.     display.print(Light_LED_PIN_D2_rawData);
  88.     display.display();
  89.  
  90.     // Update the physical output
  91.     updateOutputs();
  92.  
  93.     delay(100);
  94. }
  95.  
  96. void updateOutputs()
  97. {
  98.     digitalWrite(Light_LED_PIN_D2, Light_LED_PIN_D2_rawData);
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement