Advertisement
pleasedontcode

"Arduino Setup" rev_197

Jan 14th, 2024
65
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: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-14 16:42:23
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* if button is pressed so set out to 128. */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* read gps from spi and generate sinusoide signal if */
  23.     /* position is moving. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /********* User code review feedback **********
  28. #### Feedback 1 ####
  29. - generate a function sinewave used to reproduce sine wave in dac
  30. output.
  31. ********* User code review feedback **********/
  32.  
  33. /****** DEFINITION OF LIBRARIES *****/
  34. #include <Arduino.h>
  35. #include <SPI.h>
  36. #include <EasyButton.h>
  37.  
  38. /****** FUNCTION PROTOTYPES *****/
  39. void setup(void);
  40. void loop(void);
  41. void generateSinewave(void);
  42.  
  43. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  44. const uint8_t butt_PushButton_PIN_D4 = 4;
  45. const uint8_t ditpullup_PIN_D14 = 14;
  46. const uint8_t ditpulldown_PIN_D16 = 16;
  47.  
  48. /***** DEFINITION OF DAC OUTPUT PINS *****/
  49. const uint8_t out_PIN_D25 = 25;
  50.  
  51. /***** DEFINITION OF SPI PINS *****/
  52. const uint8_t spi_PIN_MOSI_D23 = 23;
  53. const uint8_t spi_PIN_MISO_D19 = 19;
  54. const uint8_t spi_PIN_SCLK_D18 = 18;
  55. const uint8_t spi_PIN_CS_D5 = 5;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58. EasyButton button(butt_PushButton_PIN_D4, true, true); // Instantiate the EasyButton object with the pin and enable pullup and inverted state
  59.  
  60. bool positionIsMoving = false; // Declare and initialize the positionIsMoving variable
  61.  
  62. void setup(void)
  63. {
  64.   // put your setup code here, to run once:
  65.   pinMode(butt_PushButton_PIN_D4, INPUT_PULLUP);
  66.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  67.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  68.  
  69.   pinMode(spi_PIN_CS_D5, OUTPUT);
  70.   // start the SPI library:
  71.   SPI.begin();
  72.  
  73.   button.begin(); // Initialize the button object
  74.  
  75.   // Set DAC output pin as output
  76.   pinMode(out_PIN_D25, OUTPUT);
  77. }
  78.  
  79. void loop(void)
  80. {
  81.   // put your main code here, to run repeatedly:
  82.   button.read(); // Read the button state
  83.  
  84.   if (button.wasPressed())
  85.   {
  86.     // Button was pressed
  87.     // Implement System Requirement 1: Set DAC output to 128
  88.     analogWrite(out_PIN_D25, 128);
  89.   }
  90.  
  91.   // Read GPS data from SPI and check if the position is moving
  92.   // Implement System Requirement 2: Generate sinusoidal signal if position is moving
  93.   // Add your code here to read GPS data from SPI and check position
  94.  
  95.   // If position is moving, generate sinusoidal signal
  96.   if (positionIsMoving)
  97.   {
  98.     generateSinewave();
  99.   }
  100.  
  101.   delay(100); // Delay for stability
  102. }
  103.  
  104. void generateSinewave(void)
  105. {
  106.   // Implement code to generate sine wave in DAC output
  107.   // Add your code here to generate the sinewave signal
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement