-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaula 3
119 lines (102 loc) · 2 KB
/
aula 3
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <string.h>
COORD coord ={0 , 0};
void gotoxy (int x, int y);
void ini();
struct sensor leitura();
struct motor ia();
void movemotor();
struct sensor{
int s1;
int s2;
};
struct sensor S;
struct motor {
int m1;
int m2;
};
struct motor M ;
/* MAIN */
/*------------------------------------------------------------------------------------*/
int main()
{
int s1,s2,m1,m2;
ini();
while(1){
leitura(S);
ia(M);
movemotor();
sleep(1/2);
}
return 0;
}
/* outras funções */
void gotoxy (int x, int y)
{
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
void ini(){
printf("COMANDOS : sensor esquerdo = 1 / sensor direito= 2 / os dois sensores = 3 / \n nenhum sensor = 4");
}
void movemotor(){
if(M.m1==1){
gotoxy(0,6);
printf("move motor 1\r");
}
else{
gotoxy(0,6);
printf("para motor 1\r");
}
if (M.m2==1){
gotoxy(0,8);
printf("move motor 2\r");
}
else{
gotoxy(0,8);
printf("para motor 2\r");
}
}
struct motor ia(){
if (S.s1==0 && S.s2==0){
M.m1=1;
M.m2=1;
}
else if(S.s1==1 && S.s2==0){
M.m1=1;
M.m2=0;
}
else if(S.s1==0 && S.s2 ==1){
M.m1=0;
M.m2=1;
}
else if (S.s1==1 && S.s2 ==1){
M.m1=1;
M.m2=0;
}
return M;
}
struct sensor leitura(){
int asc;
if (kbhit()){
asc= getch();
if (asc=='1'){
S.s1=1;
S.s2=0;
}
else if (asc == '2'){
S.s1=0;
S.s2=1;
}
else if(asc == '3'){
S.s1=S.s2=1;
}
else if(asc == '4'){
S.s1=S.s2=0;
}
}
return S;
}