Advertisement
pleasedontcode

"Digital Setup" rev_218

Jan 17th, 2024
70
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: "Digital Setup"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-18 00:56:27
  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. /****** DEFINITION OF LIBRARIES *****/
  27. #include <EasyButton.h>
  28. #include <DS18B20.h>
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34. void onButtonPressed(void);
  35. void readGPS(void);
  36. bool isMoving(void);
  37.  
  38. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  39. const uint8_t butt_PushButton_PIN_D4 = 4;
  40. const uint8_t ditpullup_PIN_D14 = 14;
  41. const uint8_t ditpulldown_PIN_D16 = 16;
  42. const uint8_t temp_DS18B20_DQ_PIN_D13 = 13;
  43.  
  44. /***** DEFINITION OF DAC OUTPUT PINS *****/
  45. const uint8_t out_PIN_D25 = 25;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. /***** used to store raw data *****/
  49. uint8_t out_PIN_D25_rawData = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. /***** used to store data after characteristic curve transformation *****/
  53. float out_PIN_D25_phyData = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. EasyButton button(butt_PushButton_PIN_D4);
  57.  
  58. void setup(void) {
  59.   // put your setup code here, to run once:
  60.  
  61.   pinMode(butt_PushButton_PIN_D4, INPUT_PULLUP);
  62.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  63.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  64.   pinMode(temp_DS18B20_DQ_PIN_D13, INPUT);
  65.  
  66.   button.begin(); // Initialize the EasyButton library
  67.   button.onPressed(onButtonPressed); // Set the callback function for when the button is pressed
  68. }
  69.  
  70. void loop(void) {
  71.   // put your main code here, to run repeatedly:
  72.  
  73.   // System Requirement 1: If button is pressed, set out_PIN_D25_rawData to 128
  74.   if (button.read()) {
  75.     out_PIN_D25_rawData = 128;
  76.   } else {
  77.     out_PIN_D25_rawData = 0;
  78.   }
  79.  
  80.   // System Requirement 2: Read GPS from SPI and generate sinusoidal signal if position is moving
  81.   if (isMoving()) {
  82.     // Code to read GPS from SPI
  83.     readGPS();
  84.  
  85.     // Code to generate sinusoidal signal
  86.     // ...
  87.   }
  88.  
  89.   updateOutputs(); // Refresh output data
  90.  
  91.   button.read(); // Check the state of the button
  92. }
  93.  
  94. void updateOutputs() {
  95.   dacWrite(out_PIN_D25, out_PIN_D25_rawData);
  96. }
  97.  
  98. void onButtonPressed() {
  99.   // Code to execute when the button is pressed
  100. }
  101.  
  102. void readGPS() {
  103.   // Code to read GPS from SPI
  104. }
  105.  
  106. bool isMoving() {
  107.   // Code to check if position is moving
  108.   // Return true if moving, false otherwise
  109.   return false;
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement