I can't seem to find out why this isn't working. I'm trying to implement something into a program of mine, and using variables does not work. If I put the value of the variable in, it'll work. Well, here's the code.
What I tried to use was an array to take place of the values in my code, however it just didn't work. I guessed that it had something to do with double and int, so I tried to make the first array "a" a double, and the second array "b" was int, then covert the double to the int, but that still didn't work.
This WORKS:
for(ct=1;ct<2000;ct++)
{
if (ct<=255)
{
if (ct == 1)
DDRD|=(1<<PORTD0); //LED1 On
OCR1A++; //LED1 brightness up
}
else if ((ct>255) && (ct<=510))
{
if (ct == 510)
DDRD&=~0x01; //LED1 Off
OCR1A--; //LED1 brightness down
}
}
This does NOT work:
unsigned int ct=1,i,a[17],max,interval;
double num;
max = 1360;
num = 16/3;
interval = max/num;
for(i=0;i<17;i++)
{
a[i]=(i/3)*interval;
}
for(ct=1;ct<2000;ct++)
{
if (ct<=a[3])
{
if (ct == a[0]+1)
DDRD|=(1<<PORTD0); //LED1 On
OCR1A++; //LED1 brightness up
}
else if ((ct>a[3]) && (ct<=a[6]))
{
if (ct == a[6])
DDRD&=~0x01; //LED1 Off
OCR1A--; //LED1 brightness down
}
}
I even tried this:
unsigned int ct=1,i,b[17];
double num,max,interval,a[17];
max = 1360;
num = 16/3;
interval = max/num;
for(i=0;i<17;i++)
{
a[i]=(i/3)*interval;
b[i]=(int)a[i];
}
for(ct=1;ct<2000;ct++)
{
if (ct<=b[3])
{
if (ct == b[0]+1)
DDRD|=(1<<PORTD0); //LED1 On
OCR1A++; //LED1 brightness up
}
else if ((ct>b[3]) && (ct<=b[6]))
{
if (ct == b[6])
DDRD&=~0x01; //LED1 Off
OCR1A--; //LED1 brightness down
}
}
What's going on?