Difference between revisions of "DelayMicroseconds"

From Pinguino
Jump to: navigation, search
(Description)
m (Example: re-indent)
 
Line 26: Line 26:
 
  void setup(void)
 
  void setup(void)
 
  {
 
  {
pinMode(0,OUTPUT);
+
pinMode(0,OUTPUT);
 
  }
 
  }
  
 
  void loop(void)
 
  void loop(void)
 
  {
 
  {
PORTBbits.RB0 = 0xff;
+
PORTBbits.RB0 = 0xff;
delayMicroseconds(pulsewidth);
+
delayMicroseconds(pulsewidth);
PORTBbits.RB0 = 0;
+
PORTBbits.RB0 = 0;
delayMicroseconds(pulsewidth);
+
delayMicroseconds(pulsewidth);
PORTBbits.RB0 = 0xff;
+
PORTBbits.RB0 = 0xff;
delayMicroseconds(pulsewidth);
+
delayMicroseconds(pulsewidth);
PORTBbits.RB0 = 0;
+
PORTBbits.RB0 = 0;
delayMicroseconds(pulsewidth);
+
delayMicroseconds(pulsewidth);
 
  }
 
  }
 
</source>
 
</source>

Latest revision as of 10:35, 7 March 2011

Name

delayMicroseconds - Wait for a specified amount of time

Description

Pause for a NUMBER micro-seconds.

Since
Beta 10 (?)

Syntax

delayMicroseconds(time);
time
delay time in microseconds.
Valid values from 1 to 65535 microseconds.
Argument type: unsigned int
Output
none

Example

 // Test for delayMicroseconds function:
 // Modify the value of pulsewidth, and check 
 // the square wave at user pin 0 with specified width.
 // by Jesús Carmona Esteban
 // to be compiled with Pinguino IDE 10 or upper.

 unsigned int pulsewidth=2;

 void setup(void)
 {
 	pinMode(0,OUTPUT);
 }

 void loop(void)
 {
 	PORTBbits.RB0 = 0xff;
	delayMicroseconds(pulsewidth);
	PORTBbits.RB0 = 0;
	delayMicroseconds(pulsewidth);
	PORTBbits.RB0 = 0xff;
	delayMicroseconds(pulsewidth);
	PORTBbits.RB0 = 0;
	delayMicroseconds(pulsewidth);
 }

Bugs

There is a bug at IDE versions previous to Beta 10, and DelayMicroseconds function produce a much larger microseconds delay than specified by argument. At Beta 10 IDE and later versions this delayMicroseconds function produces the exact amount of microseconds delay.

See also

Delay

Comments