/*Displays the chosen board*/ void displayBoard(Cell board[BOARD_HEIGHT][BOARD_WIDTH], Player * player) { int x,y; printf("| |0|1|2|3|4|5|6|7|8|9|\n"); for (x=0; x < BOARD_WIDTH; x++){ printf("|%i|", x); for (y=0; y < BOARD_HEIGHT; y++){ if (board[x][y] == EMPTY){ printf("%s|", EMPTY_OUTPUT); } if (board[x][y] == BLOCKED){ printf("%s|", BLOCKED_OUTPUT); } if (board[x][y] == PLAYER){ displayDirection(player->direction); } } printf("\n"); } printf("\n"); }
void lightDisplay(void) { int i; clearStates(); displaySpeed(); displayDirection(); _delay_ms(1000); for (i = 0; i < 8; i++) { dir[i] = ON; if (i < 6) { spd[i] = ON; if (i < 4) { ctrl[i] = ON; } } displaySpeed(); displayDirection(); _delay_ms(1000); } }
int main(void) { //setup USART recive UCSR0B = (1<<RXEN0); UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); UBRR0 = 25; // 25 = 2400 baud; 6 = 9600 baud /* Set pins as output, high->output, low->input */ DDRA = 0xFF; /* Pin for LED out */ DDRB = 0xFF; /* Pin for LED out */ DDRC = 0xFF; /* Pin for LED out */ DDRD = 0xFE; /* Pin for LED out */ unsigned char input; unsigned char value; unsigned char control; PORTA = 0xFF; PORTB = 0xFF; PORTC = 0xFF; PORTD = 0xFF; _delay_ms(1000); /* while (1){ clearStates(); lightDisplay(); }*/ /* int i = 0; unsigned int states[4] = {0x27, 0xA0, 0x56, 0xD4}; */ /* while (1) { unsigned char in = USART_Receive(); for (int i = 0; i < 8; i++) { dir[i] = (in>>(7-i))&0x1; } displayDirection(); } */ while(1) { //clearStates(); input = USART_Receive(); //input = 0x27; /* _delay_ms(2000); input = states[i]; i++; i = i%4;*/ control = input & CTRL_MSK; if (input & CMD_BIT) { ctrl[LONG_SIP] = control == LONG_SIP ? ON : OFF; ctrl[LONG_PUFF] = control == LONG_PUFF ? ON : OFF; ctrl[SIP] = control == SIP || ctrl[LONG_SIP] ? ON : OFF; ctrl[PUFF] = control == PUFF || ctrl[LONG_PUFF] ? ON : OFF; } else { clearCtrl(); } value = (input&VAL_MSK) >> 3; if (input & SPD_BIT) { //SPEED clearSpeed(); if (input & NEG_BIT) { //REVERSE spd[0] = ON; } else { //FORWARD switch (value) { default: case 4: spd[4+SPD_OFFSET] = ON; case 3: spd[3+SPD_OFFSET] = ON; case 2: spd[2+SPD_OFFSET] = ON; case 1: spd[1+SPD_OFFSET] = ON; break; case 0: spd[0+SPD_OFFSET] = ON; break; } } displaySpeed(); } else { //DIRECTION clearDir(); if (input & NEG_BIT) { //LEFT switch (value) { default: case 4: dir[DIR_OFFSET+1-4] = ON; case 3: dir[DIR_OFFSET+1-3] = ON; case 2: dir[DIR_OFFSET+1-2] = ON; case 1: dir[DIR_OFFSET+1-1] = ON; break; case 0: break; } } else { //RIGHT switch (value) { default: case 4: dir[4+DIR_OFFSET] = ON; case 3: dir[3+DIR_OFFSET] = ON; case 2: dir[2+DIR_OFFSET] = ON; case 1: dir[1+DIR_OFFSET] = ON; break; case 0: break; } } displayDirection(); } } return 0; }