Show Posts
Pages: 1 [2] 3 4 ... 13
16  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino timer on: September 23, 2008, 10:41:12 am
If milliseconds is precise enough, you can use millis() which returns the number of milliseconds since last reset. Stick the current value of millis() in a variable, execute your task, than call millis() again and substract the previous value to get the number of elapsed milliseconds.

If you are worried about millis() itself taking some time and messing up your accuracy, you can test it by replacing your task with something like delay(10) and seeing if you get 10 elapsed ms. Try this with different values and if the error (if any) is consistent, you can probably substract that error from your results in the final sketch.
17  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with time delay in if_else statement on: September 20, 2008, 10:37:05 am
WOW!

Awesome project  :o  can't wait to see the finished product!
18  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with time delay in if_else statement on: September 19, 2008, 03:37:23 am
I'm not sure I understand the question, so if I'm being dense and stating the obvious, just bonk me on the head.

If you don't need to be doing anything else during those two seconds or waiting, and if you don't want the pins to go low as soon as the button is released, the simplest thing to do is:

Code:
  if( nunchuck_zbutton() ) {            
     digitalWrite(transistorPin2, HIGH);
     delay(2000);  
     digitalWrite(transistorPin1, HIGH);  
 }
 else {
     digitalWrite(transistorPin2, LOW);
     digitalWrite(transistorPin1, LOW);
 }

I suspect it's not that simple, tho. You probably want the pins to go low as soon the button is released, even if the two seconds have not elapsed yet and only the first pin is high. Correct?

If that is the case, you need to detect the button press, set the first pin high, and record the current time with millis(). You can then go about your business and periodically check to see if the button is released (set both pins to low) or if the current time exceeds the recorded time plus 2,000 milliseconds before the button is released (set second pin high). Note that the second condition requires you to keep track of the fact that the button is pressed and has not yet been released, so you will need a true/false variable to keep track of that if you are not in a dedicated loop doing nothing but monitoring the button.

This is conceptually similar to debouncing, which checks for stability in an input by waiting for a certain period with no change, so you might be able to adapt the debounce example's code for this.
19  Forum 2005-2010 (read only) / Interfacing / Re: Running 2 i2c instances simaltaneusly on: September 20, 2008, 08:19:13 am
Some devices also allow you to change the address over I2C, as well.

For example, the HMC6343 tilt-compensated compass from Honeywell stores its I2C slave address in EEPROM (at location0x00, default 0x32). Since it provides a write to EEPROM command, you can change the default if you should want two of these things on the same net.

Not that I have ever had a reason to do this. :-)
20  Forum 2005-2010 (read only) / Interfacing / Re: how to sync trigger pulse with PWM signal on: September 12, 2008, 12:49:39 pm
I may have misunderstood what you are trying to do, but wouldn't a 1/0.005=200Hz (rather than 200kHz) PWM signal with a duty cycle of 1 (out of the 1024 levels that library gives you) give you pretty close to a 5 uS pulse every 5mS?
21  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: November 13, 2008, 08:32:05 am
Nice! I like the pixelation effect from the PWM...
22  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: October 31, 2008, 06:26:04 pm
Wow, lovely work on the documentation!

Thank you  smiley
23  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: October 28, 2008, 11:38:44 am
Sorry, took a while to liberate some time for this, but here's my little test sketch trying to reproduce the situation where you have an uneven current value from pin 0 to pin 15 when the set value is low:

(The idea is that a 10k pot allows you to control the value being set for all sixteen LEDs.)

Code:
/*
 * Mathieu Glachant - Low value fader test sketch
 * Based on library by Alex Leone - acleone ~AT~ u.washington.edu
 * 2008-09-02 - v001
 *
 * Pin setup:
 * ------------                                             ---u----
 * ARDUINO   13|                                      LED2 |1     28| LED channel 1   (short leg (cathode), with the longer leg (anode) hooked up to +5V)
 *           12|                                      LED3 |2     27|-> GND
 *           11|                                      LED4 |3     26|-> SIN (pin 4)
 *           10|-> BLANK (pin 23)                     LED5 |4     25|-> SCLK (pin 6)
 *            9|-> XLAT (pin 24)                        .  |5     24|-> XLAT (pin 9)
 *            8|                                        .  |6     23|-> BLANK (pin 10)
 *            7|                                        .  |7     22|-> GND
 *            6|-> SCLK (pin 25)                        .  |8     21|-> VCC (+5V)
 *            5|                                        .  |9     20|-> 2K Resistor -> GND
 *            4|-> SIN (pin 26)                         .  |10    19|-> +5V
 *            3|-> GSCLK (pin 18)                       .  |11    18|-> GSCLK (pin 3)
 *            2|                                        .  |12    17|
 *            1|                                        .  |13    16|
 *            0|                                      LED15|14    15| LED channel 16
 * ------------                                             --------
 *
 * Put the longer leg of the LEDs in the +5V and the shorter leg in LED(1-16).
 * The 2K resistor between pin 20 and GND will let ~20mA through each LED.  The actual formula is
 *   Iref value = 39.05 / (desired current in A)           eg       1953Ohms = 39.06 / 0.020A
 *
 *
 * This sketch implements a fader based on the analog voltage at analog pin potPin (see constants below).
 */

#include <TLC5940LED.h>
#include <Wire.h>

#define NUM_TLCS      1
#define HMC6352Address  0x21
#define potPin          0  // Analog pot to set the overall brightness

void setup()
{
  Tlc.init(NUM_TLCS);
  Tlc.resetTimers();
  Wire.begin();
}

int readPot(float scale)
{
  return (int)(scale*analogRead(potPin)/1024);  // Read the analog voltage from the pot
}

void headingLED(int heading)
{
  Tlc.clear(); // sets all the channels to zero, but doesn't update
  for (uint8_t channel = 1; channel <= NUM_TLCS * 16; channel++)
  {
    Tlc.set(channel, heading);  //  Tlc.set(channel, value (0-4095))   this requires a Tlc.update() to set the values.
  }
  Tlc.update();
}

void loop()
{
  headingLED(readPot(4095));
  
  delay(5);
}

The short of it is, I can't reproduce it. Any value of the analog voltage from the control pot for which the LEDs are visibly lit, I see no difference from one end to the other of the ramp. All the LEDs are lit equally to my naked eye.

What am I doing differently from what you did to get your results?
24  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: October 24, 2008, 09:20:10 am
By the way, Mike, what happens if you remove LEDs from one end or the other while this is in effect? Do the LEDs all brighten slightly or does the effect seem to slide over?

I'm wondering if it's sensitive to how much current is being drained... or if it's just something it does at low values.
25  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: October 24, 2008, 09:16:41 am
Ah, so I should be able to reproduce this if I set the entire row to a uniform but low value, then... I'll try that when I have some time.
26  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: October 24, 2008, 07:52:33 am
Interesting... I've only used pager-type vibration motors, and the intensity felt the same to the touch. Also, in my application I only ever have two on at the same time, never the full sixteen.

What value for the current supply setting resistor did you pick, are you sure your motors don't draw more current than you picked that resistor for, and (sorry for the dumb questions) are you sure the datasheet says the chip can provide that current amount under the voltage you are supplying it with (from memory it's 120mA for 5V, but I'd need to check to be sure)?

I'll play around with mine here, see if I can reproduce this behavior.
27  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: September 03, 2008, 02:28:57 am
Quote
For people who want to use the TLC5940 to drive motors, use the old library from the first post for now.  The PWM period for the TLC5940LED library is fixed at 488Hz, which might be too fast for driving a DC motor.

As far as those 3V/80mA Sparkfun vibration motors are concerned, they seem to run fine at 500Hz, ramping up and down smoothly, based on prior experience. Alas, I won't be able to confirm with the TLC5940 for at least two weeks (vacation).

Quote
Just as a note, the TLC should act as GND for whatever you're using with it (voltage should flow from +5V, through whatever, and into the TLC pin).  

Thanks for the pointer. Turns out that's how I had it wired in the old setup (PWM pins on the low side) but now I'll make sure to carry it over to the TLC5940 setup.
28  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: September 02, 2008, 08:30:22 am
Samples in the mail, yippee!
29  Forum 2005-2010 (read only) / Development / Re: Library for TLC5940 16-channel PWM chip on: September 01, 2008, 07:42:35 am
Thanks for the library!

I'm going to get my hands on a sample TLC5940 and try it, it seems like the perfect solution to drive 16 small vibe motors (haptic hatband, don't ask :-) ) with that 120mA per output rating!
30  Forum 2005-2010 (read only) / Français / Re: [APL] Voir au travers d'une souris on: August 31, 2008, 04:00:01 pm
Mais il se passe des choses vraiment interessantes dans la partie Gauloise du site! :-)
Pages: 1 [2] 3 4 ... 13