प्रकाशन तिथि: 05.09.2024
Arduino स्केच:
const int ledCount = 6;
const int ledPins[ledCount] = {3, 5, 6, 9, 10, 11};
int brightness[ledCount];
int fadeDirection[ledCount];
int speed = 10;
unsigned long previousMillis = 0;
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
brightness[i] = 0;
fadeDirection[i] = random(1, 3) == 1 ? 1 : -1;
}
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= speed) {
previousMillis = currentMillis;
for (int i = 0; i < ledCount; i++) {
brightness[i] += fadeDirection[i] * random(1, 6);
if (brightness[i] >= 255) {
brightness[i] = 255;
fadeDirection[i] = -1;
} else if (brightness[i] <= 0) {
brightness[i] = 0;
fadeDirection[i] = 1;
}
analogWrite(ledPins[i], brightness[i]);
}
}
}
यह उदाहरण PWM का उपयोग करके एलईडी को बेतरतीब ढंग से चालू और बंद करता है। कृपया ध्यान दें कि डायोड Arduino Nano बोर्ड पर PWM पिन से जुड़े हुए हैं।
No Comments Yet