Pages: 1 [2]   Go Down
Author Topic: trying to control 37leds with 5x 74HC595  (Read 1756 times)
0 Members and 1 Guest are viewing this topic.
Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 44
Posts: 2463
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i guess that the shift out function isn't the best way to work with...
I'm thinking te create a for loop with the unsigned long long variable
and then just always multiplying (*2) each bit..

You know how I know you didn't run or look at my sketch?  smiley-confuse
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i guess that the shift out function isn't the best way to work with...
I'm thinking te create a for loop with the unsigned long long variable
and then just always multiplying (*2) each bit..

You know how I know you didn't run or look at my sketch?  smiley-confuse

I did runned your sketch and looked at it in the serial but i didn't know how to send it out to my shift register..
Now i am writting my own sketch with some parts from your sketch and trying to make it work for my hardware..
« Last Edit: March 16, 2012, 08:41:26 am by kjellebormans » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 597
Posts: 33314
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if someone else has a other idea about how it could work to he may always post it idea
Why so you can ignore that as well?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if someone else has a other idea about how it could work to he may always post it idea
Why so you can ignore that as well?

Sorry grumpy_mike but i need to use the Shift register and i need to keep it as cheap as possible ..
so if i use spi i need to make my project more expensiver and i am on the limit rigth know..
i got 5 shift registers, enough leds and the arduino and that are the things i only can use for this project.
because the software steering is hard because i can't split up the unsigned long long into 5 or more pieces because the shift register works with an 8bit system so you need to send 5times 8bits you can't send them in one piece.. The highbits and lowits from the arduino software just splits a unsigned long or word but the split in 2 thats easy because you just have 16 bits .. but the unsigned long long got 64 bits if you use highbit and lowbit on that i don't know what you will get but it isn't the upers 32bits and the other 32 bits that i would need to split up again untill its 8bits / piece .. i am know wondering if it would work on a other methode .. i 'm trying to just read in one bit and then shift them on a randomspeed from 0->36-0->36-->....
i hope you understand me smiley
greetzz kjelle
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

so if i use spi i need to make my project more expensiver and i am on the limit rigth know..

Why? I used SPI to drive some 595s. It's built into the processor. It's hardly an expense.

I don't understand the rest of what you said. You don't need to put things into an unsigned long. Why would you even do that?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but the unsigned long long got 64 bits if you use highbit and lowbit on that i don't know what you will get but it isn't the upers 32bits and the other 32 bits that i would need to split up again untill its 8bits / piece

Sorry, that's just not making sense.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Re: trying to control 37leds with 5x 74HC595

All you need to do is set up the 5 x 8 bits that you want to display in 5 bytes. Then:

Code:
SPI.transfer (a);
SPI.transfer (b);
SPI.transfer (c);
SPI.transfer (d);
SPI.transfer (e);

That's it. No longs, long longs, or anything.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 597
Posts: 33314
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i hope you understand me
No I don't.

Quote
and that are the things i only can use for this project.
Sounds like a school assignment then. If so it is designed to make you learn stuff and this is what you are refusing to do. So far in terms of learning you should get an F.

Quote
because the shift register works with an 8bit system so you need to send 5times 8bits you can't send them in one piece
That is just rubbish.

Quote
and then shift them on a randomspeed from 0->36-0->36-->.
In reply #8 I gave you code to do this. But you just ignored it.

Quote
i am on the limit rigth know..
No you are not at the limit you are way beyond knowledge and into fairy land.
Why bother asking a question if you just ignore the answer.
If you don't understand the answer then ask about what you don't understand.
There are lots of ways to tackle your problem. None of them are as hard as the solution your misunderstandings are forcing to to try and implement.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i thank you all for trying to help me out smiley
but know i figured it out with some help offcourse smiley

tnx to http://bildr.org/2011/02/74hc595/#

Code:
int SER_Pin = 8;   //pin 14 on the 75HC595
int RCLK_Pin = 9;  //pin 12 on the 75HC595
int SRCLK_Pin = 10; //pin 11 on the 75HC595

//How many of the shift registers - change this
#define number_of_74hc595s 5

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

int Randomwaarde;
int del = 5 ;
void setup(){
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);

  //reset all register pins
  clearRegisters();
  writeRegisters();

  randomSeed(analogRead(3));
  Randomwaarde = random(190, 210);
  Serial.println(Randomwaarde);
}              

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    registers[i] = LOW;
  }
}

//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

void loop(){


  for (int x=0; x<=36; x++)
  {
    if (del <= Randomwaarde)
    {
      setRegisterPin(x, HIGH);
      writeRegisters();
      delay(del);
      setRegisterPin(x, LOW);
      writeRegisters();
      del = del +1;
    }
    else
    {
      setRegisterPin(x, HIGH);
      writeRegisters();
      delay(10000);
      setRegisterPin(x, LOW);
      writeRegisters();
      del = 5;

    }

  }
}

« Last Edit: March 19, 2012, 05:32:35 am by kjellebormans » Logged

Pages: 1 [2]   Go Up
Jump to: