Hi, I am trying to programme an series of LEDS on and off without using the delay() function, i have already created projects that do this using sine waves and the mills() function however i now need a very specific sine wave creating and I'm unsure of how to do it.
For my previous project i have used:
ok so far i have this, which just produces a normal sine wave from 0 - 255 both in the positive and negative, keithRB could you expand on what you've said, do you have any pointers on how i would code this?
//------------------------
// Sine Wave Values
//------------------------
int value1;
float delaytime1;
//-------------------------
// Time Offsets
//-------------------------
long wait1 = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
//---------------------------
// Define Time Variables
//---------------------------
delaytime1 = millis()/5000.0;
if (millis() >= wait1) {
value1 = 255 * sin ( delaytime1 * PI);
}
//---------------------------
// Serial Print Data
//---------------------------
delay (10);
Serial.print ("v1 = ");
Serial.println ( value1);
}
//------------------------
// Sine Wave Values
//------------------------
int value1;
float delaytime1;
float pie;
//-------------------------
// Time Offsets
//-------------------------
long wait1 = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
//---------------------------
// Define Time Variables
//---------------------------
delaytime1 = millis()/5000.0;
pie = 2 * PI;
if (millis() >= wait1) {
value1 = 255 * sin ( delaytime1);
}
//---------------------------
// Serial Print Data
//---------------------------
if (delaytime1 < (pie / 2)) {
delay (10);
Serial.print ("v1 = ");
Serial.println ( value1);
}
}
PaulS i think you were missing the point, this sketch is a little out take of a much bigger project, all i needed was to be able to create a sine wave which went from 0-255-0. Although technically i've not achieved this i am able to print the values and tell it when to stop printing the value which gives me what i need.