Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: "Motion Control"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-04-27 19:11:29
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Make the lights turn on and off in a wave pattern */
- /* 2 times when motion is detected with an ir */
- /* sensor */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <avrtos.h> //https://github.com/lucasdietrich/AVRTOS
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myLED_LED_PIN_D2 = 2;
- const int pirPin = 3;
- const int LED1 = 13;
- const int LED2 = 11;
- const int LED3 = 9;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool myLED_LED_PIN_D2_rawData = 0;
- bool motionDetected = false; // Added for motion detection
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float myLED_LED_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(myLED_LED_PIN_D2, OUTPUT);
- pinMode(pirPin, INPUT); // Set PIR pin as input
- pinMode(LED1, OUTPUT); // Set LED1 pin as output
- pinMode(LED2, OUTPUT); // Set LED2 pin as output
- pinMode(LED3, OUTPUT); // Set LED3 pin as output
- Serial.begin(9600); // Start serial communication
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- int motionState = digitalRead(pirPin); // Read PIR sensor state
- if (motionState == HIGH) {
- motionDetected = true;
- // Wave pattern for lights
- for (int i = 0; i < 2; i++) { // Repeat the wave pattern 2 times
- digitalWrite(LED1, HIGH);
- delay(100);
- digitalWrite(LED1, LOW);
- delay(100);
- digitalWrite(LED2, HIGH);
- delay(100);
- digitalWrite(LED2, LOW);
- delay(100);
- digitalWrite(LED3, HIGH);
- delay(100);
- digitalWrite(LED3, LOW);
- delay(100);
- }
- } else {
- digitalWrite(LED1, LOW);
- digitalWrite(LED2, LOW);
- digitalWrite(LED3, LOW);
- motionDetected = false;
- Serial.println("Motion ended.");
- }
- }
- void updateOutputs()
- {
- digitalWrite(myLED_LED_PIN_D2, myLED_LED_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement