Advertisement
pleasedontcode

"Arduino Data Logger" rev_27

Dec 20th, 2023
59
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 Data Logger"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-12-20 08:46:59
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create an integral function relative to acquisiton */
  21.     /* data record at fixed time with millis function. */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void recordData(void);
  31.  
  32. /****** SYSTEM REQUIREMENTS *****/
  33. /****** SYSTEM REQUIREMENT 1 *****/
  34. // Create an integral function relative to acquisition
  35. // data record at fixed time with millis function.
  36.  
  37. /***** DEFINITION OF ANALOG INPUT PINS *****/
  38. const uint8_t Sensor_PIN_A0 = A0;
  39.  
  40. // Variables to store the previous and current time
  41. unsigned long previousTime = 0;
  42. unsigned long currentTime = 0;
  43.  
  44. // Time interval in milliseconds to record data
  45. const unsigned long recordInterval = 1000;
  46.  
  47. void setup(void)
  48. {
  49.   // put your setup code here, to run once:
  50.   pinMode(Sensor_PIN_A0, INPUT);
  51.   Serial.begin(9600);
  52. }
  53.  
  54. void loop(void)
  55. {
  56.   // put your main code here, to run repeatedly:
  57.   currentTime = millis();
  58.  
  59.   // Check if the record interval has elapsed
  60.   if (currentTime - previousTime >= recordInterval) {
  61.     recordData();
  62.     previousTime = currentTime;
  63.   }
  64. }
  65.  
  66. void recordData(void)
  67. {
  68.   // Code to record data from sensor
  69.   int sensorValue = analogRead(Sensor_PIN_A0);
  70.   Serial.print("Sensor Value: ");
  71.   Serial.println(sensorValue);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement