pleasedontcode

Sensor Display rev_04

Jul 27th, 2025
132
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: Sensor Display
  13.     - Source Code NOT compiled for: Arduino Nano
  14.     - Source Code created on: 2025-07-27 10:40:33
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Implement a system to read data from a connected */
  21.     /* sensor via the PipedStream library, process the */
  22.     /* data, and display the results on a connected LCD */
  23.     /* display. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <PipedStream.h>    // https://github.com/paulo-raca/ArduinoBufferedStreams
  30. #include <LiquidCrystal_I2C.h>    // https://github.com/marcoschwartz/LiquidCrystal_I2C
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF I2C PINS *****/
  37. const uint8_t myLCD1602I2C_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  38. const uint8_t myLCD1602I2C_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  39. const uint8_t myLCD1602I2C_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  40.  
  41. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  42. PipedStream sensorStream; // Stream to read sensor data
  43. LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize LCD at I2C address 0x27 with 16 columns and 2 rows
  44.  
  45. // Buffer to store sensor data
  46. char sensorDataBuffer[32];
  47.  
  48. void setup(void)
  49. {
  50.   // Initialize serial communication for debugging
  51.   Serial.begin(9600);
  52.  
  53.   // Initialize the LCD
  54.   lcd.init();
  55.   lcd.backlight();
  56.   lcd.clear();
  57.   lcd.setCursor(0, 0);
  58.   lcd.print("Sensor Data:");
  59.  
  60.   // Initialize the sensor stream
  61.   // For simulation, we can connect the stream to a dummy source or assume it's connected
  62.   // For actual sensor, connect sensor output to the stream's input
  63.   // Here, we simulate by writing data to the stream in code (if needed)
  64.  
  65.   // For example, if sensor data is sent via serial or other means, connect accordingly
  66.   // For now, assume sensorStream is connected to the sensor source externally
  67. }
  68.  
  69. void loop(void)
  70. {
  71.   // Check if data is available from the sensor stream
  72.   if (sensorStream.available()) {
  73.     // Read data from the stream
  74.     int len = sensorStream.readBytes(sensorDataBuffer, sizeof(sensorDataBuffer) - 1);
  75.     sensorDataBuffer[len] = '\0'; // Null-terminate the string
  76.  
  77.     // Process data (for example, convert to integer or float if needed)
  78.     // For simplicity, assume data is a string to display
  79.     Serial.print("Received sensor data: ");
  80.     Serial.println(sensorDataBuffer);
  81.  
  82.     // Display on LCD
  83.     lcd.setCursor(0, 1);
  84.     lcd.print("                "); // Clear previous data
  85.     lcd.setCursor(0, 1);
  86.     lcd.print(sensorDataBuffer);
  87.   }
  88.  
  89.   // Optional: simulate sensor data input for testing
  90.   // For example, write dummy data to the stream periodically
  91.   static unsigned long lastMillis = 0;
  92.   if (millis() - lastMillis > 2000) { // every 2 seconds
  93.     lastMillis = millis();
  94.     // Simulate sensor data
  95.     const char* dummyData = "Temp:25C";
  96.     sensorStream.write(dummyData, strlen(dummyData));
  97.   }
  98.  
  99.   delay(100);
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment