I edited a program (not very great, but it works) the only thing is only thing is i cant get The light and the servo to work in sync ( i made 2 functions "showSpectrum" and "servoTest") the code is below can anyone assist me, its for a school project i was assigned to.
const int RED_PIN = 6;
const int GREEN_PIN = 5;
const int BLUE_PIN = 3;
int DISPLAY_TIME = 100;
#include <Servo.h> // servo library
Servo servo1; // servo control object
void setup()
{
servo1.attach(9);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop()
{
showSpectrum();
servoTest();
}
void showSpectrum()
{
int x;
for (x = 0; x < 768; x++)
{
showRGB(x); // Call RGBspectrum() with our new x
delay(10); // Delay for 10 ms (1/100th of a second)
}
}
// The "base" numbers are:
// 0 = pure red
// 255 = pure green
// 511 = pure blue
// 767 = pure red (again)
void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;
if (color <= 255) // zone 1
{
redIntensity = 255 - color; // red goes from on to off
greenIntensity = color; // green goes from off to on
blueIntensity = 0; // blue is always off
}
else if (color <= 511) // zone 2
{
redIntensity = 0; // red is always off
greenIntensity = 255 - (color - 256); // green on to off
blueIntensity = (color - 256); // blue off to on
}
else // color >= 512 // zone 3
{
redIntensity = (color - 512); // red off to on
greenIntensity = 0; // green is always off
blueIntensity = 255 - (color - 512); // blue on to off
}
analogWrite(RED_PIN, redIntensity);
analogWrite(BLUE_PIN, blueIntensity);
analogWrite(GREEN_PIN, greenIntensity);
}
void servoTest()
{
int position;
for(position = 0; position < 180; position += 2)
{
servo1.write(position); // Move to next position
delay(20); // Short pause to allow it to move
}
// Tell servo to go to 0 degrees, stepping by one degree
for(position = 180; position >= 0; position -= 1)
{
servo1.write(position); // Move to next position
delay(20); // Short pause to allow it to move
}
}