Advertisement
pleasedontcode

LED Control rev_01

Apr 10th, 2024
88
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: LED Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-10 11:14:03
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This code will consider a hospital set up where a */
  21.     /* person is isolated and under medical observation */
  22.     /* create a program that mimics a blood pressure */
  23.     /* monitoring system if the person's BP reading is */
  24.     /* above 200,lit a red light in the remote control */
  25.     /* room and */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Wire.h>
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF ANALOG INPUT PINS *****/
  37. const uint8_t POT_Potentiometer_Vout_PIN_A0 = A0;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t LED_LED_PIN_D2 = 2;
  41.  
  42. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  43. /***** used to store raw data *****/
  44. bool LED_LED_PIN_D2_rawData = 0;
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float LED_LED_PIN_D2_phyData = 0.0;
  49.  
  50. void setup(void)
  51. {
  52.   // put your setup code here, to run once:
  53.   pinMode(POT_Potentiometer_Vout_PIN_A0, INPUT);
  54.   pinMode(LED_LED_PIN_D2, OUTPUT);
  55.   Wire.begin(); // Initialize I2C communication
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // put your main code here, to run repeatedly:
  61.   updateOutputs(); // Refresh output data
  62.  
  63.   // Read the analog value from the potentiometer
  64.   int potValue = analogRead(POT_Potentiometer_Vout_PIN_A0);
  65.  
  66.   // Convert the analog value to a physical value
  67.   float physicalValue = map(potValue, 0, 1023, 0, 300); // Assuming the potentiometer measures values from 0 to 300
  68.  
  69.   if (physicalValue > 200)
  70.   {
  71.     LED_LED_PIN_D2_rawData = 1; // Set the raw data to turn on the LED
  72.   }
  73.   else
  74.   {
  75.     LED_LED_PIN_D2_rawData = 0; // Set the raw data to turn off the LED
  76.   }
  77. }
  78.  
  79. void updateOutputs()
  80. {
  81.   digitalWrite(LED_LED_PIN_D2, LED_LED_PIN_D2_rawData);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement