Advertisement
pleasedontcode

"Random Color" rev_04

Sep 2nd, 2024
346
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: "Random Color"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-09-02 14:52:43
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* fix the code. */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Adafruit_NeoPixel.h> // Added library for NeoPixel
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void rndRed(); // Function prototype for rndRed
  30. void rndBlue(); // Function prototype for rndBlue
  31. void rndGreen(); // Function prototype for rndGreen
  32. void rndPurple(); // Function prototype for rndPurple
  33.  
  34. #define PIN        6
  35. #define NUMPIXELS 15
  36. Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);
  37.  
  38. // this constant won't change:
  39. const int  btnRed = 2;  // the pin that the pushbutton is attached to
  40. const int  btnBlue = 3;  // the pin that the pushbutton is attached to
  41. const int  btnGreen = 4;  // the pin that the pushbutton is attached to
  42. const int  btnPurple = 5;  // the pin that the pushbutton is attached to
  43.  
  44. void setup(void)
  45. {
  46.     randomSeed(analogRead(A0)); // This line is compatible as it initializes random seed
  47.     // put your setup code here, to run once:
  48.     pinMode(btnRed, INPUT);
  49.     pinMode(btnBlue, INPUT);
  50.     pinMode(btnGreen, INPUT);
  51.     pinMode(btnPurple, INPUT);
  52.  
  53.     // initialize the LED as an output:
  54.     // initialize serial communication:
  55.     Serial.begin(9600);
  56.     pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  57.     pixels.clear(); // Set all pixel colors to 'off'
  58.     pixels.show();
  59.     delay(1000);
  60. }
  61.  
  62. void loop(void)
  63. {
  64.     // put your main code here, to run repeatedly:
  65.     if (digitalRead(btnRed) == HIGH) {
  66.         rndRed();
  67.         delay(100);
  68.     }
  69.  
  70.     if (digitalRead(btnBlue) == HIGH) {
  71.         rndBlue();
  72.         delay(100);
  73.     }
  74.  
  75.     if (digitalRead(btnGreen) == HIGH) {
  76.         rndGreen();
  77.         delay(100);
  78.     }
  79.  
  80.     if (digitalRead(btnPurple) == HIGH) {
  81.         rndPurple();
  82.         delay(100);
  83.     }
  84. }
  85.  
  86. void rndRed() {
  87.     int led = random(0, NUMPIXELS); // Fixed range to use NUMPIXELS constant
  88.     pixels.setPixelColor(led, pixels.Color(255, 0, 0, 0)); // Set the selected pixel to red
  89.     pixels.show();   // Send the updated pixel colors to the hardware.
  90.     delay(500);
  91. }
  92.  
  93. void rndBlue() {
  94.     int led = random(0, NUMPIXELS); // Fixed range to use NUMPIXELS constant
  95.     pixels.setPixelColor(led, pixels.Color(0, 0, 255, 0)); // Set the selected pixel to blue
  96.     pixels.show();   // Send the updated pixel colors to the hardware.
  97.     delay(500);
  98. }
  99.  
  100. void rndGreen() {
  101.     int led = random(0, NUMPIXELS); // Fixed range to use NUMPIXELS constant
  102.     pixels.setPixelColor(led, pixels.Color(0, 255, 0, 0)); // Set the selected pixel to green
  103.     pixels.show();   // Send the updated pixel colors to the hardware.
  104.     delay(500);
  105. }
  106.  
  107. void rndPurple() {
  108.     int led = random(0, NUMPIXELS); // Fixed range to use NUMPIXELS constant
  109.     pixels.setPixelColor(led, pixels.Color(171, 0, 255, 0)); // Set the selected pixel to purple
  110.     pixels.show();   // Send the updated pixel colors to the hardware.
  111.     delay(500);
  112. }
  113.  
  114. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement