pleasedontcode

LED Controller rev_01

Nov 15th, 2025
187
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: LED Controller
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2025-11-15 11:56:37
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turn on led1_LED when both b1_PushButton and */
  21.     /* b2_PushButton give the signal */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24.  
  25. /* START CODE */
  26.  
  27. // Include the necessary libraries
  28. #include <EasyButton.h>
  29. #include <MCP3208.h>
  30.  
  31. // Define the push button pins
  32. const uint8_t b1_PushButton_PIN_D2 = 2;
  33. const uint8_t b2_PushButton_PIN_D3 = 3;
  34.  
  35. // Define the LED pin
  36. const uint8_t led1_LED_PIN_D4 = 4;
  37.  
  38. // Create instances of the libraries
  39. EasyButton button1(b1_PushButton_PIN_D2);
  40. EasyButton button2(b2_PushButton_PIN_D3);
  41. MCP3208 adc;
  42.  
  43. void setup() {
  44.   // Initialize serial communication
  45.   Serial.begin(9600);
  46.  
  47.   // Initialize the push buttons as input with pull-up
  48.   pinMode(b1_PushButton_PIN_D2, INPUT_PULLUP);
  49.   pinMode(b2_PushButton_PIN_D3, INPUT_PULLUP);
  50.  
  51.   // Initialize the LED pin as output
  52.   pinMode(led1_LED_PIN_D4, OUTPUT);
  53.  
  54.   // Initialize ADC
  55.   adc.begin(); // default CS pin 10
  56.   adc.analogReadResolution(12); // set ADC resolution to 12 bits
  57. }
  58.  
  59. void loop() {
  60.   // Read the state of the push buttons
  61.   bool button1State = digitalRead(b1_PushButton_PIN_D2) == LOW; // active low
  62.   bool button2State = digitalRead(b2_PushButton_PIN_D3) == LOW; // active low
  63.  
  64.   // Check if both buttons are pressed
  65.   if (button1State && button2State) {
  66.     // Turn on the LED
  67.     digitalWrite(led1_LED_PIN_D4, HIGH);
  68.   } else {
  69.     // Turn off the LED
  70.     digitalWrite(led1_LED_PIN_D4, LOW);
  71.   }
  72.  
  73.   // Read ADC channels if needed for further processing
  74.   uint16_t channel0 = adc.analogRead(0);
  75.   uint16_t channel1 = adc.analogRead(1);
  76.  
  77.   // Optional: send ADC readings to Serial for debugging
  78.   Serial.print("Channel 0 Value: ");
  79.   Serial.println(channel0);
  80.   Serial.print("Channel 1 Value: ");
  81.   Serial.println(channel1);
  82.  
  83.   delay(100); // Small delay to debounce buttons
  84. }
  85.  
  86. /* END CODE */
  87.  
Advertisement
Add Comment
Please, Sign In to add comment