# Help in Scrolling LEDs

Hello, I wonder how to do this in arduino:

1. I have 8 leds.
2. I have to shift per 1 bit.
in Zilog Microcontroller, I do this:
``````int dataShift = 0x80 //Start from the value leftmost bit
for_loop... from 1 to 8
if(dataShift==0x00) dataShit = 0x80; //reset if data becomes 0
PAOUT = dataShift;
dataShift=dataShift>>1; //shift 1 bit at a time
``````

The codes above is only for shifting one bit at a time.
But here comes my problem:

I have to shift one bit at a time, but when it comes to the right most bit, the display will be still. Ughh, I can't describe it well. But I have a picture below. loop = 1000 0000 up to 0000 0001
loop = 1000 0001 up to 0000 0011
loop = 1000 0011 up to 0000 0111

until 1's occupy the whole octet. Please help. This might do it:

``````for (x=0; x<0x80; x=x<<1){
x=x | 0x01; // 00000001, 00000011, 00000111, 00001111 ...
datashift = 0x80 | x; // 10000001, 10000011, 10000111, 10001111 ...
}
``````

Hello sir, what I am trying to do is this:

here is my code (in Zilog):

``````#include <ez8.h>

void delay(void){
int x,y;
for(x=0;x<=500;x++)
for(y=0;y<=512;y++);
}

void main(){
int x=0;
int dataShift = 0x80;

PAAF = 0x00;
PAOC = 0x00;
PAHDE = 0xFF;

while(1){

/*LOOP1*/
PAOUT = ~0x80;	delay();
PAOUT = ~0x40;	delay();
PAOUT = ~0x20;	delay();
PAOUT = ~0x10;	delay();
PAOUT = ~0x08;	delay();
PAOUT = ~0x04;	delay();
PAOUT = ~0x02;	delay();
PAOUT = ~0x01;	delay();
/*end of loop1*/

/*LOOP2*/
PAOUT = ~0x81;	delay();
PAOUT = ~0x41;	delay();
PAOUT = ~0x21;	delay();
PAOUT = ~0x11;	delay();
PAOUT = ~0x09;	delay();
PAOUT = ~0x05;	delay();
PAOUT = ~0x03;	delay();
/*end of loop2*/

/*LOOP3*/
PAOUT = ~0x83;	delay();
PAOUT = ~0x43;	delay();
PAOUT = ~0x23;	delay();
PAOUT = ~0x13;	delay();
PAOUT = ~0x0B;	delay();
PAOUT = ~0x07;	delay();
/*end of loop3*/

/*LOOP4*/
PAOUT = ~0x87;	delay();
PAOUT = ~0x47;	delay();
PAOUT = ~0x27;	delay();
PAOUT = ~0x17;	delay();
PAOUT = ~0x0f;	delay();
/*end of loop4*/

/*LOOP5*/
PAOUT = ~0x8f;	delay();
PAOUT = ~0x4f;	delay();
PAOUT = ~0x2f;	delay();
PAOUT = ~0x1f;	delay();
/*end of loop5*/

/*LOOP6*/
PAOUT = ~0x9f;	delay();
PAOUT = ~0x5f;	delay();
PAOUT = ~0x3f;	delay();
/*end of loop6*/

/*LOOP7*/
PAOUT = ~0xbf;	delay();
PAOUT = ~0x7f;	delay();
/*end of loop7*/

/*LOOP8*/
PAOUT = ~0xff;	delay();
/*end of loop8*/

}

}
``````

It’s not tested with LED’s and it is not elegant but something like this…

``````const byte ledPins[] = {2,3,4,5,6,7,8,9};   // List of pins the LED's are connected to

void setup(){
Serial.begin(115200);
Serial.println("Begin");
for (byte x = 0; x < sizeof(ledPins); x++){
pinMode(ledPins[x],OUTPUT);
digitalWrite(ledPins[x],LOW);
}
}

void loop() {
byte x,y;
for (x = 0; x < sizeof(ledPins); x++){
for (y = sizeof(ledPins); y > x; y--){
digitalWrite(ledPins[y-1],HIGH);
delay(100);
digitalWrite(ledPins[y-1],LOW);
Serial.print(ledPins[y-1]);
Serial.print(" ");
}
digitalWrite(ledPins[y],HIGH);
Serial.print(ledPins[y]);
Serial.println();
}
Serial.println("End");
while (1){};
}
``````

The problem with trying to convert the Z80 code is the UNO only has one 8 bit port but it includes pin 0 & 1 so if you want to use serial then this rules out direct port manipulation of D