Guest User

Untitled

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