-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
99 lines (73 loc) · 1.46 KB
/
main.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "lib/usart/usart.h"
#include "motor.h"
#define MY_ID 1
USART32(uart);
void pwm_init(){
TCCR1A |= (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10);
TCCR1B |= (1 << CS11) | (1 << CS10);
}
void wait(){
while (uart.empty());
}
int size(unsigned char primitive){
switch (primitive){
case 4: return 2;
}
}
int main()
{
unsigned char adress;
unsigned char primitive;
unsigned char trash;
pwm_init();
motor_init();
sei();
//m2_start();
//m1_start();
uart << "**** BSRM01 v.0.00001 ready. ****\r\n";
while(1){
//wait();
//uart >> adress;
//adress-=48;
//if (adress == MY_ID){
wait();
uart >> primitive;
switch (primitive){
case 'S':
m1_stop();
m2_stop();
uart << "BSRM01: M1, M2 STOP!";
case 'E':
unsigned char eng;
unsigned char power;
wait();
uart >> eng;
wait();
uart >> power;
if (eng == 0){
uart <<"E0:" << (int)power <<"%";
m1_set(power);
m1_start();
}
else if (eng == 1){
uart <<"E1:" << (int)power <<"%";
m2_set(power);
m2_start();
}
break;
}
}
// else {
// uart << "Are you talking to me, dude?\r\n";
// wait();
// uart >> primitive;
// for(int i = 0; i < size(primitive); i++){
// wait();
// uart >> trash;
// }
// }
//}
}