Advertisement
pleasedontcode

"Sensor Display" rev_01

Jul 10th, 2024
147
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 Uno
  14.     - Source Code created on: 2024-07-10 18:08:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create a project to display sensor data on a 1602 */
  21.     /* LCD via I2C using the LiquidCrystal_I2C library. */
  22.     /* Configure I2C pins (SDA: A4, SCL: A5) and set the */
  23.     /* slave address to 39. Implement setup and loop */
  24.     /* functions for continuous data update. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>  //https://github.com/marcoschwartz/LiquidCrystal_I2C
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF I2C PINS *****/
  36. const uint8_t ledde_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  37. const uint8_t ledde_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  38. const uint8_t ledde_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; // I2C address for the LCD
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. LiquidCrystal_I2C lcd(ledde_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize the LCD with I2C address and dimensions
  42.  
  43. void setup(void)
  44. {
  45.   // Initialize the LCD
  46.   lcd.init();
  47.  
  48.   // Turn on the backlight
  49.   lcd.backlight();
  50.  
  51.   // Set the cursor to column 0, line 0 and print a message
  52.   lcd.setCursor(0, 0);
  53.   lcd.print("Sensor Data:");
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // Simulate sensor data
  59.   int sensorValue = analogRead(A0); // Read the sensor value from analog pin A0
  60.  
  61.   // Set the cursor to column 0, line 1 and print the sensor value
  62.   lcd.setCursor(0, 1);
  63.   lcd.print("Value: ");
  64.   lcd.print(sensorValue);
  65.  
  66.   // Wait for a short period before updating again
  67.   delay(1000); // Update every second
  68. }
  69.  
  70. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement