-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.c
More file actions
58 lines (47 loc) · 1.09 KB
/
sensor.c
File metadata and controls
58 lines (47 loc) · 1.09 KB
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
49
50
51
52
53
54
55
56
57
58
/********************************************
*
* Name: Sai Praneetha Mutyala
* Section: 2 (2.30-3.50)
* Assignment: Project
*
********************************************/
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include "speedtrap.h"
#include "sensor.h"
unsigned char bit, c, d;
/* Make the sensors work */
void init_sensor(){
//DDRD |= (1<<2)|(1<<3);
PORTD |= (1<<PD2)|(1<<PD3); //pull up button
PCICR |= (1 << PCIE2); //enable interrupts on PORTD(buttons)
PCMSK2 |= (1 << PCINT18) | (1 << PCINT19); //enable interrupt bit PD2 and PD3
bit = PIND;
c = bit & (1<<PD2);
d = bit & (1<<PD3);
}
ISR(PCINT2_vect){
bit = PIND;
c = bit & (1<<PD2);
d = bit & (1<<PD3);
if(c!=0){ //if first object was detected
msec +=1;
}
if (c!=0 && d==0){
msec+=1;
}
if(c!=0 && d!=0){
msec=0;;
}
if (c==0 && d!=0){
msec+=1;
}
if (c==0 && d==0){
msec+=1;
}
if(d!=0){ //if second object was detected
msec = msec;
}
}