Go Down

Topic: Multiplex IR LED's? (Read 7 times) previous topic - next topic

Grumpy_Mike

The code is nearly right but you only do one column per refresh not all of them.
You are only sourcing one LED's current per shift register pin so that is fine but check on the data sheet that the total package current is OK, it depends on what type of shift register you get, that is given by the letters before the 595 bit, you might have to use LS or HS type. The darlingtons are good for 500mA per pin.

xXN1pplefaceXx

I also forgot to ask, how would I generate a 38khz wave for the IR Emitters so the detectors can sense the IR signals?

Grumpy_Mike

You love springing surprises don't you. You said at the start that the IR carried no data, now you are saying they are modulated!!!
Well modulation is data, what sort of sensor do you have, part number? This changes again how you should do things.

xXN1pplefaceXx


The code is nearly right but you only do one column per refresh not all of them.
You are only sourcing one LED's current per shift register pin so that is fine but check on the data sheet that the total package current is OK, it depends on what type of shift register you get, that is given by the letters before the 595 bit, you might have to use LS or HS type. The darlingtons are good for 500mA per pin.

OOOOOOOohhhh omg I understand now :D

Firstly, the datasheet for the 595s Im getting say the max continuous output current is 35mA I think, http://www.jaycar.com.au/products_uploaded/ZC4895.pdf But I dont know if thats per pin or not?

Ok now to the good part :P, I think I have got it, and I wrote up the code, not psuedocode:
This works if the ULN2803 inverts I have read that it does but im still not sure, on your site It says they do or is that for the FET's?

Code: [Select]

const int latchPin = 4;
const int clockPin = 3;
const int dataPin = 2;

byte displayData [ ] = {
B11111111,
B10000001,
B10111101,
B10100101,
B10100101,
B10111101,
B10000001,
B11111111,
B11011011,
B11111111,
B11111111,
B11111111};
int rowCount = 0;

long int refreshDue;
long int refreshTime = 10;

void setup() {
  pinMode(dataPin, OUTPUT); //Data
  pinMode(clockPin, OUTPUT); //Clock
  pinMode(latchPin, OUTPUT); //Latch
}
void loop() {
  if(millis() >= refreshDue){
    refreshDue = millis() + refreshTime;
    refreshDisplay();
  }
}

void refreshDisplay(){

  if (rowCount>=12)rowCount=0;
 
  byte rowData;
  byte col1Data;
  byte col2Data;
 
  rowData = displayData[rowCount];
 
  if (rowCount<=7){
    col2Data=B00000000;
    col1Data=byte(rowCount+1);
  }else if (rowCount>=8{
    col2Data=byte((rowCount-8)+1);
    col1Data=B00000000;
  }
 
  digitalWrite(latchPin, LOW);
  shiftout(dataPin, clockPin, MSBFIRST, col2Data);
  shiftout(dataPin, clockPin, MSBFIRST, col1Data);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);
  digitalWrite(latchPin, HIGH);

  rowCount ++;
 
}

(I also used alot of your code, thanks bro :P)

There is one minor flaw in this code...
instead of refreshing left to right, or right to left (which is what I wanted)
it refreshes or the bit walks like this (_ means that its not used shift register pin)
00000001 0000 _ _ _ _
00000010 0000 _ _ _ _
00000100 0000 _ _ _ _
00001000 0000 _ _ _ _
00010000 0000 _ _ _ _
00100000 0000 _ _ _ _
01000000 0000 _ _ _ _
10000000 0000 _ _ _ _
00000000 0001 _ _ _ _
00000000 0010 _ _ _ _
00000000 0100 _ _ _ _
00000000 1000 _ _ _ _

Also I believe you mean HC, I cant find any HS595's anywere :P

P.S: I saw your post whilst I was posting a reply to the other one :P, I dont mean to spring the surprise, I was using just a photodiode and hoping it would work, when I realised the part that I ordered from sparkfun wasnt a photodiode but rather a reciever Lol, fail, so then I just thought since the instructable I was following before was a load of crap and I might as well actually use the reciever it could give me a better result :)
This is the part:  TSOP38, can be found here: http://www.sparkfun.com/products/10266
But I might have to order from somewhere else as they only take credit card and use something like this: http://www.jaycar.com.au/productView.asp?ID=ZD1952&form=CAT2&SUBCATID=976#1
which is way too overpriced for me :(
I would prefer to use this: http://www.electus.co.nz/productView.asp?ID=6149&CATID=33&keywords=&SPECIAL=&form=CAT&SUBCATID=140 but I dont know how to use it with the emitter, all examples use reciever breakouts and stuff :(

Thanks Mike :D

Grumpy_Mike

With your code, have the walking 1 variable as a global like the rowCount. Change it each time by a:-
Code: [Select]
walk1 = walk1 << 1;
Reset it to 1 when you reset the rowCount. Then there is no need to calculate the col2Data or col1Data simply output the walk1 value:-
Code: [Select]
  shiftout(dataPin, clockPin, MSBFIRST, walk1 >> 8);
  shiftout(dataPin, clockPin, MSBFIRST, walk1);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);


You better say what your application is because I suspect that the sensor you have is not suitable. Look at the data sheet and you will see that you can't carry on giving it pulses and expect the output to say at one level. If you want to just detect when a beam is broken you need the TSOP4038 sensor.

Go Up