serial read


hello,
i interfaced 2 hef4794b - works fine standalone code example "shift out".
but send on pd word (highbyte, lowbyte) serial port , store incoming hbyte , lbyte again in word, control 16 leds @ same time....
(with 1 driver , 8 leds works fine:)
code: [select]

void loop()
{
  // send data when receive data:
     if (serial.available() > 0) {
           // read 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 moment
}

but word have memory problem int - i'm wondering if can use (in arduino) unsignded int (uint)?
by including library? (pascal stangs avr/io?)
or have use arrays read on serial port more 1 incoming byte? (like described in serialcomm-string example)....but how again "word" out of single chars?
thanks lot help, can see, i'm newbeee;)
lisarosen

hello again, self-answer;
yes:)) can use instead of int unsigned, found in keywords.txt in libfolder of arduino...
reading more 1 byte no problem, because buffered....???
and modified code (originally shift_out) works perfect pd or max, sending simultaneously high- , lowbyte, whenever change lightpattern of 16 leds;)
code: [select]
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 when receive data:
     if (serial.available() > 0) {
           // read 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 moment
}



Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > serial read


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums