Hello everybody,
first of all, I'm quite new to programming in C, so forgive my ignorance.
For an assignment i have to program a microcontroller (Atmega8) using ICCAVR. I'm working on a programme similar to 'simon says' (where 4 led's are illuminated in a random order, and afterwards you have to give in the same combination, using press buttons. If the combination is correct, one extra pulse is added to the combination, and so on...).
Now i'm having a bit of difficulties with reading in the array of the pressed buttons.
This is what this function looks like so far:
void receive_array()
{
int wijzer;
int a;
for(wijzer=0;wijzer<=pointer;wijzer++)
{
switch(PIND)
{
case 0b00000001:
hulparray[wijzer]=1;
PORTB = PORTB | (1 << 0);
playsound1();
break;
case 0b00000010:
hulparray[wijzer]=2;
PORTB = PORTB | (1 << 1);
playsound2();
break;
case 0b00000100:
hulparray[wijzer]=3;
PORTB = PORTB | (1 << 2);
playsound3();
break;
case 0b00001000:
hulparray[wijzer]=4;
PORTB = PORTB | (1 << 3);
playsound4();
break;
default:
PORTB=0b00000000;
}
}
}
The problem is that the programme flies over this function, without even reading in a thing. Therefore it would be handy that the programme stays inside this function, untill there's a descent flank, and then read in this value. This is necessary because otherwise the whole array would consist of the same data.
Does anybody know if this is possible? Or any othes ideas of how it should be done? All help is welcome!
Thank you