Advertisement
pleasedontcode

"Arduino Setup" rev_02

Jan 1st, 2024
91
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: "Arduino Setup"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-01-01 18:25:40
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Send midi data */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* Write code that records data from a potentiometer */
  23.     /* onto an SD card. The data will be saved in a text */
  24.     /* file */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Arduino.h>
  29. #include <SPI.h>
  30. #include <EasyButton.h>
  31. #include <SdFat.h>
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t Btn1_PushButton_PIN_D2 = 2;
  39.  
  40. /***** DEFINITION OF ANALOG INPUT PINS *****/
  41. const uint8_t Pot1_Potentiometer_Vout_PIN_A0 = A0;
  42.  
  43. /***** DEFINITION OF SPI PINS *****/
  44. const uint8_t Sdrw_SDCardModule_SPI_PIN_MOSI_D11 = 11;
  45. const uint8_t Sdrw_SDCardModule_SPI_PIN_MISO_D12 = 12;
  46. const uint8_t Sdrw_SDCardModule_SPI_PIN_SCLK_D13 = 13;
  47. const uint8_t Sdrw_SDCardModule_SPI_PIN_CS_D10 = 10;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. EasyButton button(Btn1_PushButton_PIN_D2, true, false); // Initialize the EasyButton object with the button pin
  51. SdFat sd; // Initialize the SdFat library object
  52.  
  53. void setup(void)
  54. {
  55.     // put your setup code here, to run once:
  56.     Serial.begin(9600);
  57.  
  58.     pinMode(Btn1_PushButton_PIN_D2, INPUT_PULLUP);
  59.     pinMode(Pot1_Potentiometer_Vout_PIN_A0, INPUT);
  60.  
  61.     pinMode(Sdrw_SDCardModule_SPI_PIN_CS_D10, OUTPUT);
  62.     // start the SPI library:
  63.     SPI.begin();
  64.  
  65.     button.begin(); // Initialize the button object
  66.     button.onPressed([]() {
  67.         // Button has been pressed callback function
  68.         Serial.println("Button has been pressed");
  69.     });
  70.  
  71.     if (!sd.begin(Sdrw_SDCardModule_SPI_PIN_CS_D10, SPI_FULL_SPEED)) {
  72.         // Error initializing SD card
  73.         Serial.println("SD card initialization failed");
  74.         while (1)
  75.             ;
  76.     }
  77. }
  78.  
  79. void loop(void)
  80. {
  81.     // put your main code here, to run repeatedly:
  82.     button.update(); // Update the button state
  83.  
  84.     // Rest of your code
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement