Advertisement
pleasedontcode

Arduino Analysis rev_01

Apr 24th, 2024
65
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 Analysis
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-04-24 07:42:40
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* I want arduino recieve these data: 002 001 001 080 */
  21.     /* 050 050 050 010 010 080 050 050 050 010 010 010\n */
  22.     /* or 001 RUN\n or 002 HOM\n . It will be analyse the */
  23.     /* string, and consisder command */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27.  
  28. /****** FUNCTION PROTOTYPES *****/
  29. void setup(void);
  30. void loop(void);
  31. void updateOutputs(void);
  32. void analyzeData(String data);
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t myLED_LED_PIN_D2     = 2;
  36. const uint8_t myLED_LED_PIN_D3     = 3;
  37.  
  38. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  39. /***** used to store raw data *****/
  40. bool    myLED_LED_PIN_D2_rawData       = 0;
  41. bool    myLED_LED_PIN_D3_rawData       = 0;
  42.  
  43. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  44. /***** used to store data after characteristic curve transformation *****/
  45. float   myLED_LED_PIN_D2_phyData       = 0.0;
  46. float   myLED_LED_PIN_D3_phyData       = 0.0;
  47.  
  48. void setup(void)
  49. {
  50.     // put your setup code here, to run once:
  51.     Serial.begin(9600); // Initialize serial communication
  52.     pinMode(myLED_LED_PIN_D2,   OUTPUT);
  53.     pinMode(myLED_LED_PIN_D3,   OUTPUT);
  54.  
  55. }
  56.  
  57.  
  58. void loop(void)
  59. {
  60.     // put your main code here, to run repeatedly:
  61.     if (Serial.available() > 0) {
  62.         String data = Serial.readStringUntil('\n');
  63.         analyzeData(data);
  64.     }
  65.     updateOutputs(); // Refresh output data
  66.  
  67. }
  68.  
  69. void updateOutputs()
  70. {
  71.     digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
  72.     digitalWrite(myLED_LED_PIN_D3, myLED_LED_PIN_D3_rawData);
  73. }
  74.  
  75. void analyzeData(String data)
  76. {
  77.     if (data == "002 001 001 080" || data == "050 050 050 010 010 080 050 050 050 010 010 010\n") {
  78.         // Perform actions based on the received data
  79.     } else if (data == "001 RUN") {
  80.         // Perform actions for command "RUN"
  81.     } else if (data == "002 HOM") {
  82.         // Perform actions for command "HOM"
  83.     }
  84. }
  85.  
  86. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement