long time=0;
time = millis();
That's a mistake. The millis() function returns UNSIGNED long.
int period = 2000;
void loop()
{
time = millis();
value = 128+127*cos(2*PI/period*time);
I would worry about errors accumulating when 'time' gets into the millions or billions. I would try:
value = 128+127*cos((2*PI*(time%period)) / period);
That will limit the range to 0..2Pi.
There is no need to have 'time' and 'currentMillis' be separate variables.
//Use the default 16.5Mhz !!!!!!
//Hit "Upload" Wait til it says to plug in, THEN plug it in !!!
// yet another blink sketch by aarg, Arduino forum
//
unsigned long previousMillis = 0;
// circular list of intervals, alternating off and on
const unsigned long intervals[] = {60, 60, 60, 900,};
//const unsigned long intervals[] = {50, 50, 50, 1000, 10, 10};//try odd numbers here originally
//const unsigned long intervals[] = {100, 50, 100, 1000, 10, 10};
//const unsigned long intervals[] = {50, 50, 50, 800, 10, 10, 20, 30};//My favorite
const byte NUM_OF_INTERVALS = sizeof(intervals) / sizeof(unsigned long);
byte currentInterval = 0;
//int brightness = 30; // how bright the LED is
//int fadeAmount = 10; // how many points to fade the LED by
const int period = 2000;
// int displace = 500;
const byte White1Pin = 3;
const byte RedPin = 5;
const byte GreenPin = 4;
const byte White2Pin = 7;
const byte BeaconPin = 9;
void setup()
{
pinMode(13, OUTPUT);
//pinMode(Stro1, OUTPUT);
pinMode(RedPin, OUTPUT);
pinMode(White1Pin, OUTPUT);
pinMode(GreenPin, OUTPUT);
pinMode(White2Pin, OUTPUT);
pinMode(BeaconPin, OUTPUT);
digitalWrite(RedPin, HIGH);//I added this to start HIGH. Seems to work so far : )
digitalWrite(White1Pin, HIGH);
digitalWrite(White2Pin, HIGH);
digitalWrite(GreenPin, HIGH);
//digitalWrite(Lpin2, HIGH);
}
void loop()
{
unsigned long currentMillis = millis(); //get current value of millisecond counter
int value = 128 + 127 * cos((2 * PI * (currentMillis % period)) / period);
analogWrite(BeaconPin, value); // sets the value (range from 0 to 255)
if (currentMillis - previousMillis >= intervals[currentInterval]) //if the time interval has elapsed
{
currentInterval = currentInterval + 1; // select the next interval in the list
if (currentInterval >= NUM_OF_INTERVALS)
currentInterval = 0;
digitalWrite(White1Pin, not digitalRead(White1Pin)); //change state of the LED
digitalWrite(White2Pin, not digitalRead(White2Pin));
previousMillis = currentMillis; //save the time of change
}
}