Advertisement
pleasedontcode

"Gas Cylinder Tracker" rev_01

Mar 15th, 2024
52
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: "Gas Cylinder Tracker"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-15 11:15:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Measuring net weight of a full gas cylinder, */
  21.     /* determining the reference weight of gas in the */
  22.     /* cylinder by subtracting the weight of an empty gas */
  23.     /* cylinder from the net weight of a full gas */
  24.     /* cylinder, display the reference weight on the Lcd */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Wire.h>
  29. #include <LiquidCrystal_I2C.h>
  30.  
  31. /****** SYSTEM REQUIREMENTS *****/
  32. /****** SYSTEM REQUIREMENT 1 *****/
  33. /* Measuring net weight of a full gas cylinder, */
  34. /* determining the reference weight of gas in the */
  35. /* cylinder by subtracting the weight of an empty gas */
  36. /* cylinder from the net weight of a full gas */
  37. /* cylinder, display the reference weight on the LCD */
  38. /****** END SYSTEM REQUIREMENTS *****/
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43. void displayReferenceWeight(float referenceWeight);
  44.  
  45. /***** DEFINITION OF I2C PINS *****/
  46. const uint8_t Mybutton_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  47. const uint8_t Mybutton_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  48. const uint8_t Mybutton_LCD1602I2C_I2C_SLAVE_ADDRESS = 0x27; // Address of the LCD module
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51. LiquidCrystal_I2C lcd(Mybutton_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4);
  52.  
  53. void setup()
  54. {
  55.   lcd.begin(20, 4); // Initialize the LCD with 20 characters and 4 lines
  56.   lcd.backlight();
  57.   Serial.begin(9600); // Initialize the Serial communication
  58. }
  59.  
  60. void loop()
  61. {
  62.   if (Serial.available())
  63.   {
  64.     // Read the serial input and calculate the reference weight
  65.     String inputString = Serial.readStringUntil('\n');
  66.     float netWeight = inputString.toFloat();
  67.     float emptyCylinderWeight = 10.0; // Placeholder for the weight of an empty gas cylinder
  68.     float referenceWeight = netWeight - emptyCylinderWeight;
  69.  
  70.     // Display the reference weight on the LCD
  71.     displayReferenceWeight(referenceWeight);
  72.   }
  73. }
  74.  
  75. void displayReferenceWeight(float referenceWeight)
  76. {
  77.   lcd.clear();
  78.   lcd.setCursor(0, 0);
  79.   lcd.print("Reference Weight:");
  80.   lcd.setCursor(0, 1);
  81.   lcd.print(referenceWeight, 2);
  82.   lcd.print(" kg");
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement