Show Posts
Pages: 1 ... 12 13 [14]
196  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Equivalent of Pulsout command? on: March 29, 2007, 10:51:26 pm
You can do this, but you need to use the IO registers directly.
Figure out which port and pin number you are needing to alter and then you can do something like...
PORTD |= _BV(3);  // turn on pin 3 of port d
PORTD &= ~_BV(3); // turn off pin 3 of port d
_BV(3) is just a macro that makes the bit mask for bit 3, PORTD is the IO register. That will get you a fraction of a microsecond of on time for your pin. You can use the high level functions like pinMode() to set up the pin and then use these for the timing critical part. Don't use a variable in the _BV() if you can help it, it makes dramatically slower code.

The hardware page has a link to the pinout picture for Arduinos. You can see which port and pin a given digital pin is on.
197  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Equivalent of Pulsout command? on: March 29, 2007, 05:43:13 pm
If you set a digital pin to be an output, then digitalWrite() it to 1 and digitalWrite() it back to 0 you will have made a pulse just under 10 microseconds long. That is pretty close to Pulsout.  You could put a delayMicroseconds() call in between to make it longer.
198  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Reading a pushbutton on the analog ins. on: March 17, 2007, 10:29:15 am
Should work. Use a pull-up resistor, say 10k, and let the switch pull it down. You can read it as an analog value and decide if it is a large or a small number.

I think at the hardware level there is nothing stopping you from just using those pins as digital inputs, but you couldn't use digitalRead() on them. You'd have to read the port and check the proper bit.
199  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Blinking LED help! on: January 23, 2007, 02:08:11 pm
if ( countdown = 1) ... you mean to have a "==" there.
That will get you to your next bug.  (timer will go down by 100 each time into negative numbers, causing huge delays or near zero delays depending how delay() is written.)

You may wish to put in some serial printing as debugging info while you work out the logic...
 Serial.print(" countdown=")
 Serial.print(" timer=");
.. click the little rectangle with a lollypop sticking out of the top in the toolbar to get the serial monitor running after you download your program.
Pages: 1 ... 12 13 [14]