Advertisement
pleasedontcode

"Motion Control" rev_03

Apr 27th, 2025
190
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: "Motion Control"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-04-27 19:11:29
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Make the lights turn on and off in a wave pattern */
  21.     /* 2 times   when motion is detected with an ir */
  22.     /* sensor */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <avrtos.h> //https://github.com/lucasdietrich/AVRTOS
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  35. const uint8_t myLED_LED_PIN_D2      = 2;
  36. const int pirPin = 3;  
  37. const int LED1 = 13;
  38. const int LED2 = 11;
  39. const int LED3 = 9;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool    myLED_LED_PIN_D2_rawData        = 0;
  44. bool motionDetected = false; // Added for motion detection
  45.  
  46. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  47. /***** used to store data after characteristic curve transformation *****/
  48. float   myLED_LED_PIN_D2_phyData        = 0.0;
  49.  
  50. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  51.  
  52. void setup(void)
  53. {
  54.     // put your setup code here, to run once:
  55.     pinMode(myLED_LED_PIN_D2,    OUTPUT);
  56.     pinMode(pirPin, INPUT); // Set PIR pin as input
  57.     pinMode(LED1, OUTPUT);   // Set LED1 pin as output
  58.     pinMode(LED2, OUTPUT);   // Set LED2 pin as output
  59.     pinMode(LED3, OUTPUT);   // Set LED3 pin as output
  60.     Serial.begin(9600);      // Start serial communication
  61. }
  62.  
  63. void loop(void)
  64. {
  65.     // put your main code here, to run repeatedly:
  66.     updateOutputs(); // Refresh output data
  67.  
  68.     int motionState = digitalRead(pirPin); // Read PIR sensor state
  69.  
  70.     if (motionState == HIGH) {
  71.         motionDetected = true;
  72.  
  73.         // Wave pattern for lights
  74.         for (int i = 0; i < 2; i++) { // Repeat the wave pattern 2 times
  75.             digitalWrite(LED1, HIGH);
  76.             delay(100);
  77.             digitalWrite(LED1, LOW);
  78.             delay(100);
  79.  
  80.             digitalWrite(LED2, HIGH);
  81.             delay(100);
  82.             digitalWrite(LED2, LOW);
  83.             delay(100);
  84.  
  85.             digitalWrite(LED3, HIGH);
  86.             delay(100);
  87.             digitalWrite(LED3, LOW);
  88.             delay(100);
  89.         }
  90.     } else {
  91.         digitalWrite(LED1, LOW);
  92.         digitalWrite(LED2, LOW);
  93.         digitalWrite(LED3, LOW);
  94.         motionDetected = false;
  95.         Serial.println("Motion ended.");
  96.     }
  97. }
  98.  
  99. void updateOutputs()
  100. {
  101.     digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
  102. }
  103.  
  104. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement