-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.c
More file actions
48 lines (42 loc) · 880 Bytes
/
controller.c
File metadata and controls
48 lines (42 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
This is the mapping of Voxels to ports on the AVR
________________________________________________________
PORTD = | DOWN | X | X | LEFT | FALL | RIGHT | UP | RISE
7 6 5 4 3 2 1 0
*/
#include "controller.h"
#include <avr/io.h>
#define RISE 0
#define UP 1
#define RIGHT 2
#define FALL 3
#define LEFT 4
#define DOWN 7
void init_controller(void){
//set pins as inputs
DDRD = 0b00000000;
//activate pull-up resistors on pins
// that we are using.
PORTD = 0b10011111;
}
int read_bit(int bit_num){
return !((PIND >> bit_num) & 0b1);
}
int up_pressed(void){
return read_bit(UP);
}
int down_pressed(void){
return read_bit(DOWN);
}
int left_pressed(void){
return read_bit(LEFT);
}
int right_pressed(void){
return read_bit(RIGHT);
}
int rise_pressed(void){
return read_bit(RISE);
}
int fall_pressed(void){
return read_bit(FALL);
}