pleasedontcode

Device Controller rev_02

Nov 15th, 2025
208
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: Device Controller
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2025-11-15 14:21:05
  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. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* fix this code   void setup() { */
  24.     /* pinMode(13, INPUT);          pinMode(12, INPUT); */
  25.     /* pinMode(11, OUTPUT);  }    void loop() {    if */
  26.     /* (digitalRead(13) == LOW) digitalWrite(11, HIGH); */
  27.     /* else digitalWrite(11, LOW);    if (digitalRead(12) */
  28.     /* == LOW) */
  29. /****** END SYSTEM REQUIREMENTS *****/
  30.  
  31.  
  32. /* START CODE */
  33.  
  34. // Main sketch for button and MCP3208 integration
  35. #include <EasyButton.h>
  36. #include <MCP3208.h>
  37.  
  38. // Define push button pins
  39. const uint8_t b1_PushButton_PIN_D2 = 2;
  40. const uint8_t b2_PushButton_PIN_D3 = 3;
  41.  
  42. // Define LED output pin
  43. const uint8_t led1_LED_PIN_D4 = 4;
  44.  
  45. // Create MCP3208 ADC instance
  46. MCP3208 adc;
  47.  
  48. // Variables to store ADC readings
  49. uint16_t channel0;
  50. uint16_t channel1;
  51.  
  52. // Create EasyButton instances
  53. EasyButton button1(b1_PushButton_PIN_D2);
  54. EasyButton button2(b2_PushButton_PIN_D3);
  55.  
  56. // Button pressed callback functions
  57. void onButton1Pressed() {
  58.   Serial.println("Button 1 pressed");
  59. }
  60.  
  61. void onButton2Pressed() {
  62.   Serial.println("Button 2 pressed");
  63. }
  64.  
  65. void setup() {
  66.   Serial.begin(115200);
  67.  
  68.   // Initialize button pins
  69.   pinMode(b1_PushButton_PIN_D2, INPUT_PULLUP);
  70.   pinMode(b2_PushButton_PIN_D3, INPUT_PULLUP);
  71.  
  72.   // Initialize LED pin
  73.   pinMode(led1_LED_PIN_D4, OUTPUT);
  74.  
  75.   // Initialize buttons
  76.   button1.begin();
  77.   button2.begin();
  78.  
  79.   // Attach callbacks
  80.   button1.onPressed(onButton1Pressed);
  81.   button2.onPressed(onButton2Pressed);
  82.  
  83.   // Initialize MCP3208
  84.   adc.begin();
  85.   adc.analogReadResolution(12); // set resolution to 12 bits
  86. }
  87.  
  88. void loop() {
  89.   // Read button states
  90.   button1.read();
  91.   button2.read();
  92.  
  93.   // Read ADC channels
  94.   channel0 = adc.analogRead(0);
  95.   channel1 = adc.analogRead(1);
  96.  
  97.   // Example: turn on LED if channel 0 exceeds a threshold
  98.   if (channel0 > 2048) {
  99.     digitalWrite(led1_LED_PIN_D4, HIGH);
  100.   } else {
  101.     digitalWrite(led1_LED_PIN_D4, LOW);
  102.   }
  103.  
  104.   // Optional: print ADC values
  105.   Serial.print("ADC Channel 0: "); Serial.println(channel0);
  106.   Serial.print("ADC Channel 1: "); Serial.println(channel1);
  107.  
  108.   delay(100); // small delay to debounce buttons and reduce serial baud rate load
  109. }
  110.  
  111. /* END CODE */
  112.  
Advertisement
Add Comment
Please, Sign In to add comment