Show Posts
Pages: [1] 2
1  Using Arduino / LEDs and Multiplexing / TLC5940 randomized fade and colour change. tlc_fades.h on: June 25, 2013, 07:18:33 pm
So I'm trying to come up with a way to make a randomly twinkling, randomly colour changing set of 5 LEDs, that means its brightness varies randomly over time as does the hue independently. I'm using a TLC5940 to try and achieve this. However I'm not sure how to approach this, more specifically I'm not sure I fully understand how to use the fades extended library (tlc_fades.h).

would something like this be possible. This is pseudo-code, not part of any workable code yet, just me trying to see how I should approach the problem.

Code:
  if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
      uint16_t duration = twinkle_transition+random(twinkle_transition_offset);
      uint32_t twinkle_startMillis = millis() + 50;
      uint32_t twinkle_endMillis = startMillis + duration;
     
      duration = colour_transition+random(Colour_transition_offset);
      uint32_t colour_startMillis = millis() + 50;
      uint32_t colour_endMillis = startMillis + duration;
     

      RGBArray1=HSBtoRGB(Hue,saturation,brightness+random(brightness_offset);
      RGBArray2=HSBtoRGB(Hue+random(hue_offset),saturation,brightness;
      for (int j=0; j<NUM_LEDS; j++){
       for (int i=0; i<3; i++){
         tlc_addFade(LED[j][i],Old_RGB[i],RGBArray1[i], twinkle_startMillis, twinkle_endMillis); //channel, fromRGB, toRGB, startMillis, endMillis
         tlc_addFade(LED[j][i],Old_RGB[i],RGBArray2[i], colour_startMillis, colour_endMillis);}}

what happens when you have overlapping timeframes for tlc_addFade? My guess is that there is no way this will work with tlc_addFade unless you split it up to calculate individual fades in each smaller random segment by doing a test for the smaller duration then calculating intermediate RGB values. What is your best approach for adding independent brightness and hue transitions?
 
2  Using Arduino / Project Guidance / Re: TLC5940 LEDs in series. on: June 20, 2013, 09:20:53 am
I was more just wondering if I could make use of the extra unused pins but more LEDs are not really a requirement, partially because of space constraints and the perfboard I'm using.

it seems that the SoftPWM and tlc5940 libraries both use timer2 so it was a no go. I actually gave it a shot anyway. Lets just say I'm fortunate to not have epilepsy because the results weren't what I was expecting.
3  Using Arduino / Project Guidance / Re: TLC5940 LEDs in series. on: June 18, 2013, 09:54:53 am
So I thought about using SoftPWM with the TLC5940 library to try and control more LEDS from the unused arduino pins but it seems SoftPWM and the TLC5940 library do not play nice with eachother. Is there any way to use the additional arduino pins to control additional 20ma RGB LEDs or should I give up on that idea?
4  Using Arduino / Sensors / Re: Hall Effect Wheel Speed, next step on: June 18, 2013, 09:21:21 am
You have to use interrupts, there are a number of ways. Make sure your hall sensor can switch fast enough too

http://www.societyofrobots.com/robotforum/index.php?topic=14973.0

German but you can use google translate and code is still the same
http://saduino.ch/mechatronic/index.php?article=umdrehungsgeschwindigkeit-von-stirling-motor-mit-hallsensor-messen

This code also depends on whether you have a latch sensor or not.
5  Using Arduino / Project Guidance / Re: TLC5940 LEDs in series. on: June 11, 2013, 03:07:58 pm
Thanks mike for your reply. The LEDS are common anode so you are right, it's a 4 pin LED that can only be connected in parallel. Can I place them in parallel with a resistor for each and just have no resistor to ground on Rref?
6  Using Arduino / Project Guidance / TLC5940 LEDs in series. on: June 10, 2013, 02:26:05 pm
I have a single tlc5940 and plan to use 8 RGB Leds with it. 4 on their own channels and 4 in series on a single channel. Am I right in thinking this is OK to do and that I can use the same R(I ref) resistor with or without the LEDs in series?
7  Using Arduino / Programming Questions / Re: enum and switch cases on: April 19, 2013, 07:57:21 am
@pYro_65, Yes ofcourse you are right, my mistake there.

@PaulS Well this isn't actually part of any code, it's just me thinking out loud with examples of enum switch cases from the internet. I'm not sure how complete code will help but nonetheless here is a complete sketch I wrote based on them as an example where enum instances are not hardcoded:

Code:
String content = "";
char character;
enum Color { UNDEF, RED, ORANGE, YELLOW, GREEN,  BLUE, PURPLE };
Color clr;

void setup(){
}

void loop()
{
 
  while(Serial.available()) {
      character = Serial.read();
      content.concat(character);
  }

  if (content != "") {
    clr=content;
    switch (clr)
    {
      case UNDEF: break;
      case RED: clr = BLUE; break;
      case BLUE: clr = YELLOW; break;   
      // etc
      default: break;
    }
  }
}

In this example if it reads "RED" on the serial it changes "clr" to BLUE. That is if it compiled.

is the use of an enum switch-case pointless in anything but hardcoded use?
8  Using Arduino / Programming Questions / enum and switch cases on: April 18, 2013, 07:48:36 pm
Perhaps I'm not very good with google search but I cannot figure out how to use enum with switch-case. The examples I've seen (including on this forum) look like this:

Code:
enum Color { UNDEF, RED, ORANGE, YELLOW, GREEN,  BLUE, PURPLE };

void setup()
{
  Color clr = RED;
 
  switch (clr)
  {
    case UNDEF: break;
    case RED: clr = BLUE; break;
    case BLUE: clr = YELLOW; break;   
    // etc
    default: break;
  }
}

void loop()
{
}

However these examples do not seem practical since the enum instance is always hardcoded in them.
Is there something like Enum.Parse in the arduino IDE? since code like this will throw a compiler error

at Color clr = arg:

Code:
char *arg;
arg = //*Some output from some function*;
enum Color { UNDEF, RED, ORANGE, YELLOW, GREEN,  BLUE, PURPLE };
Color clr = arg;
...
which obviously throws the error
Code:
cannot convert "char*" to "clr" in initialization

Is there a special trick I can use similar to Enum.Parse in C#? or am I better off just using "if, else if"?
9  Using Arduino / General Electronics / Re: replacing pushbutton in unknown circuit with optoisolator on: March 31, 2013, 07:16:24 am
Hi dc.
I have, it's ~12V. The pc817 has the following max ratings on the output:

Collector-emitter voltage, VCEO: 35 V
Emitter-collector voltage, VECO: 6V
10  Using Arduino / General Electronics / replacing pushbutton in unknown circuit with optoisolator on: March 30, 2013, 07:58:13 pm
I have successfully replaced a push button with an optoisolator for arduino control of an unknown circuit. Everything works fine so far but I wish to know if I might run in to trouble later. I measured the current across the switch of the unknown circuit as 1.6mA. I'm using a Sharp pc817 optoisolator which has a CTR of 50% and a max current of 50mA. on one side of the optocoupler (LED Side) is an arduino output pin and a 150 Ohm resistor to limit current. On the other side (transistor side) I put no resistor at all. is this OK? I assumed that the current will be limited to 1.6mA so there was no need for one but I'm not sure if it is safe.
11  Using Arduino / Interfacing w/ Software on the Computer / Re: bluetooth on: February 15, 2013, 05:31:52 am

did you see exactly this when you did rfcomm?:

Code:
rfcomm0: xx:xx:xx:xx:xx:xx channel 1 clean

(without xx:xx... of course ) Make sure you didn't get something else. It would be nice to see a complete copy of your terminal output while you are doing these things too. It's difficult to diagnose a problem without knowing what exactly happened.

Do
Code:
$ sdptool browse local

You should find something like this in the output

Code:
Service Name: Serial Port
Service Description: COM Port
Service Provider: BlueZ
[...]
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
  Channel: 1

then do

sdptool records xx:xx:xx:xx:xx:xx

(with your BT shield address)
you should see something like

Code:
Service Name: SPP
[...]
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 1

make sure all the channel numbers match each other and your rfcomm.config file. Also make sure your cat and echo commands output file name match the actual rfcomm. e.g make sure it isn't >/dev/rfcomm0 when your shield is on rfcomm1.

If that still doesn't work then I've ran out of ideas, maybe your bluetooth shield is faulty.
12  Using Arduino / Interfacing w/ Software on the Computer / Re: bluetooth on: February 12, 2013, 02:39:23 pm
OK lets do things manually, do not rely on blueman. remove any pairing there. Then do
 
   
Code:
    $ sudo sdptool add SP
    $ sudo /etc/init.d/bluetooth restart
    $ sudo rfcomm bind all
    $ rfcomm

you should see
Code:
rfcomm0: xx:xx:xx:xx:xx:xx channel 1 clean

then
Code:
cat /dev/rfcomm0
open another terminal and do
Code:
echo Hi > /dev/rfcomm0

let me know if you don't get a response in the first terminal.
13  Using Arduino / Interfacing w/ Software on the Computer / Re: bluetooth on: February 07, 2013, 08:34:09 am
Do

Code:
cat /etc/bluetooth/rfcomm.conf

and post the output.

My one looks something like this:
Code:
rfcomm0 {
         # Automatically bind the device at startup
         bind yes;
         # Bluetooth address of the device
         device xx:xx:xx:xx:xx:xx;
         # RFCOMM channel for the connection
         channel 1;
         # Description of the connection
         comment "Arduino";
}

again where "xx:xx:xx:xx:xx:xx" would be the address for your particular bluetooth shield.
14  Using Arduino / Interfacing w/ Software on the Computer / Re: bluetooth on: January 29, 2013, 09:52:24 am
I don't know what the problem could be, far too many things could be wrong and without being able to see how your linux box or shield is set up it's hard to say. when you type "rfcomm" at the command line does it show your bluetooth device?

Code:
rfcomm0: xx:xx:xx:xx:xx:xx channel 1 closed

where "xx:xx:xx:xx:xx:xx" is the address of your particular bluetooth shield?
15  Using Arduino / General Electronics / Re: Types of Opto-isolators on: January 27, 2013, 07:18:24 am
Thanks dc42. I think I understand the concept of a triac now. The isolated circuit would need to drop below threshold voltage on the  main terminals of the triac otherwise it will remain on indefinitely. This happens automatically on an AC circuit at a given frequency but not on a DC circuit. Darlington pair opto-isolators it is then. Thanks again for your help.
Pages: [1] 2