/*
Arduino | coding-help
Thread:Servo Help
PigPerOne June 28, 2025 — 3:14 PM
I have a honestly pretty dumb question but for whatever reason I cannot
figure out how to make this servo work correctly. I have a couple problems.
The first being that the servo always rotates 90 degrees no matter what
when the sim is first started. The second being that when I do put a write
function in the void loop it doesn’t work once nor loop with the lights.
Here is the tinkercad, help would be greatly appreciated.
https://www.tinkercad.com/things/bm19ASxNey4-dazzling-leelo/editel?returnTo=https%3A%2F%2Fwww.tinkercad.com%2Fdashboard%2Fdesigns%2Fcircuits
*/
#include <Servo.h>
const int RGB_PINS[][3] = {
{11, 10, 9},
{8, 7, 6},
{5, 4, 3}
};
const int SERVO_PIN = 2;
Servo servo;
void setColor(int ledNum, int R, int G, int B) {
digitalWrite(RGB_PINS[ledNum - 1][0], R);
digitalWrite(RGB_PINS[ledNum - 1][1], G);
digitalWrite(RGB_PINS[ledNum - 1][2], B);
}
void setup() {
Serial.begin(115200);
for (int i = 0; i < 3; i++) {
pinMode(RGB_PINS[0][i], OUTPUT);
pinMode(RGB_PINS[1][i], OUTPUT);
pinMode(RGB_PINS[2][i], OUTPUT);
}
servo.write(0);
servo.attach(SERVO_PIN);
}
void loop() {
servo.write(180);
setColor(1, 1, 0, 0);
delay(500);
setColor(2, 0, 1, 0);
delay(500);
setColor(3, 0, 0, 1);
delay(500);
servo.write(0);
setColor(1, 0, 0, 0);
delay(500);
setColor(2, 0, 0, 0);
delay(500);
setColor(3, 0, 0, 0);
delay(500);
}