Progetto

Generale

Profilo

File » Processing_Move_PanTilt.pde

Interfaccia processing per pilotare i motori ed i servo PanTilt - Moreno Petrucci, 08-09-2012 16:58

 
1
/**
2
 * Move Control
3
 */
4

    
5
import processing.serial.*;
6
Serial myPort;
7
int up;
8

    
9
void setup() {
10
  size(500, 600);
11
  smooth(); 
12
  background(100);
13
  //noStroke();
14
  
15
  myPort= new Serial(this, "COM5",9600);
16
  
17
}
18

    
19
void draw(){
20

    
21
  // Pulsante UP - SU'
22
  if (overRect(195,5,110,105) && mousePressed) {
23
      stroke(241,250,8);
24
      fill(15,150,150);
25
      
26
      rect(195,5,110,105);
27
      
28
      fill(200,200,200);
29
      triangle(250, 10, 200, 100, 300, 100);
30
      
31
      myPort.write('u');
32
      
33
  }
34
  else {
35
      stroke(55,55,55);
36
      fill(15,150,150);
37
      
38
      rect(195,5,110,105);
39
      fill(255,255,255);
40
      triangle(250, 10, 200, 100, 300, 100);
41
  }
42

    
43
  // Pulsante DOWN - GIU'
44
  if (overRect(195,115,110,105) && mousePressed) {
45
      stroke(241,250,8);
46
      fill(15,150,150);
47
      
48
      rect(195,115,110,105);
49
      
50
      fill(200,200,200);
51
      triangle(250, 210, 200, 120, 300, 120);
52
      
53
      myPort.write('d');
54
      
55
  }
56
  else {
57
      stroke(55,55,55);
58
      fill(15,150,150);
59
      
60
      rect(195,115,110,105);
61
      fill(255,255,255);
62
      triangle(250, 210, 200, 120, 300, 120);
63
  }
64

    
65

    
66
// Pulsante LEFT - SINISTRA 
67
  if (overRect(80,115,110,105) && mousePressed) {
68
      stroke(241,250,8);
69
      fill(15,150,150);
70
      
71
      rect(80,115,110,105);
72
      
73
      fill(200,200,200);
74
      triangle(85, 170, 180, 120, 180, 210);
75
      
76
      myPort.write('l');
77
      
78
  }
79
  else {
80
      stroke(55,55,55);
81
      fill(15,150,150);
82
      
83
      rect(80,115,110,105);
84
      fill(255,255,255);
85
      triangle(85, 170, 180, 120, 180, 210);
86
  }
87

    
88
// Pulsante RIGHT - DESTRA 
89
  if (overRect(310,115,110,105) && mousePressed) {
90
      stroke(241,250,8);
91
      fill(15,150,150);
92
      
93
      rect(310,115,110,105);
94
      
95
      fill(200,200,200);
96
      triangle(410, 170, 320, 120, 320, 210);
97
      
98
      myPort.write('r');
99
      
100
  }
101
  else {
102
      stroke(55,55,55);
103
      fill(15,150,150);
104
      
105
      rect(310,115,110,105);
106
      fill(255,255,255);
107
      triangle(410, 170, 320, 120, 320, 210);
108
  }
109
  
110
  //---------- Controllo Motori -----------------
111
   // Pulsante AVANTI
112
  if (overRect(195,305,110,105) && mousePressed) {
113
      stroke(241,250,8);
114
      fill(150,150,150);
115
      
116
      rect(195,5,110,105);
117
      
118
      fill(200,200,200);
119
      triangle(250, 310, 200, 400, 300, 400);
120
      
121
      myPort.write('a');
122
      
123
  }
124
  else {
125
      stroke(55,55,55);
126
      fill(150,150,150);
127
      
128
      rect(195,305,110,105);
129
      fill(255,255,255);
130
      triangle(250, 310, 200, 400, 300, 400);
131
  }
132

    
133
  // Pulsante INDIETRO
134
  if (overRect(195,415,110,105) && mousePressed) {
135
      stroke(241,250,8);
136
      fill(150,150,150);
137
      
138
      rect(195,415,110,105);
139
      
140
      fill(200,200,200);
141
      triangle(250, 510, 200, 420, 300, 420);
142
      
143
      myPort.write('i');
144
      
145
  }
146
  else {
147
      stroke(55,55,55);
148
      fill(150,150,150);
149
      
150
      rect(195,415,110,105);
151
      fill(255,255,255);
152
      triangle(250, 510, 200, 420, 300, 420);
153
  }
154

    
155

    
156
// Pulsante LEFT - SINISTRA 
157
  if (overRect(80,415,110,105) && mousePressed) {
158
      stroke(241,250,8);
159
      fill(150,150,150);
160
      
161
      rect(80,415,110,105);
162
      
163
      fill(200,200,200);
164
      triangle(85, 470, 180, 420, 180, 510);
165
      
166
      myPort.write('s');
167
      
168
  }
169
  else {
170
      stroke(55,55,55);
171
      fill(150,150,150);
172
      
173
      rect(80,415,110,105);
174
      fill(255,255,255);
175
      triangle(85, 470, 180, 420, 180, 510);
176
  }
177

    
178
// Pulsante RIGHT - DESTRA 
179
  if (overRect(310,415,110,105) && mousePressed) {
180
      stroke(241,250,8);
181
      fill(150,150,150);
182
      
183
      rect(310,415,110,105);
184
      
185
      fill(200,200,200);
186
      triangle(410, 470, 320, 420, 320, 510);
187
      
188
      myPort.write('e');
189
      
190
  }
191
  else {
192
      stroke(55,55,55);
193
      fill(150,150,150);
194
      
195
      rect(310,415,110,105);
196
      fill(255,255,255);
197
      triangle(410, 470, 320, 420, 320, 510);
198
  }
199

    
200
}
201

    
202
boolean overRect(int x, int y, int w, int h) {
203
    if (mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h) {
204
     return true;
205
    }
206
   else {
207
      return false;
208
   } 
209
  
210

    
211
}
212

    
213

    
(2-2/4)