#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 7 // Number of LEDs in the ring
#define LED_PIN 6 // Data pin for the LEDs
#define MOTOR_A_PIN 9 // Pin for motor A
#define MOTOR_B_PIN 10 // Pin for motor B
#define BALL_DETECTION_PIN 11 // Pin for ball detection indicator
#define COLOR_ORDER GRB // Color order for the LEDs
#define BRIGHTNESS 255 // Maximum brightness for the LEDs
Adafruit_NeoPixel strip (NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); // Initialize the LED strip object
int fadeValue = 0; // Variable to store the fade value
int fadeDirection = 1; // Variable to store the fade direction
void setup() {
strip.begin(); // Prepare the data pin for NeoPixel output
pinMode(MOTOR_A_PIN, INPUT); // Set the pin for motor A as input
pinMode(MOTOR_B_PIN, INPUT); // Set the pin for motor B as input
pinMode(BALL_DETECTION_PIN, INPUT); // Set the pin for ball detection indicator as input
}
void loop() {
strip.clear(); // Set all pixel colors to 'off'
// Read the state of motor A and B pins
int motorA = digitalRead(MOTOR_A_PIN);
int motorB = digitalRead(MOTOR_B_PIN);
// Read the state of ball detection indicator pin
int ballDetection = digitalRead(BALL_DETECTION_PIN);
// Set the color and brightness of the top two LEDs based on motor A state
if (motorA == HIGH) {
strip.setPixelColor(0, strip.Color(255, 165, 0)); // Set pixel 0 to orange color
strip.setPixelColor(1, strip.Color(255, 165, 0)); // Set pixel 1 to orange color
strip.setBrightness(BRIGHTNESS * 0.75); // Set brightness to 75%
strip.show(); // Update the strip with new colors and brightness
delay(10); // Wait for a short time
} else {
strip.setPixelColor(0, strip.Color(fadeValue, fadeValue * 0.65, 0)); // Set pixel 0 to orange color with fade value
strip.setPixelColor(1, strip.Color(fadeValue, fadeValue * 0.65, 0)); // Set pixel 1 to orange color with fade value
strip.setBrightness(BRIGHTNESS); // Set brightness to maximum
strip.show(); // Update the strip with new colors and brightness
// Update the fade value and direction
fadeValue = fadeValue + fadeDirection * 5;
if (fadeValue >= BRIGHTNESS || fadeValue <= 0) {
fadeDirection = -fadeDirection;
}
delay(50); // Wait for a longer time to create a fading effect
}
// Set the color and brightness of the bottom two LEDs based on motor B state
if (motorB == HIGH) {
strip.setPixelColor(5, strip.Color(0, 0, 255)); // Set pixel 5 to blue color
strip.setPixelColor(6, strip.Color(0, 0, 255)); // Set pixel 6 to blue color
strip.setBrightness(BRIGHTNESS * 0.75); // Set brightness to 75%
strip.show(); // Update the strip with new colors and brightness
delay(10); // Wait for a short time
} else {
strip.setPixelColor(5, strip.Color(0, 0, fadeValue)); // Set pixel 5 to blue color with fade value
strip.setPixelColor(6, strip.Color(0, 0, fadeValue)); // Set pixel 6 to blue color with fade value
strip.setBrightness(BRIGHTNESS); // Set brightness to maximum
strip.show(); // Update the strip with new colors and brightness
// Update the fade value and direction (same as above)
fadeValue = fadeValue + fadeDirection * 5;
if (fadeValue >= BRIGHTNESS || fadeValue <= 0) {
fadeDirection = -fadeDirection;
}
delay(50); // Wait for a longer time to create a fading effect
}
// Set the color and brightness of the middle three LEDs based on ball detection state
if (ballDetection == HIGH) {
strip.setPixelColor(2, strip.Color(0, BRIGHTNESS, 0)); // Set pixel 2 to green color with maximum brightness
strip.setPixelColor(3, strip.Color(0, BRIGHTNESS, 0)); // Set pixel 3 to green color with maximum brightness
strip.setPixelColor(4, strip.Color(0, BRIGHTNESS, 0)); // Set pixel 4 to green color with maximum brightness
strip.show(); // Update the strip with new colors and brightness
delay(10); // Wait for a short time
} else {
strip.setPixelColor(2, strip.Color(0, BRIGHTNESS * 0.5, 0)); // Set pixel 2 to green color with 50% brightness
strip.setPixelColor(3, strip.Color(0, BRIGHTNESS * 0.5, 0)); // Set pixel 3 to green color with 50% brightness
strip.setPixelColor(4, strip.Color(0, BRIGHTNESS * 0.5, 0)); // Set pixel 4 to green color with 50% brightness
strip.show(); // Update the strip with new colors and brightness
delay(10); // Wait for a short time
}
}