Advertisement
pleasedontcode

multipleButtonConfig

Dec 3rd, 2023 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 5.57 KB | Source Code | 0 0
  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: multipleButtonConfig
  13.   - Source Code compiled for: Arduino Uno
  14.   - Source Code created on: 2023-12-03 16:14:24
  15.   - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /****** SYSTEM REQUIREMENTS *****/
  20. /****** SYSTEM REQUIREMENT 1 *****/
  21.   /* crea un array di 33 elementi relativo allo stato */
  22.   /* di ogni pulsante. I pulsanti button_x_PushButton */
  23.   /* sono utilizzati per salvare lo stato. */
  24. /****** SYSTEM REQUIREMENT 2 *****/
  25.   /* Se rotarySwitch_Position0 è attivo allora salva i */
  26.   /* pulsanti negli elementi da 0 a 10 dell'array. Se */
  27.   /* rotarySwitch_Position1 è attivo salva i pulsanti */
  28.   /* negli elementi da 11 a 21. Se */
  29.   /* rotarySwitch_Position2 è attivo salva gli elementi */
  30.   /* da 22 a 33. */
  31. /****** END SYSTEM REQUIREMENTS *****/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <Arduino.h>
  35. #include <EasyButton.h>
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40.  
  41. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  42. const uint8_t button_0_PushButton_PIN_D2 = 2;
  43. const uint8_t button_1_PushButton_PIN_D3 = 3;
  44. const uint8_t button_2_PushButton_PIN_D4 = 4;
  45. const uint8_t button_3_PushButton_PIN_D5 = 5;
  46. const uint8_t button_4_PushButton_PIN_D6 = 6;
  47. const uint8_t button_5_PushButton_PIN_D7 = 7;
  48. const uint8_t button_6_PushButton_PIN_D8 = 8;
  49. const uint8_t button_7_PushButton_PIN_D9 = 9;
  50. const uint8_t button_8_PushButton_PIN_D10 = 10;
  51. const uint8_t button_9_PushButton_PIN_D11 = 11;
  52. const uint8_t button_10_PushButton_PIN_D12 = 12;
  53. const uint8_t rotarySwitch_Position0_PIN_D13 = 13;
  54. const uint8_t rotarySwitch_Position1_PIN_A0 = A0;
  55. const uint8_t rotarySwitch_Position2_PIN_A1 = A1;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  58. EasyButton button_0(button_0_PushButton_PIN_D2);
  59. EasyButton button_1(button_1_PushButton_PIN_D3);
  60. EasyButton button_2(button_2_PushButton_PIN_D4);
  61. EasyButton button_3(button_3_PushButton_PIN_D5);
  62. EasyButton button_4(button_4_PushButton_PIN_D6);
  63. EasyButton button_5(button_5_PushButton_PIN_D7);
  64. EasyButton button_6(button_6_PushButton_PIN_D8);
  65. EasyButton button_7(button_7_PushButton_PIN_D9);
  66. EasyButton button_8(button_8_PushButton_PIN_D10);
  67. EasyButton button_9(button_9_PushButton_PIN_D11);
  68. EasyButton button_10(button_10_PushButton_PIN_D12);
  69. EasyButton rotarySwitch_Position0(rotarySwitch_Position0_PIN_D13);
  70. EasyButton rotarySwitch_Position1(rotarySwitch_Position1_PIN_A0);
  71. EasyButton rotarySwitch_Position2(rotarySwitch_Position2_PIN_A1);
  72.  
  73.  
  74. /****** SYSTEM REQUIREMENT 2 *****/
  75. uint8_t buttonStates[33]; // Array to store button states
  76.  
  77. void setup()
  78. {
  79.   pinMode(button_0_PushButton_PIN_D2, INPUT_PULLUP);
  80.   pinMode(button_1_PushButton_PIN_D3, INPUT_PULLUP);
  81.   pinMode(button_2_PushButton_PIN_D4, INPUT_PULLUP);
  82.   pinMode(button_3_PushButton_PIN_D5, INPUT_PULLUP);
  83.   pinMode(button_4_PushButton_PIN_D6, INPUT_PULLUP);
  84.   pinMode(button_5_PushButton_PIN_D7, INPUT_PULLUP);
  85.   pinMode(button_6_PushButton_PIN_D8, INPUT_PULLUP);
  86.   pinMode(button_7_PushButton_PIN_D9, INPUT_PULLUP);
  87.   pinMode(button_8_PushButton_PIN_D10, INPUT_PULLUP);
  88.   pinMode(button_9_PushButton_PIN_D11, INPUT_PULLUP);
  89.   pinMode(button_10_PushButton_PIN_D12, INPUT_PULLUP);
  90.   pinMode(rotarySwitch_Position0_PIN_D13, INPUT_PULLUP);
  91.   pinMode(rotarySwitch_Position1_PIN_A0, INPUT_PULLUP);
  92.   pinMode(rotarySwitch_Position2_PIN_A1, INPUT_PULLUP);
  93.  
  94.   // Set initial button states to HIGH (released)
  95.   for (int i = 0; i < 33; i++)
  96.   {
  97.     buttonStates[i] = HIGH;
  98.   }
  99.  
  100.   // Initialization code goes here
  101. }
  102.  
  103. void loop()
  104. {
  105.   // Main code goes here
  106.  
  107.   // Handle button states based on the requirements
  108.   if (rotarySwitch_Position0.read() == LOW)
  109.   {
  110.     buttonStates[0] = button_0.read();
  111.     buttonStates[1] = button_1.read();
  112.     buttonStates[2] = button_2.read();
  113.     buttonStates[3] = button_3.read();
  114.     buttonStates[4] = button_4.read();
  115.     buttonStates[5] = button_5.read();
  116.     buttonStates[6] = button_6.read();
  117.     buttonStates[7] = button_7.read();
  118.     buttonStates[8] = button_8.read();
  119.     buttonStates[9] = button_9.read();
  120.     buttonStates[10] = button_10.read();
  121.   }
  122.   else if (rotarySwitch_Position1.read() == LOW)
  123.   {
  124.     buttonStates[11] = button_0.read();
  125.     buttonStates[12] = button_1.read();
  126.     buttonStates[13] = button_2.read();
  127.     buttonStates[14] = button_3.read();
  128.     buttonStates[15] = button_4.read();
  129.     buttonStates[16] = button_5.read();
  130.     buttonStates[17] = button_6.read();
  131.     buttonStates[18] = button_7.read();
  132.     buttonStates[19] = button_8.read();
  133.     buttonStates[20] = button_9.read();
  134.     buttonStates[21] = button_10.read();    
  135.   }
  136.   else if (rotarySwitch_Position2.read() == LOW)
  137.   {
  138.     buttonStates[22] = button_0.read();
  139.     buttonStates[23] = button_1.read();
  140.     buttonStates[24] = button_2.read();
  141.     buttonStates[25] = button_3.read();
  142.     buttonStates[26] = button_4.read();
  143.     buttonStates[27] = button_5.read();
  144.     buttonStates[28] = button_6.read();
  145.     buttonStates[29] = button_7.read();
  146.     buttonStates[30] = button_8.read();
  147.     buttonStates[31] = button_9.read();
  148.     buttonStates[32] = button_10.read();  
  149.   }
  150. }
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement