How to use floats for delay?


hello everyone, having issue here regarding delays , float values.  doing i'm trying write sample program make arduino turn light on , off on pin 6. such can input frequency , duty cycle , read oscilloscope.  have feeling datatype associated "delay" may integer or long double or something.   

most of math according friend of mine, , seems work we're doing(we calculated on paper), thing think delay somehow related integer or long double.  if put float value delay, seems decimal gets cut off.

for example, if  calculated 0.003, think cuts off decimal , tries make delay 0 since integers or long doubles don't take decimals.

am correct in assumption?  if correct --what approach can take fix this?  there way use floats delays?





code: [select]
/*
  blink stuff

  modified 21 may 2014

 */

float f; //just declares f float datatype
float x; //just declares x float datatype
float y; //just declares y float datatype
float dc;//just declares dc float datatype
float a; //just declares a  float datatype

 
// setup function runs once when press reset or power board
void setup() {
  serial.begin(9600);
  pinmode(6, output);
  f= 1; // input number frequency in hz
  dc=70; //input duty cycle
  x= 1/f; //frequency
  y= dc/100*x; //this duty cycle
  a= x-y; //a second delay, time part of square wave arduino doesn't anything
 
}


// loop function runs on , on again forever
void loop() {


  digitalwrite(6, high);   // turn led on (high voltage level)
  delay(a);  // delay amount of milliseconds
  serial.print("a decimal is\n");  // make monitor display "a desimal is"
  serial.print(a, dec);  //print whatever float value supposed in decimal
  serial.print("....mkayyy?\n"); //i put here because carriage return being dumb
  digitalwrite(6, low);    // turn led off making voltage low
  delay(y);             // wait y amount of milliseconds
  serial.print("y decimal is\n");  // display "y decimal is" on monitor
  serial.print(y,dec);  //take floar value in , output decimal answer
   serial.print("....mkayyy?\n");  //cheap solution dumb carriage return
 
}

why?

its argument milliseconds, , not delay less 1 ms.

so delay of .003 makes no sense. if want such short delay, use delaymicroseconds(), granularity 4 us, can't 3 either.


Arduino Forum > Using Arduino > Programming Questions > How to use floats for delay?


arduino

Comments