-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_code.c
66 lines (56 loc) · 1.33 KB
/
bot_code.c
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
59
60
61
62
63
64
65
66
/*
* gesture_control_bot.c
*
* Created: 12-08-2017 14:14:50
* Author : Dhruv Srivastava
*/
#define F_CPU 14745600 // Crystal Frequency
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
unsigned char signal; // To store received data at UDR0 from server
void init(){
cli(); // For clearing the global interrupts
DDRA = DDRA | 0x0F;
PORTA = PORTA & 0xF0; // Motion pin refreshed
DDRL = DDRL | 0x18;
PORTL = PORTL | 0x18; // Allow PWM control
DDRC = DDRC | 0x08;
PORTC = PORTC & 0xF7; // Buzzer refreshed
UCSR0B = 0x00; // UART0 init
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x5F;
UBRR0H = 0x00;
UCSR0B = 0x98;
sei(); // For enabling the global interrupts
}
void beep(void){
PORTC = PINC | 0x08; // Beep ON
_delay_ms(100);
PORTC = PINC & 0xF7; // Beep OFF
}
SIGNAL(USART0_RX_vect){ // Reading interrupt signal values
signal = UDR0;
UDR0 = signal; // Acknowledging the received signal to server
beep();
if(signal == 'w'){
PORTA = 0x06; // Forward
}
if(signal == 's'){
PORTA = 0x09; // Reverse
}
if(signal == 'a'){
PORTA = 0x05; // Left
}
if(signal == 'd'){
PORTA = 0x0A; // Right
}
if(signal == 'x'){
PORTA = 0x00; // Stop
}
}
int main(void){
init();
while (1);
}