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: LED Controller
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2025-11-15 11:56:37
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* turn on led1_LED when both b1_PushButton and */
- /* b2_PushButton give the signal */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // Include the necessary libraries
- #include <EasyButton.h>
- #include <MCP3208.h>
- // Define the push button pins
- const uint8_t b1_PushButton_PIN_D2 = 2;
- const uint8_t b2_PushButton_PIN_D3 = 3;
- // Define the LED pin
- const uint8_t led1_LED_PIN_D4 = 4;
- // Create instances of the libraries
- EasyButton button1(b1_PushButton_PIN_D2);
- EasyButton button2(b2_PushButton_PIN_D3);
- MCP3208 adc;
- void setup() {
- // Initialize serial communication
- Serial.begin(9600);
- // Initialize the push buttons as input with pull-up
- pinMode(b1_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(b2_PushButton_PIN_D3, INPUT_PULLUP);
- // Initialize the LED pin as output
- pinMode(led1_LED_PIN_D4, OUTPUT);
- // Initialize ADC
- adc.begin(); // default CS pin 10
- adc.analogReadResolution(12); // set ADC resolution to 12 bits
- }
- void loop() {
- // Read the state of the push buttons
- bool button1State = digitalRead(b1_PushButton_PIN_D2) == LOW; // active low
- bool button2State = digitalRead(b2_PushButton_PIN_D3) == LOW; // active low
- // Check if both buttons are pressed
- if (button1State && button2State) {
- // Turn on the LED
- digitalWrite(led1_LED_PIN_D4, HIGH);
- } else {
- // Turn off the LED
- digitalWrite(led1_LED_PIN_D4, LOW);
- }
- // Read ADC channels if needed for further processing
- uint16_t channel0 = adc.analogRead(0);
- uint16_t channel1 = adc.analogRead(1);
- // Optional: send ADC readings to Serial for debugging
- Serial.print("Channel 0 Value: ");
- Serial.println(channel0);
- Serial.print("Channel 1 Value: ");
- Serial.println(channel1);
- delay(100); // Small delay to debounce buttons
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment