Advertisement
pleasedontcode

"Input Control" rev_198

Jan 14th, 2024
71
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: "Input Control"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-01-14 16:56:24
  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 <Arduino.h>
  28. #include <EasyButton.h>
  29. #include <OneWire.h>
  30. #include <DallasTemperature.h>
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35. void updateOutputs(void);
  36. void checkButton(void);
  37. void checkGPS(void);
  38.  
  39. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  40. const uint8_t butt_PushButton_PIN_D4 = 4;
  41. const uint8_t ditpullup_PIN_D14 = 14;
  42. const uint8_t ditpulldown_PIN_D16 = 16;
  43. const uint8_t temp_DS18B20_DQ_PIN_D13 = 13;
  44.  
  45. /***** DEFINITION OF DAC OUTPUT PINS *****/
  46. const uint8_t out_PIN_D25 = 25;
  47.  
  48. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  49. /***** used to store raw data *****/
  50. uint8_t out_PIN_D25_rawData = 0;
  51.  
  52. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  53. /***** used to store data after characteristic curve transformation *****/
  54. float out_PIN_D25_phyData = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. EasyButton butt_PushButton(butt_PushButton_PIN_D4, true, false, 20);
  58. OneWire oneWire(temp_DS18B20_DQ_PIN_D13);
  59. DallasTemperature ds18b20(&oneWire);
  60.  
  61. void buttonPressed()
  62. {
  63.   Serial.println("Button pressed");
  64.   out_PIN_D25_rawData = 128; // Set output to 128 when the button is pressed (System Requirement 1)
  65. }
  66.  
  67. void setup(void)
  68. {
  69.   // put your setup code here, to run once:
  70.  
  71.   pinMode(butt_PushButton_PIN_D4, INPUT_PULLUP);
  72.   pinMode(ditpullup_PIN_D14, INPUT_PULLUP);
  73.   pinMode(ditpulldown_PIN_D16, INPUT_PULLDOWN);
  74.  
  75.   ds18b20.begin();
  76.   butt_PushButton.begin();
  77.   butt_PushButton.onPressed(buttonPressed);
  78.  
  79.   Serial.begin(9600); // Initialize Serial communication
  80.  
  81.   // Initialize GPS module (System Requirement 2)
  82.   // ...
  83. }
  84.  
  85. void loop(void)
  86. {
  87.   // put your main code here, to run repeatedly:
  88.  
  89.   updateOutputs(); // Refresh output data
  90.  
  91.   checkButton(); // Check button status (System Requirement 1)
  92.  
  93.   checkGPS(); // Check GPS position (System Requirement 2)
  94.  
  95.   ds18b20.requestTemperatures(); // Request temperature readings
  96.   float temperature = ds18b20.getTempCByIndex(0); // Get temperature in Celsius
  97.   Serial.print("Temperature: ");
  98.   Serial.println(temperature);
  99.  
  100.   delay(1000); // Wait for 1 second
  101. }
  102.  
  103. void updateOutputs()
  104. {
  105.   dacWrite(out_PIN_D25, out_PIN_D25_rawData);
  106. }
  107.  
  108. void checkButton()
  109. {
  110.   butt_PushButton.read();
  111. }
  112.  
  113. void checkGPS()
  114. {
  115.   // Read GPS data from SPI and generate sinusoidal signal if position is moving (System Requirement 2)
  116.   // ...
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement