Advertisement
pleasedontcode

"Arduino Relay Control" rev_02

Apr 20th, 2024
75
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 Relay Control"
  13.     - Source Code compiled for: Arduino Nano
  14.     - Source Code created on: 2024-04-20 05:46:58
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* inputs turn on or off a relay on the outputs, */
  21.     /* input is pwm signal from rc receiver */
  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 updateOutputs(void);
  31.  
  32. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  33. const uint8_t a3_PIN_A3 = A3;
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t r1_PIN_D3 = 3;
  37. const uint8_t r2_PIN_D4 = 4;
  38.  
  39. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  40. /***** used to store raw data *****/
  41. bool r1_PIN_D3_rawData = false;
  42. bool r2_PIN_D4_rawData = false;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float r1_PIN_D3_phyData = 0.0;
  47. float r2_PIN_D4_phyData = 0.0;
  48.  
  49. void setup(void)
  50. {
  51.   // put your setup code here, to run once:
  52.   pinMode(a3_PIN_A3, INPUT);
  53.   pinMode(r1_PIN_D3, OUTPUT);
  54.   pinMode(r2_PIN_D4, OUTPUT);
  55.  
  56.   // initialize the output pins to LOW
  57.   digitalWrite(r1_PIN_D3, LOW);
  58.   digitalWrite(r2_PIN_D4, LOW);
  59. }
  60.  
  61. void loop(void)
  62. {
  63.   // put your main code here, to run repeatedly:
  64.  
  65.   // Read the input value from a3_PIN_A3
  66.   int inputSignal = analogRead(a3_PIN_A3);
  67.  
  68.   // Map the input signal to the output range (0-255)
  69.   int outputValue = map(inputSignal, 0, 1023, 0, 255);
  70.  
  71.   // Turn on or off the relay on r1_PIN_D3 based on the input signal
  72.   if (outputValue > 0)
  73.   {
  74.     r1_PIN_D3_rawData = true;
  75.   }
  76.   else
  77.   {
  78.     r1_PIN_D3_rawData = false;
  79.   }
  80.  
  81.   // Update the outputs
  82.   updateOutputs();
  83. }
  84.  
  85. void updateOutputs()
  86. {
  87.   digitalWrite(r1_PIN_D3, r1_PIN_D3_rawData);
  88.   digitalWrite(r2_PIN_D4, r2_PIN_D4_rawData);
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement