/********* 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: "Random Colors"
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-09-02 15:05:09
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* fix the code. */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include // Include the NeoPixel library
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void rndRed();
void rndBlue();
void rndGreen();
void rndPurple();
/****** CONSTANTS AND VARIABLES *****/
#define PIN 6
#define NUMPIXELS 15
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);
const int btnRed = 2; // the pin that the pushbutton is attached to
const int btnBlue = 3; // the pin that the pushbutton is attached to
const int btnGreen = 4; // the pin that the pushbutton is attached to
const int btnPurple = 5; // the pin that the pushbutton is attached to
void setup(void)
{
randomSeed(analogRead(A0)); // Seed the random number generator with noise from analog pin A0
// Set button pins as input
pinMode(btnRed, INPUT);
pinMode(btnBlue, INPUT);
pinMode(btnGreen, INPUT);
pinMode(btnPurple, INPUT);
// Initialize serial communication:
Serial.begin(9600);
// Initialize the NeoPixel strip
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off'
pixels.show(); // Update the strip to show the changes
delay(1000); // Wait for a second
}
void loop(void)
{
// Check the state of each button and call the corresponding function if pressed
if (digitalRead(btnRed) == HIGH) {
rndRed(); // Call function to light up a random red pixel
delay(100); // Debounce delay
}
if (digitalRead(btnBlue) == HIGH) {
rndBlue(); // Call function to light up a random blue pixel
delay(100); // Debounce delay
}
if (digitalRead(btnGreen) == HIGH) {
rndGreen(); // Call function to light up a random green pixel
delay(100); // Debounce delay
}
if (digitalRead(btnPurple) == HIGH) {
rndPurple(); // Call function to light up a random purple pixel
delay(100); // Debounce delay
}
}
void rndRed() {
int led = random(0, NUMPIXELS); // Use NUMPIXELS constant for random range
pixels.setPixelColor(led, pixels.Color(255, 0, 0, 0)); // Set the pixel to red
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Wait for half a second
}
void rndBlue() {
int led = random(0, NUMPIXELS); // Use NUMPIXELS constant for random range
pixels.setPixelColor(led, pixels.Color(0, 0, 255, 0)); // Set the pixel to blue
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Wait for half a second
}
void rndGreen() {
int led = random(0, NUMPIXELS); // Use NUMPIXELS constant for random range
pixels.setPixelColor(led, pixels.Color(0, 255, 0, 0)); // Set the pixel to green
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Wait for half a second
}
void rndPurple() {
int led = random(0, NUMPIXELS); // Use NUMPIXELS constant for random range
pixels.setPixelColor(led, pixels.Color(171, 0, 255, 0)); // Set the pixel to purple
pixels.show(); // Send the updated pixel colors to the hardware.
delay(500); // Wait for half a second
}
/* END CODE */