Hello... I'm a little bit new to programming with the arduino... and a bit rusty at programming in general...
i would like to have a tri color LED that slowly cycles through all the colors
and while this is happening i would like to control 1 or 2 servos at the same time, each independantly operated according to an algorithm.
making the LED go through all the colors was easy, but once i tried hooking up a servo and making it work with it, both the LED and the servo wouldn't work right...
the LED would just blink on once, then go off completely, and the servo would twitch in place...
i changed the code a little bit and now its completely not working right... the servo works a little better now, but still not correctly... still very twitchy, and now the light just flashes all the colors seemingly randomly...
I would like all of this to be very smooth... gradual color changes, and very slow servo movement... if anyone can point me in the right direction, i would greatly appreciate it.
P.S. please bare with me, as i know my coding is probably horrible and really inefficient. I know this, and i'm currently seeking counseling for it. just kidding... but seriously, my code sucks. don't hate me.
#include <Servo.h>
Servo myservo;
int pos = 0;
const int RED_LED_PIN = 9;
const int GREEN_LED_PIN = 10;
const int BLUE_LED_PIN = 11;
const int SERVO_PIN = 6;
unsigned long time;
int redIntensity = 0;
int greenIntensity = 0;
int blueIntensity = 0;
const int servoTime = 17;
const int greenTime = 73;
const int blueTime = 127;
const int redTime = 167;
const int DISPLAY_TIME = 333;
void setup() {
myservo.attach(6);
}
void loop() {
time = millis();
boolean aaa = true;
if ((time % servoTime ==0) && (aaa =true))
{
for(pos = 0; pos < 180; pos += 1)
{
myservo.write(pos);
if (pos ==180)
{
aaa = false;
}
}
if ((time % servoTime ==0) && (aaa = false)){
for(pos = 180; pos>=1; pos -=1)
{
myservo.write(pos);
if (pos ==1)
{
aaa = true;
}
}
}
}
if (time % greenTime ==0)
{
for (greenIntensity =0; greenIntensity <= 255; greenIntensity +=1) {
redIntensity = 255-greenIntensity;
analogWrite(GREEN_LED_PIN, greenIntensity);
analogWrite(RED_LED_PIN, redIntensity);
}
}
if (time % blueTime ==0)
{
for (blueIntensity =0; blueIntensity <= 255; blueIntensity +=1) {
greenIntensity = 255-blueIntensity;
analogWrite(BLUE_LED_PIN, blueIntensity);
analogWrite(GREEN_LED_PIN, greenIntensity);
}
}
if (time % redTime ==0)
{
for (redIntensity =0; redIntensity <= 255; redIntensity +=1) {
blueIntensity = 255-redIntensity;
analogWrite(RED_LED_PIN, redIntensity);
analogWrite(BLUE_LED_PIN, blueIntensity);
}
}
}