Hi, i've been trying to solve this problem for about 2 or 3 days and i can't find a solution. My english isn't that good, but i will try to explain it.
So the problem is as follows: i have to input a number from 1 to 8 with a BCD Thumbswitch, the arduino has to read it and it has to compute this: let's say i set the thumbswitch on 4, it has to display something like this
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
0 0 0 0 0 1 1 1
0 0 0 0 1 1 1 1
0 0 0 1 1 1 1 0
0 0 1 1 1 1 0 0
0 1 1 1 1 0 0 0
1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 1
1 1 0 0 0 0 1 1
0 0 0 0 0 1 1 1
0 0 0 0 1 1 1 1
and it musn't stop, in other words, it has to rotate the bits without losing any of them.
I tried to do like this just for number 2, but then i realized it was wrong,
byte num=0,i;
bool n0,n1,n2,n3;
void setup(){
for(i=6;i<14;i++)
pinMode(i,OUTPUT);
}
bool convierteBit (byte n, byte indice){
n=n>>indice;
bool binario =n%2;
return binario;
}
void displaya (byte digito)
{
for(i=13;i>=6;i--)
{
digitalWrite(i,digito%2);
digito=digito>>1;
}
delay(500);
}
void loop()
{
n0=digitalRead(0);
n1=digitalRead(1);
n2=digitalRead(2);
n3=digitalRead(3);
num=8n0+4n1+2*n2+n3;
if(num==2)
{
byte dato=B00000011;
delay(300);
for(int k=0;k<8;k++)
{displaya(dato);
dato=dato<<1;
delay(300);
}
}
}
This is the circuit