I’m having a problem where my code doesnt work for no apparent reason, i had working code that made my led do a changing rgb pattern, but then i changed the code slightly (still using the same function to light up the led) and now the led doesnt light up.
Here is the code:
#include <Arduino.h>
const int redPin = 22; // GPIO pin for red color
const int greenPin = 21; // GPIO pin for green color
const int bluePin = 17; // GPIO pin for blue color
const int maxLed = 100;
const int cycleSpeed = 2;
const int cycleLength = 50;
void setColor(int, int, int);
void setup() {
// Set RGB LED pins as outputs
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
//red to green
for (int cycle = 0; cycle < maxLed; cycle += cycleSpeed){
if (cycle > maxLed) cycle = maxLed;
setColor(maxLed - cycle, cycle, 0);
delay(cycleLength);
}
//green to blue
for (int cycle = 0; cycle < maxLed; cycle += cycleSpeed){
if (cycle > maxLed) cycle = maxLed;
setColor(0, maxLed - cycle, cycle);
delay(cycleLength);
}
//blue to red
for (int cycle = 0; cycle < maxLed; cycle += cycleSpeed){
if (cycle > maxLed) cycle = maxLed;
setColor(cycle, 0, maxLed - cycle);
delay(cycleLength);
}
}
void setColor(int redValue, int greenValue, int blueValue) {
// Set intensity of each color component
analogWrite(redPin, redValue); // Set intensity of red color
analogWrite(greenPin, greenValue); // Set intensity of green color
analogWrite(bluePin, blueValue); // Set intensity of blue color
}
And here is the new code, all i changed was the loop:
#include <Arduino.h>
const int redPin = 22; // GPIO pin for red color
const int greenPin = 21; // GPIO pin for green color
const int bluePin = 17; // GPIO pin for blue color
const int maxLed = 100;
const int cycleSpeed = 2;
const int cycleLength = 50;
void setColor(int, int, int);
void setup() {
// Set RGB LED pins as outputs
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(100, 100, 100)
}
void setColor(int redValue, int greenValue, int blueValue) {
// Set intensity of each color component
analogWrite(redPin, redValue); // Set intensity of red color
analogWrite(greenPin, greenValue); // Set intensity of green color
analogWrite(bluePin, blueValue); // Set intensity of blue color
}
I’m sure that the pins are connected, since when i change back the code it always works.
Hope someone can help me.