Advertisement
pleasedontcode

"Digital Setup" rev_213

Jan 15th, 2024
88
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-15 23:17:13
  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 <OneWire.h>
  29. #include <DallasTemperature.h>
  30. #include <SPI.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t butt_PushButton_PIN_D4 = 4;
  39. const uint8_t ditpullup_PIN_D14 = 14;
  40. const uint8_t ditpulldown_PIN_D16 = 16;
  41. const uint8_t temp_DS18B20_DQ_PIN_D13 = 13;
  42.  
  43. /***** DEFINITION OF DAC OUTPUT PINS *****/
  44. const uint8_t out_PIN_D25 = 25;
  45.  
  46. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  47. /***** used to store raw data *****/
  48. uint8_t out_PIN_D25_rawData = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. /***** used to store data after characteristic curve transformation *****/
  52. float out_PIN_D25_phyData = 0.0;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. EasyButton buttPushButton(butt_PushButton_PIN_D4);
  56. OneWire oneWire(temp_DS18B20_DQ_PIN_D13);
  57. DallasTemperature tempSensor(&oneWire);
  58.  
  59. void setup(void)
  60. {
  61.   // put your setup code here, to run once:
  62.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  63.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  64.  
  65.   // Initialize SPI for GPS communication
  66.   SPI.begin();
  67.  
  68.   // Initialize the button
  69.   buttPushButton.begin();
  70.  
  71.   // Initialize the temperature sensor
  72.   tempSensor.begin();
  73. }
  74.  
  75. void loop(void)
  76. {
  77.   // put your main code here, to run repeatedly:
  78.   updateOutputs(); // Refresh output data
  79.  
  80.   // Handle button press
  81.   buttPushButton.read();
  82.   if (buttPushButton.isPressed())
  83.   {
  84.     // Button press action
  85.     out_PIN_D25_rawData = 128; // Set output to 128
  86.   }
  87.   else
  88.   {
  89.     out_PIN_D25_rawData = 0; // Set output to 0
  90.   }
  91.  
  92.   // Read GPS position
  93.   // TODO: Read GPS position from SPI and check if position is moving
  94.   bool isMoving = false; // Placeholder value
  95.  
  96.   // Generate sinusoidal signal if position is moving
  97.   if (isMoving)
  98.   {
  99.     // TODO: Generate sinusoidal signal
  100.   }
  101.  
  102.   // Read temperature
  103.   tempSensor.requestTemperatures();
  104.   float temperature = tempSensor.getTempCByIndex(0);
  105.  
  106.   delay(1000); // Delay for 1 second
  107. }
  108.  
  109. void updateOutputs(void)
  110. {
  111.   dacWrite(out_PIN_D25, out_PIN_D25_rawData);
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement