/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: "Arduino Relay Control"
- Source Code compiled for: Arduino Nano
- Source Code created on: 2024-04-20 05:46:58
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* inputs turn on or off a relay on the outputs, */
/* input is pwm signal from rc receiver */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t a3_PIN_A3 = A3;
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t r1_PIN_D3 = 3;
const uint8_t r2_PIN_D4 = 4;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool r1_PIN_D3_rawData = false;
bool r2_PIN_D4_rawData = false;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float r1_PIN_D3_phyData = 0.0;
float r2_PIN_D4_phyData = 0.0;
void setup(void)
{
// put your setup code here, to run once:
pinMode(a3_PIN_A3, INPUT);
pinMode(r1_PIN_D3, OUTPUT);
pinMode(r2_PIN_D4, OUTPUT);
// initialize the output pins to LOW
digitalWrite(r1_PIN_D3, LOW);
digitalWrite(r2_PIN_D4, LOW);
}
void loop(void)
{
// put your main code here, to run repeatedly:
// Read the input value from a3_PIN_A3
int inputSignal = analogRead(a3_PIN_A3);
// Map the input signal to the output range (0-255)
int outputValue = map(inputSignal, 0, 1023, 0, 255);
// Turn on or off the relay on r1_PIN_D3 based on the input signal
if (outputValue > 0)
{
r1_PIN_D3_rawData = true;
}
else
{
r1_PIN_D3_rawData = false;
}
// Update the outputs
updateOutputs();
}
void updateOutputs()
{
digitalWrite(r1_PIN_D3, r1_PIN_D3_rawData);
digitalWrite(r2_PIN_D4, r2_PIN_D4_rawData);
}