Advertisement
pleasedontcode

"Digital Input & DAC" rev_211

Jan 15th, 2024
85
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 Input & DAC"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-15 23:00:17
  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 <driver/dac.h>
  28. #include <EasyButton.h>
  29. #include <OneWire.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t butt_PushButton_PIN_D4 = 4;
  38. const uint8_t ditpullup_PIN_D14 = 14;
  39. const uint8_t ditpulldown_PIN_D16 = 16;
  40. const uint8_t temp_DS18B20_DQ_PIN_D13 = 13;
  41.  
  42. /***** DEFINITION OF DAC OUTPUT PINS *****/
  43. const uint8_t out_PIN_D25 = 25;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. uint8_t out_PIN_D25_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float out_PIN_D25_phyData = 0.0;
  52.  
  53. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  54. EasyButton butt_PushButton(butt_PushButton_PIN_D4);
  55. OneWire oneWire(temp_DS18B20_DQ_PIN_D13);
  56.  
  57. void setup(void)
  58. {
  59.   // put your setup code here, to run once:
  60.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  61.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  62.  
  63.   butt_PushButton.begin();
  64. }
  65.  
  66. void loop(void)
  67. {
  68.   // put your main code here, to run repeatedly:
  69.   butt_PushButton.read();
  70.  
  71.   /****** SYSTEM REQUIREMENT 1 *****/
  72.   if (butt_PushButton.isPressed())
  73.   {
  74.     out_PIN_D25_rawData = 128;
  75.   }
  76.   else
  77.   {
  78.     out_PIN_D25_rawData = 0;
  79.   }
  80.  
  81.   /****** SYSTEM REQUIREMENT 2 *****/
  82.   // Read GPS from SPI and check if position is moving
  83.   bool isMoving = false; // Replace with actual logic to determine if position is moving
  84.  
  85.   if (isMoving)
  86.   {
  87.     // Generate sinusoidal signal
  88.     float amplitude = 100.0; // Replace with desired amplitude
  89.     float frequency = 1.0;   // Replace with desired frequency
  90.  
  91.     out_PIN_D25_phyData = amplitude * sin(frequency * millis() / 1000.0);
  92.     out_PIN_D25_rawData = map(out_PIN_D25_phyData, -amplitude, amplitude, 0, 255);
  93.   }
  94.   else
  95.   {
  96.     out_PIN_D25_phyData = 0.0;
  97.     out_PIN_D25_rawData = 0;
  98.   }
  99.  
  100.   updateOutputs(); // Refresh output data
  101. }
  102.  
  103. void updateOutputs(void)
  104. {
  105.   dac_output_voltage(DAC_CHANNEL_1, out_PIN_D25_rawData);
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement