Guest User

Untitled

a guest
Apr 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.41 KB | None | 0 0
  1. /****************************************"
  2. IM-Press Technologies - By Paul D'Intino
  3. (C)Copyright 2011
  4. Sensor Array Test ver 2.0
  5.  
  6. With HEAPS of help from Taha Bintahir =)
  7.  
  8. ****************************************/
  9.  
  10. import processing.serial.*;
  11. Serial myPort;
  12.  
  13. PFont font; // The display font:
  14. String inString; // Input string from serial port:
  15.  
  16. // int[] SerialInArray = {0,0,0,0,0,0,0,0}; //clear the output
  17.  
  18. int Width = 600;
  19. int Height = 600;
  20.  
  21. String Buff = null; // Data in Buffer
  22.  
  23. byte[][] serialInArray = new byte[4][8]; // Where we'll put what we receive
  24. int serialCount = 0; // A count of how many bytes we receive
  25. boolean firstContact = false; // Whether we've heard from the microcontroller
  26.  
  27. int limitvalue = 1;
  28. int strokewidth = 1;
  29.  
  30. //Initialise Sensor Width/Height
  31. int SensorWidth = 20;
  32. int SensorHeight = 20;
  33.  
  34. void setup () {
  35. size(Width, Height);
  36.  
  37. println(Serial.list());
  38. myPort = new Serial(this, Serial.list()[1], 115200);
  39. //myPort.bufferUntil('\n');
  40. println("****************************************");
  41. println("IM-Press Technologies - By Paul D'Intino");
  42. println("(C)Copyright 2011");
  43. println("Sensor Array Test ver 1.0");
  44. println("****************************************");
  45. //println("");
  46. println("DEBUG SCREEN");
  47. println("============");
  48. //println("Number of Sensors = " + NumberOfSensors);
  49. println("Initializing Sensors...");
  50. println("Font Selected: " + PFont.list()[431]);
  51. //background (255);
  52. frameRate(45); //max 40-45fps before flickering occurs
  53. //smooth(); //looks better but slows down performance
  54.  
  55. }
  56.  
  57.  
  58. void draw () {
  59. background (0);
  60. clearArray();
  61. serialInArray = readByte();
  62. font = createFont(PFont.list()[431],12);
  63. //fill(70,255,70); //Matrix Green
  64. fill(200,70,70);
  65. textFont(font);
  66. text("IM-Press Technologies", 30,40);
  67. text("By Paul D'Intino", 30,60);
  68. text("(C)Copyright 2011", 30,80);
  69. text("Sensor Array Test ver 2.0", 390,40);
  70. text("Received: " + serialInArray[0] + ","
  71. + serialInArray[1] + ","
  72. + serialInArray[2] + ","
  73. + serialInArray[3] + ","
  74. + serialInArray[4] + ","
  75. + serialInArray[5] + ","
  76. + serialInArray[6] + ","
  77. + serialInArray[7] + ",", 30,570);// 30,570);
  78.  
  79. updateWindow();
  80.  
  81. //Draw the border modules
  82. /*-----------------------*/
  83.  
  84. //noStroke();
  85. stroke(0);
  86. strokeWeight(1);
  87. //fill(152,251,152); //Pale Green
  88. //fill(135,206,250); //Light Sky Blue
  89. //fill(0,191,255); //Deep Sky Blue
  90. fill(0,255,127); //Spring Green
  91. //rect(x,y,width,height);
  92. rect(20,0,560,20); //Top
  93. rect(0,20,20,560); //Left
  94. rect(20,580,560,20); //Bottom
  95. rect(580,20,20,560); //Right
  96.  
  97. //Draw IR LED's
  98. /*-------------*/
  99.  
  100. //IR LED Top
  101. fill(200); //Spring Green
  102. rect(width/2-10,0,SensorWidth,SensorHeight);
  103.  
  104. //IR LED Top Left
  105. fill(80); //Spring Green
  106. rect(width/2-width/4-10,0,SensorWidth,SensorHeight);
  107.  
  108. //IR LED Top Right
  109. fill(80); //Spring Green
  110. rect(width/2+width/4-10,0,SensorWidth,SensorHeight);
  111.  
  112. //IR LED Right
  113. fill(200); //Spring Green
  114. rect(width-20,height/2-10,SensorWidth,SensorHeight);
  115.  
  116. //IR LED Right Top
  117. fill(80); //Spring Green
  118. rect(width-20,height/2-height/4-10,SensorWidth,SensorHeight);
  119.  
  120. //IR LED Right Bottom
  121. fill(80); //Spring Green
  122. rect(width-20,height/2+height/4-10,SensorWidth,SensorHeight);
  123.  
  124. //IR LED Bottom
  125. fill(200); //Spring Green
  126. rect(width/2-10,height-20,SensorWidth,SensorHeight);
  127.  
  128. //IR LED Bottom Left
  129. fill(80); //Spring Green
  130. rect(width/2-width/4-10,height-20,SensorWidth,SensorHeight);
  131.  
  132. //IR LED Bottom right
  133. fill(80); //Spring Green
  134. rect(width/2+width/4-10,height-20,SensorWidth,SensorHeight);
  135.  
  136. //IR LED Left
  137. fill(200); //Spring Green
  138. rect(0,height/2-10,SensorWidth,SensorHeight);
  139.  
  140. //IR LED Left Top
  141. fill(80); //Spring Green
  142. rect(0,height/2-height/4-10,SensorWidth,SensorHeight);
  143.  
  144. //IR LED Left Bottom
  145. fill(80); //Spring Green
  146. rect(0,height/2+height/4-10,SensorWidth,SensorHeight);
  147.  
  148.  
  149.  
  150.  
  151. }
  152. void clearArray()
  153. {
  154. for(int h = 0; h < 4; h++){
  155. for(int i = 0; i < 8; i++){
  156. serialInArray[h][i] = 100;
  157. }
  158. }
  159. }
  160.  
  161. byte [][] readByte()
  162. {
  163.  
  164. byte[] tempData = new byte[8];
  165. byte[][] tempFrame = new byte [4][8];
  166. int noBytesRead = 0;
  167. int count = 0
  168.  
  169. while(myPort.available() > 0){
  170.  
  171. if(firstContact == false){
  172. int inByte = myPort.read();
  173. if(inByte == 'A'){
  174. myPort.clear();
  175. myPort.write('A');
  176. firstContact = true;
  177. noBytesRead = myPort.readBytes(tempData);
  178. }
  179. }
  180. else{
  181. myPort.write('A');
  182. noBytesRead = myPort.readBytes(tempData);
  183. }
  184.  
  185. for(int i = 0; i < 7; i++){
  186. tempFrame[count][i] = tempData[i];
  187. }
  188. count++;
  189. if(count > 4){
  190. break;
  191. }
  192. }
  193.  
  194. // return tempData;
  195. }
  196.  
  197. void updateWindow(){
  198.  
  199. /*
  200. //Print Array for test purposes
  201. print(serialInArray[0]);
  202. print(serialInArray[1]);
  203. print(serialInArray[2]);
  204. print(serialInArray[3]);
  205. print(serialInArray[4]);
  206. print(serialInArray[5]);
  207. print(serialInArray[6]);
  208. println(serialInArray[7]);
  209. */
  210.  
  211. int xPos = 67; //originally 50
  212. int yPos = 67; //originally 50
  213.  
  214. //Top Sensors - Bottom IR LED
  215. for(int i = 0; i < 8; i++){
  216. int movingXPos = xPos*(i+1);
  217. int movingYPos = yPos*(i+1);
  218. if(serialInArray[i] >=limitvalue){
  219. }
  220. else{
  221. stroke(255);
  222. //stroke(255,255,0); // YELLOW
  223. strokeWeight(strokewidth);
  224. //line (x1,y1,newX, height of sketch- number)
  225. //line(width/2, height, movingXPos, 0); //original
  226. line(width/2, height, movingXPos, 0); // TOP
  227. line(width/2, height, 0, movingYPos); // LEFT
  228. line(width/2, height, height, movingYPos); //RIGHT
  229. }
  230. }
  231.  
  232. //Top Sensors - Bottom Left IR LED
  233. for(int i = 0; i < 8; i++){
  234. int movingXPos = xPos*(i+1);
  235. int movingYPos = yPos*(i+1);
  236. if(serialInArray[i] >=limitvalue){
  237. }
  238. else{
  239. stroke(255);
  240. //stroke(255,255,0); // YELLOW
  241. strokeWeight(strokewidth);
  242. //line (x1,y1,newX, height of sketch- number)
  243. //line(width/2, height, movingXPos, 0); //original
  244. line(width/2-width/4, height, movingXPos, 0); // TOP
  245. line(width/2-width/4, height, 0, movingYPos); // LEFT
  246. line(width/2-width/4, height, height, movingYPos); //RIGHT
  247. }
  248. }
  249.  
  250. //Top Sensors - Bottom Right IR LED
  251. for(int i = 0; i < 8; i++){
  252. int movingXPos = xPos*(i+1);
  253. int movingYPos = yPos*(i+1);
  254. if(serialInArray[i] >=limitvalue){
  255. }
  256. else{
  257. stroke(255);
  258. //stroke(255,255,0); // YELLOW
  259. strokeWeight(strokewidth);
  260. //line (x1,y1,newX, height of sketch- number)
  261. //line(width/2, height, movingXPos, 0); //original
  262. line(width/2+width/4, height, movingXPos, 0); // TOP
  263. line(width/2+width/4, height, 0, movingYPos); // LEFT
  264. line(width/2+width/4, height, height, movingYPos); //RIGHT
  265. }
  266. }
  267.  
  268. //Bottom Sensors - Top IR LED
  269. for(int i = 0; i < 8; i++){
  270. int movingXPos = xPos*(i+1);
  271. int movingYPos = yPos*(i+1);
  272. if(serialInArray[i] >=limitvalue){
  273. }
  274. else{
  275. stroke(255);
  276. //stroke(255,0,0); // RED
  277. strokeWeight(strokewidth);
  278. //line (x1,y1,newX, height of sketch- number)
  279. //line(width/2, 0, movingXPos, height); //original
  280. line(width/2, 0, movingXPos, height); // BOTTOM
  281. line(width/2, 0, 0, movingYPos); // LEFT
  282. line(width/2, 0, height, movingYPos); //RIGHT
  283. }
  284. }
  285.  
  286. //Bottom Sensors - Top Left IR LED
  287. for(int i = 0; i < 8; i++){
  288. int movingXPos = xPos*(i+1);
  289. int movingYPos = yPos*(i+1);
  290. if(serialInArray[i] >=limitvalue){
  291. }
  292. else{
  293. stroke(255);
  294. //stroke(255,0,0); // RED
  295. strokeWeight(strokewidth);
  296. //line (x1,y1,newX, height of sketch- number)
  297. //line(width/2, 0, movingXPos, height); //original
  298. line(width/2-width/4, 0, movingXPos, height); // BOTTOM
  299. line(width/2-width/4, 0, 0, movingYPos); // LEFT
  300. line(width/2-width/4, 0, height, movingYPos); //RIGHT
  301. }
  302. }
  303.  
  304. //Bottom Sensors - Top Right IR LED
  305. for(int i = 0; i < 8; i++){
  306. int movingXPos = xPos*(i+1);
  307. int movingYPos = yPos*(i+1);
  308. if(serialInArray[i] >=limitvalue){
  309. }
  310. else{
  311. stroke(255);
  312. //stroke(255,0,0); // RED
  313. strokeWeight(strokewidth);
  314. //line (x1,y1,newX, height of sketch- number)
  315. //line(width/2, 0, movingXPos, height); //original
  316. line(width/2+width/4, 0, movingXPos, height); // BOTTOM
  317. line(width/2+width/4, 0, 0, movingYPos); // LEFT
  318. line(width/2+width/4, 0, height, movingYPos); //RIGHT
  319. }
  320. }
  321.  
  322. //Right Sensors - Left IR LED
  323. for(int i = 0; i < 8; i++){
  324. int movingXPos = xPos*(i+1);
  325. int movingYPos = yPos*(i+1);
  326. if(serialInArray[i] >=limitvalue){
  327. }
  328. else{
  329. stroke(255);
  330. //stroke(0,0,255); // BLUE
  331. strokeWeight(strokewidth);
  332. //line (x1,y1,newX, height of sketch- number)
  333. //line(0, height/2, height, movingYPos); //original
  334. line(0, height/2, height, movingYPos); // RIGHT
  335. line(0, height/2, movingXPos, height); // BOTTOM
  336. line(0, height/2, movingXPos, 0); // TOP
  337. }
  338. }
  339.  
  340. //Right Sensors - Left Top IR LED
  341. for(int i = 0; i < 8; i++){
  342. int movingXPos = xPos*(i+1);
  343. int movingYPos = yPos*(i+1);
  344. if(serialInArray[i] >=limitvalue){
  345. }
  346. else{
  347. stroke(255);
  348. //stroke(0,0,255); // BLUE
  349. strokeWeight(strokewidth);
  350. //line (x1,y1,newX, height of sketch- number)
  351. //line(0, height/2, height, movingYPos); //original
  352. line(0, height/2-height/4, height, movingYPos); // RIGHT
  353. line(0, height/2-height/4, movingXPos, height); // BOTTOM
  354. line(0, height/2-height/4, movingXPos, 0); // TOP
  355. }
  356. }
  357.  
  358. //Right Sensors - Left Bottom IR LED
  359. for(int i = 0; i < 8; i++){
  360. int movingXPos = xPos*(i+1);
  361. int movingYPos = yPos*(i+1);
  362. if(serialInArray[i] >=limitvalue){
  363. }
  364. else{
  365. stroke(255);
  366. //stroke(0,0,255); // BLUE
  367. strokeWeight(strokewidth);
  368. //line (x1,y1,newX, height of sketch- number)
  369. //line(0, height/2, height, movingYPos); //original
  370. line(0, height/2+height/4, height, movingYPos); // RIGHT
  371. line(0, height/2+height/4, movingXPos, height); // BOTTOM
  372. line(0, height/2+height/4, movingXPos, 0); // TOP
  373. }
  374. }
  375.  
  376.  
  377. //Left Sensors - Right IR LED
  378. for(int i = 0; i < 8; i++){
  379. int movingXPos = xPos*(i+1);
  380. int movingYPos = yPos*(i+1);
  381. if(serialInArray[i] >=limitvalue){
  382. }
  383. else{
  384. stroke(255);
  385. //stroke(0,255,0); // GREEN
  386. strokeWeight(strokewidth);
  387. //line (x1,y1,newX, height of sketch- number)
  388. //line(width, height/2, 0, movingYPos); //original
  389. line(width, height/2, 0, movingYPos); // LEFT
  390. line(width, height/2, movingXPos, height); // BOTTOM
  391. line(width, height/2, movingXPos, 0); // TOP
  392. }
  393. }
  394.  
  395. //Left Sensors - Right Top IR LED
  396. for(int i = 0; i < 8; i++){
  397. int movingXPos = xPos*(i+1);
  398. int movingYPos = yPos*(i+1);
  399. if(serialInArray[i] >=limitvalue){
  400. }
  401. else{
  402. stroke(255);
  403. //stroke(0,255,0); // GREEN
  404. strokeWeight(strokewidth);
  405. //line (x1,y1,newX, height of sketch- number)
  406. //line(width, height/2, 0, movingYPos); //original
  407. line(width, height/2-height/4, 0, movingYPos); // LEFT
  408. line(width, height/2-height/4, movingXPos, height); // BOTTOM
  409. line(width, height/2-height/4, movingXPos, 0); // TOP
  410. }
  411. }
  412.  
  413. //Left Sensors - Right Bottom IR LED
  414. for(int i = 0; i < 8; i++){
  415. int movingXPos = xPos*(i+1);
  416. int movingYPos = yPos*(i+1);
  417. if(serialInArray[i] >=limitvalue){
  418. }
  419. else{
  420. stroke(255);
  421. //stroke(0,255,0); // GREEN
  422. strokeWeight(strokewidth);
  423. //line (x1,y1,newX, height of sketch- number)
  424. //line(width, height/2, 0, movingYPos); //original
  425. line(width, height/2+height/4, 0, movingYPos); // LEFT
  426. line(width, height/2+height/4, movingXPos, height); // BOTTOM
  427. line(width, height/2+height/4, movingXPos, 0); // TOP
  428. }
  429. }
  430. }
Add Comment
Please, Sign In to add comment