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: Device Controller
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2025-11-15 14:21:05
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* turn on led1_LED when both b1_PushButton and */
- /* b2_PushButton give the signal */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* fix this code void setup() { */
- /* pinMode(13, INPUT); pinMode(12, INPUT); */
- /* pinMode(11, OUTPUT); } void loop() { if */
- /* (digitalRead(13) == LOW) digitalWrite(11, HIGH); */
- /* else digitalWrite(11, LOW); if (digitalRead(12) */
- /* == LOW) */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- // Main sketch for button and MCP3208 integration
- #include <EasyButton.h>
- #include <MCP3208.h>
- // Define push button pins
- const uint8_t b1_PushButton_PIN_D2 = 2;
- const uint8_t b2_PushButton_PIN_D3 = 3;
- // Define LED output pin
- const uint8_t led1_LED_PIN_D4 = 4;
- // Create MCP3208 ADC instance
- MCP3208 adc;
- // Variables to store ADC readings
- uint16_t channel0;
- uint16_t channel1;
- // Create EasyButton instances
- EasyButton button1(b1_PushButton_PIN_D2);
- EasyButton button2(b2_PushButton_PIN_D3);
- // Button pressed callback functions
- void onButton1Pressed() {
- Serial.println("Button 1 pressed");
- }
- void onButton2Pressed() {
- Serial.println("Button 2 pressed");
- }
- void setup() {
- Serial.begin(115200);
- // Initialize button pins
- pinMode(b1_PushButton_PIN_D2, INPUT_PULLUP);
- pinMode(b2_PushButton_PIN_D3, INPUT_PULLUP);
- // Initialize LED pin
- pinMode(led1_LED_PIN_D4, OUTPUT);
- // Initialize buttons
- button1.begin();
- button2.begin();
- // Attach callbacks
- button1.onPressed(onButton1Pressed);
- button2.onPressed(onButton2Pressed);
- // Initialize MCP3208
- adc.begin();
- adc.analogReadResolution(12); // set resolution to 12 bits
- }
- void loop() {
- // Read button states
- button1.read();
- button2.read();
- // Read ADC channels
- channel0 = adc.analogRead(0);
- channel1 = adc.analogRead(1);
- // Example: turn on LED if channel 0 exceeds a threshold
- if (channel0 > 2048) {
- digitalWrite(led1_LED_PIN_D4, HIGH);
- } else {
- digitalWrite(led1_LED_PIN_D4, LOW);
- }
- // Optional: print ADC values
- Serial.print("ADC Channel 0: "); Serial.println(channel0);
- Serial.print("ADC Channel 1: "); Serial.println(channel1);
- delay(100); // small delay to debounce buttons and reduce serial baud rate load
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment