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 Detection"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-04-27 19:04:18
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Make the lights turn on and off in a wave pattern */
- /* when motion is detected 2 times */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void);
- void wavePattern(void); // Function to create wave pattern
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t idk_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 idk_LED_PIN_D2_rawData = 0;
- bool motionDetected = false; // Added from USER CODE
- int motionCount = 0; // Count the number of motion detections
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float idk_LED_PIN_D2_phyData = 0.0;
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(idk_LED_PIN_D2, OUTPUT);
- pinMode(pirPin, INPUT); // Added from USER CODE
- pinMode(LED1, OUTPUT); // Added from USER CODE
- pinMode(LED2, OUTPUT); // Added from USER CODE
- pinMode(LED3, OUTPUT); // Added from USER CODE
- Serial.begin(9600); // Added from USER CODE
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- int motionState = digitalRead(pirPin); // Added from USER CODE
- if (motionState == HIGH) { // Added from USER CODE
- motionCount++; // Increment motion count
- Serial.println("Motion detected."); // Log motion detection
- if (motionCount == 2) { // Check if motion detected twice
- wavePattern(); // Call wave pattern function
- motionCount = 0; // Reset motion count after wave
- }
- } else { // Added from USER CODE
- digitalWrite(LED1, LOW); // Added from USER CODE
- digitalWrite(LED2, LOW); // Added from USER CODE
- digitalWrite(LED3, LOW); // Added from USER CODE
- Serial.println("Motion ended."); // Added from USER CODE
- }
- }
- void updateOutputs()
- {
- digitalWrite(idk_LED_PIN_D2, idk_LED_PIN_D2_rawData);
- }
- // Function to create wave pattern
- void wavePattern() {
- digitalWrite(LED1, HIGH);
- delay(100);
- digitalWrite(LED1, LOW);
- digitalWrite(LED2, HIGH);
- delay(100);
- digitalWrite(LED2, LOW);
- digitalWrite(LED3, HIGH);
- delay(100);
- digitalWrite(LED3, LOW);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement