# using sin function, why so choppy? --- SOLVED, use float

Beginner here, my hope is to make my LED cycle up n down smoothly, not working, makes hard steps, wondering why?
Thanks

``````#define LED 9

int flux = 0;
int multi = 500;  //frequency mutliplier

void setup() {

pinMode(LED, OUTPUT);    }

void loop(){

flux = (1 + sin(millis()/multi))*60;

analogWrite(LED, flux);

}
``````

Try Serial.printing flux each time. See what values you get.

Then look at what type sin() returns, and use those instead of ints.

Thought of using float as well but without success, below is version 2...
Thanks

``````#define LED 9

float flux = 0;
int multi = 500;

void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);    }

void loop(){
flux = (1 + sin(millis()/multi))*60;
//delay(100);
analogWrite(LED, flux);
Serial.println(flux);
}
``````

You are doing integer division `millis() / multi`. Integer division gives integer results. You need

``````  float multi = 500.0 ;
``````

as the sin(x) needs a float parameter you must make the var multi float, and as analogWrite needs an int flux should be an int.

Try this.

``````#define LED 9

float multi = 500.0;

void setup()
{
Serial.begin(115200);     // use max speed to
pinMode(LED, OUTPUT);
}

void loop()
{
float x = (1.0 * millis()) / multi;  // multiply by 1.0 to force float math
Serial.print("X: ");
Serial.print(x);

int flux = (1 + sin(x) ) * 127;  // goes from 0..254
analogWrite(LED, flux);
Serial.print("\t\tsin(x) : ");
Serial.println(flux);
}
``````

Thanks robtillaart, total newbie mistake so thanks for the patience guys
Acab