/********* 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 Analysis
- Source Code NOT compiled for: Arduino Mega
- Source Code created on: 2024-04-24 07:42:40
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* I want arduino recieve these data: 002 001 001 080 */
/* 050 050 050 010 010 080 050 050 050 010 010 010\n */
/* or 001 RUN\n or 002 HOM\n . It will be analyse the */
/* string, and consisder command */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);
void analyzeData(String data);
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t myLED_LED_PIN_D2 = 2;
const uint8_t myLED_LED_PIN_D3 = 3;
/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool myLED_LED_PIN_D2_rawData = 0;
bool myLED_LED_PIN_D3_rawData = 0;
/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float myLED_LED_PIN_D2_phyData = 0.0;
float myLED_LED_PIN_D3_phyData = 0.0;
void setup(void)
{
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial communication
pinMode(myLED_LED_PIN_D2, OUTPUT);
pinMode(myLED_LED_PIN_D3, OUTPUT);
}
void loop(void)
{
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
String data = Serial.readStringUntil('\n');
analyzeData(data);
}
updateOutputs(); // Refresh output data
}
void updateOutputs()
{
digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
digitalWrite(myLED_LED_PIN_D3, myLED_LED_PIN_D3_rawData);
}
void analyzeData(String data)
{
if (data == "002 001 001 080" || data == "050 050 050 010 010 080 050 050 050 010 010 010\n") {
// Perform actions based on the received data
} else if (data == "001 RUN") {
// Perform actions for command "RUN"
} else if (data == "002 HOM") {
// Perform actions for command "HOM"
}
}
/* END CODE */