Advertisement
pleasedontcode

"Infrared Control" rev_01

Apr 17th, 2024
40
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: "Infrared Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-17 20:12:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Irremote.h  Fastled    Led pin6   Num leds 184 */
  21.     /* Receiver_pin 2   Brightness 40     all colors with */
  22.     /* remote   and a cycling ledstrip code that you can */
  23.     /* override with the ir  with serial monitor */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <IRremote.h>   // https://github.com/Arduino-IRremote/Arduino-IRremote
  28. #include <FastLED.h>    // https://github.com/FastLED/FastLED
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void); // Added function prototype
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t ir_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t ledstrip_PIN_D6 = 6;
  40.  
  41. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  42. /***** used to store raw data *****/
  43. bool ledstrip_PIN_D6_rawData = 0;
  44.  
  45. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  46. /***** used to store data after characteristic curve transformation *****/
  47. float ledstrip_PIN_D6_phyData = 0.0;
  48.  
  49. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  50. IRrecv irrecv(ir_PIN_D2);   // Create an instance of the IRrecv class
  51. decode_results results;     // Create a variable to store the IR decoding results
  52.  
  53. CRGB leds[184];   // Create an array to store the LED strip data
  54.  
  55. void setup(void)
  56. {
  57.     // put your setup code here, to run once:
  58.  
  59.     pinMode(ir_PIN_D2, INPUT);
  60.     pinMode(ledstrip_PIN_D6, OUTPUT);
  61.  
  62.     irrecv.enableIRIn();    // Enable IR reception
  63.  
  64.     FastLED.addLeds<WS2812, ledstrip_PIN_D6, GRB>(leds, 184);   // Initialize FastLED library with the LED strip
  65.  
  66.     FastLED.setBrightness(40);   // Set the LED strip brightness to 40
  67.  
  68.     for (int i = 0; i < 184; i++) {
  69.         leds[i] = CRGB::Black;   // Turn off all LEDs initially
  70.     }
  71.  
  72.     FastLED.show();   // Update LED strip with initial data
  73. }
  74.  
  75. void loop(void)
  76. {
  77.     // put your main code here, to run repeatedly:
  78.  
  79.     updateOutputs(); // Refresh output data
  80.  
  81.     if (irrecv.decode(&results))    // Check if IR signal is received
  82.     {
  83.         // Process the received IR signal here
  84.         irrecv.resume();    // Continue to receive IR signals
  85.     }
  86. }
  87.  
  88. void updateOutputs()
  89. {
  90.     for (int i = 0; i < 184; i++) {
  91.         leds[i] = CRGB::White;   // Set all LEDs to white
  92.     }
  93.  
  94.     FastLED.show();   // Update LED strip with the new data
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement