Advertisement
pleasedontcode

**Wave Pattern** rev_04

Apr 27th, 2025
195
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: **Wave Pattern**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-04-27 19:33:10
  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 <IRremote.h> // Include the IRremote library
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33.  
  34. // USER CODE
  35. const int ir = 5;  
  36. const int LED1 = 13;
  37. const int LED2 = 12;
  38. const int LED3 = 11;
  39.  
  40. int previousState = LOW;
  41.  
  42. void setup(void)
  43. {
  44.     // put your setup code here, to run once:
  45.     pinMode(ir, INPUT);
  46.     pinMode(LED1, OUTPUT);
  47.     pinMode(LED2, OUTPUT);
  48.     pinMode(LED3, OUTPUT);
  49.     Serial.begin(9600); // Initialize serial communication at 9600 bits per second
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // put your main code here, to run repeatedly:
  55.     int currentState = digitalRead(ir);
  56.  
  57.     if (previousState == LOW && currentState == HIGH) {  
  58.         // Wave pattern for LEDs
  59.         for (int i = 0; i < 2; i++) { // Repeat the wave pattern 2 times
  60.             digitalWrite(LED1, HIGH);
  61.             delay(100);
  62.             digitalWrite(LED2, HIGH);
  63.             delay(100);
  64.             digitalWrite(LED3, HIGH);
  65.             delay(100);
  66.             digitalWrite(LED3, LOW);
  67.             delay(100);
  68.             digitalWrite(LED2, LOW);
  69.             delay(100);
  70.             digitalWrite(LED1, LOW);
  71.             delay(100);
  72.         }
  73.     } else {
  74.         digitalWrite(LED3, LOW);
  75.         digitalWrite(LED2, LOW);
  76.         digitalWrite(LED1, LOW);
  77.     }
  78.    
  79.     previousState = currentState; // Update previousState for the next loop iteration
  80. }
  81.  
  82. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement