Transmission speed

Hi, i would like to ask if anyone knows the solution to a little problem i have.

I'm using this circuit http://sweb.cityu.edu.hk/sm2608/styled-10/ (Multiple Inputs - Parallel to Serial Shift Registers 4021), that use a program similar to http://arduino.cc/en/Tutorial/ShftIn12 , well what i have to do is multiplex 16 buttons and for example if i press the 5th button there is a program that is executed.

My problem is the time between i press the button and the program is executed, i have to stay pressing the button until the Tx Led is ON meaning the information was send to the pc and i can see in the serial monitor what button i press.

I tried to delete or changing some stuff in the program but the speed of transmission is always the same, i have another program that does the same but the speed is much slower but yet i don't find it there too.

What i would like to do is knowing in the program where is the part saying the speed of transmission and/or if someone know a way to make it do what i expect it to do, the best was that only when i press the button that it send the information (^^')

If someone can help I would appreciate it very much :slight_smile:

If someone can help I would appreciate it very much

If someone can post some code, we can help very much.

Look at blink without delay.

Mark

I tried to delete or changing some stuff in the program

...but I didn't post either the code I deleted or the code that's left.

Just in case the above posts are too subtle Dio07master, post your code.


Rob

The links i gave with the names were the places where i got the code, because it was more than one, i didn't want to make a too long post with all in it, but again sorry about that and thank you for replying.
My two next posts are the code i tried.
First - Fast Transmission speed but while pressing the button it might transmit 3-5 times
Second - Very slow transmission speed and i have to stay pressing the button for a while until it transmit once

P.S. i put the two so because maybe one is easier to understand

int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

void setup() {
  Serial.begin(9600);  // start serial

  pinMode(latchPin, OUTPUT); // setup pin modes
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);
}

void loop()
{
 //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin, HIGH);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(1000000); // one second delay
  //set it to 0 to transmit data serially 
  digitalWrite(latchPin, LOW);

  for (int i=0; i<8; i++)
  {
    // read data
    int temp = digitalRead(dataPin);
    Serial.print(temp); 

    // trigger next input (LOW -> HIGH)
    digitalWrite(clockPin, HIGH);
    delayMicroseconds(2);
    digitalWrite(clockPin, LOW);
    delayMicroseconds(2);
  }

  Serial.println();
  delay(200);
}
//define where your pins are
int latchPin = 8;
int dataPin = 9;
int clockPin = 7;

//Define variables to hold the data 
//for shift register.
//starting with a non-zero numbers can help
//troubleshoot
byte switchVar1 = 72;  //01001000

void setup() {
  //start serial
  Serial.begin(9600);

  //define pin modes
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT); 
  pinMode(dataPin, INPUT);

}

void loop() {

  //Pulse the latch pin:
  //set it to 1 to collect parallel data
  digitalWrite(latchPin, HIGH);
  //set it to 1 to collect parallel data, wait
  delayMicroseconds(2000);
  //set it to 0 to transmit data serially  
  digitalWrite(latchPin, LOW);

  //while the shift register is in serial mode
  //collect each shift register into a byte
  //the register attached to the chip comes in first 
  switchVar1 = shiftIn(dataPin, clockPin);

  //Print out the results.
  //leading 0's at the top of the byte 
  //(7, 6, 5, etc) will be dropped before 
  //the first pin that has a high input
  //reading  
  Serial.println(switchVar1, BIN);

//white space
Serial.println("-------------------");
//delay so all these print satements can keep up. 
delay(1000);

}

//------------------------------------------------end main loop

////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0

byte shiftIn(int myDataPin, int myClockPin) { 
  int i;
  int temp = 0;
  int pinState;
  byte myDataIn = 0;

  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, INPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop

//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
  for (i=7; i>=0; i--)
  {
    digitalWrite(myClockPin, LOW);
    delayMicroseconds(0.2);
    temp = digitalRead(myDataPin);
    if (temp) {
      pinState = 1;
      //set the bit to 0 no matter what
      myDataIn = myDataIn | (1 << i);
    }
    else {
      //turn it off -- only necessary for debuging
     //print statement since myDataIn starts as 0
      pinState = 0;
    }

    //Debuging print statements
    //Serial.print(pinState);
    //Serial.print("     ");
    //Serial.println (dataIn, BIN);

    digitalWrite(myClockPin, 1);

  }
  //debuging print statements whitespace
  //Serial.println();
  //Serial.println(myDataIn, BIN);
  return myDataIn;
}

AWOL:

I tried to delete or changing some stuff in the program

...but I didn't post either the code I deleted or the code that's left.

I thought that putting the links was good, putting all the code in one post uhmm it seemed a lot ^^'

As I said see blink with out delay. - your program does nothing at all while in a delay other than wait for the end of the delay - so it wont see any button pushes until the delay is complete.

Mark

putting all the code in one post uhmm it seemed a lot

Putting it inside code tags would have been, uhmm, better.

AWOL:

putting all the code in one post uhmm it seemed a lot

Putting it inside code tags would have been, uhmm, better.

I don't know yet how to do things the best way here ^^'

holmes4:
As I said see blink with out delay. - your program does nothing at all while in a delay other than wait for the end of the delay - so it wont see any button pushes until the delay is complete.

Mark

I will try your idea today and see the result. I didn't understand very much the link between the two things but i can see your concept :slight_smile:

Dio07master:

AWOL:
Putting it inside code tags would have been, uhmm, better.

I don't know yet how to do things the best way here

Ahh, well, actually dead easy.

Go back to each of your previous submissions with code, choose "modify", highlight the code part and click on the "Code" button - the one with the "hash" [ # ] symbol and it will tag that code for you.


Done!

Terrific!

holmes4:
As I said see blink with out delay. - your program does nothing at all while in a delay other than wait for the end of the delay - so it wont see any button pushes until the delay is complete.

Mark

Well i tested and i also saw something that i had a wrong idea about, thanks for this tip and thank you all that saw this ^^

In a way it was my idea that was really bad on what the program does