Pages: [1]   Go Down
Author Topic: serial read  (Read 612 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
i interfaced two HEF4794B - works fine as standalone with the code example "shift out".
But now I would like to send over PD a word (highbyte, lowbyte) to the serial port and store the incoming hbyte and the lbyte again in a word, to control the 16 Leds at the same time....
(with just one driver and only 8 leds it works fine:)
Code:
void loop()
{
   // send data only when you receive data:
      if (Serial.available() > 0) {
            // read the incoming byte:
            dato = Serial.read();
    }
        
    for (count = 0; count < 8; count++) {
    digitalWrite(data, dato & 01);
    //serialWrite((dato & 01) + 48);
    dato>>=1;
    if (count == 7){
    digitalWrite(oe, LOW);
    digitalWrite(strob, HIGH);

    }
    PulseClock();
     digitalWrite(oe, HIGH);
 }

  delayMicroseconds(10);
  digitalWrite(strob, LOW);
  delay(10); // waits for a moment
}
but with the word I will have a memory problem with the int - so i'm wondering if i can use (in arduino) as well unsignded int (uint)?
by including which library? (pascal stangs avr/io?)
or do i have to use arrays to read over the serial port more than one incoming byte? (like described in the serialComm-string example)....but how do I get then again a "word" out of this single chars?
thanks a lot for any help, as you can see, i'm a newbeee;)
lisarosen
Logged

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

hello again, this is a self-answer;
yes:)) I can use instead of an int a unsigned, as I found in the keywords.txt in the libfolder of arduino...
reading more than one byte is no problem, because they get buffered....???
and this modified code (originally shift_out) works now perfect with pd or max, sending simultaneously a high- and a lowbyte, whenever i like to change the lightpattern of the 16 leds;)
Code:
int data = 9;
int strob = 8;
int clock = 10;
int oe = 11;
int count = 0;
int dato = 0;
int dato2 = 0;
unsigned datostored = 0;
unsigned datoo = 0;

void setup()
{
  beginSerial(9600);
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(strob, OUTPUT);
  pinMode(oe, OUTPUT);
}

void PulseClock(void) {
    digitalWrite(clock, LOW);
    delayMicroseconds(2);
    digitalWrite(clock, HIGH);
    delayMicroseconds(5);
    digitalWrite(clock, LOW);
}

void loop()
{
   // send data only when you receive data:
      if (Serial.available() > 0) {
            // read the incoming byte:
            dato = Serial.read();
                dato2 = Serial.read();
    }
        else {datoo = datostored;
    }
    datoo = (dato * 256) + dato2;
    for (count = 0; count < 16; count++) {
    digitalWrite(data, datoo & 01);
    //serialWrite((dato & 01) + 48);
    datoo>>=1;
    if (count == 15){
    digitalWrite(oe, LOW);
    digitalWrite(strob, HIGH);

    }
    datostored = datoo;
    PulseClock();
     digitalWrite(oe, HIGH);
 }

  delayMicroseconds(10);
  digitalWrite(strob, LOW);
  delay(10); // waits for a moment
}
Logged

Pages: [1]   Go Up
Jump to: