Hello!
I am trying to move my code which i made in thinkercad to recreate it in arduino, however i have reached some problems. These are some of the errors "warning: narrowing conversion of '128' from 'int' to 'char' inside { } [-Wnarrowing]
char BinaryD[] = {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0};"
All the other errors are about the same narrowing conversion warning.
My code is shown below and the tinkercad link is this
The first 2 patters work fine on my arduino but the 3rd and the 4th are completely messed up.
Any help? Thanks in advance
static volatile int cnt = 1;
int speed;
int num = 0;
ISR(INT0_vect)
{
cnt ++;
if (cnt == 5)
cnt = 1;
}
void setup() {
Serial.begin(9600);
DDRD = 0xf0;
DDRB = 0x0f;
PIND = 0x04;
EICRA = 0x03;
EIMSK = 0x01;
DDRC = 0x00;
}
void loop(){
if (cnt == 1)
Bounce();
if (cnt == 2)
Music();
if (cnt == 3)
Complicated();
if (cnt == 4)
{
PORTB = 0x00;
PORTD = 0x00;
Binary();
}
}
void Bounce()
{
char Pat_BounceD[] = {0x00,0x10,0x30,0x60,0xC0,0x80,0xC0,0x60,0x30,0x10,0x00};
char Pat_BounceB[] = {0x00,0x08,0x0C,0x06,0x03,0x01,0x03,0x06,0x0C,0x08,0x00};
for(int i=0; i<=10 ; i++)
{
PORTD = Pat_BounceD[i];
PORTB = Pat_BounceB[i];
delay(100);
if (cnt != 1)
break;
}
}
void Music()
{
char Pat_MusicD[] = {0x00,0x10,0x30,0x70,0xf0,0xf0,0xf0,0xf0,0xf0};
char Pat_MusicB[] = {0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0f};
for(int i=0; i<=8 ; i++)
{
PORTD = Pat_MusicD[i];
PORTB = Pat_MusicB[i];
delay(100);
if (cnt != 2)
break;
}
for(int j=8; j>=0 ; j--)
{
PORTD = Pat_MusicD[j];
PORTB = Pat_MusicB[j];
delay(100);
if (cnt != 2)
break;
}
}
void Complicated()
{
char Pat_CountEOB[] = {0x08,0x04,0x02,0x01,0x00};
char Pat_CountEOD[] = {0x80,0x40,0x20,0x10};
char Pat_CountNTD[] = {0x90,0x50,0x30};
char Pat_CountBSD[] = {0xb0,0x70};
char Pat_countLB[] = {0x09,0x05,0x03,0x0b,0x07,0x0f};
char x, y, e, n, b;
char Pat_ComplicatedB[] = {0x00,x,x,x,x,x,y};
char Pat_ComplicatedD[] = {0x00,e,n,b,0xf0,0xf0,0xf0};
for(int i=0; i<=6 ; i++)
{
if (Pat_ComplicatedB[i] == x)
{
for (int k=0; k<=4 ; k++)
{
PORTB = Pat_CountEOB[k];
delay(100);
if (cnt != 3)
break;
}
}
if(Pat_ComplicatedB[i] == y)
{
for (int k=0; k<=6 ; k++)
{
PORTB = Pat_countLB[k];
delay(100);
if (cnt != 3)
break;
}
}
if ((Pat_ComplicatedB[i] != x) && Pat_ComplicatedB[i] != y)
PORTB = Pat_ComplicatedB[i];
//Done with portb
if(i == 1)
{
for (int k=0; k<=3 ; k++)
{
PORTD = Pat_CountEOD[k];
delay(100);
if (cnt != 3)
break;
}
}
else if(i == 2)
{
for (int k=0; k<=2 ; k++)
{
PORTD = Pat_CountNTD[k];
delay(100);
if (cnt != 3)
break;
}
}
else if(i == 3)
{
for (int k=0; k<=1 ; k++)
{
PORTD = Pat_CountBSD[k];
delay(100);
if (cnt != 3)
break;
}
}
else
PORTD = Pat_ComplicatedD[i];
if (cnt != 3)
break;
}
}
void Binary()
{
char BinaryB[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f};
char BinaryD[] = {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0};
char x;
char Pat_BinaryD[] = {0x00,x,x,x,x,x,x,x,x,x,x,x,x,x,x};
char Pat_BinaryB[] = {0x00,x,x,x,x,x,x,x,x,x,x,x,x,x,x};
for (int i=0; i<=15 ; i++)
{
for (int k=0; k<=15 ; k++)
{
PORTD = BinaryD[k];
delay(speed);
if (cnt != 4)
break;
}
PORTB = BinaryB[i];
delay(speed);
if (cnt != 4)
break;
}
}