Guest User

Untitled

a guest
Apr 21st, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.36 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 i = 0; i < 8; i++){
  155. serialInArray[i] = 100;
  156.  
  157. }
  158. }
  159.  
  160. byte [][] readByte()
  161. {
  162.  
  163. byte[] tempData = new byte[8];
  164. byte[][] tempFrame = new byte [4][8];
  165. int noBytesRead = 0;
  166. int count = 0
  167.  
  168. while(myPort.available() > 0){
  169.  
  170. if(firstContact == false){
  171. int inByte = myPort.read();
  172. if(inByte == 'A'){
  173. myPort.clear();
  174. myPort.write('A');
  175. firstContact = true;
  176. noBytesRead = myPort.readBytes(tempData);
  177. }
  178. }
  179. else{
  180. myPort.write('A');
  181. noBytesRead = myPort.readBytes(tempData);
  182. }
  183.  
  184. for(int i = 0; i < 7; i++){
  185. tempFrame[count][i] = tempData[i];
  186. }
  187. count++;
  188. if(count > 4){
  189. break;
  190. }
  191. }
  192.  
  193. // return tempData;
  194. }
  195.  
  196. void updateWindow(){
  197.  
  198. /*
  199. //Print Array for test purposes
  200. print(serialInArray[0]);
  201. print(serialInArray[1]);
  202. print(serialInArray[2]);
  203. print(serialInArray[3]);
  204. print(serialInArray[4]);
  205. print(serialInArray[5]);
  206. print(serialInArray[6]);
  207. println(serialInArray[7]);
  208. */
  209.  
  210. int xPos = 67; //originally 50
  211. int yPos = 67; //originally 50
  212.  
  213. //Top Sensors - Bottom IR LED
  214. for(int i = 0; i < 8; i++){
  215. int movingXPos = xPos*(i+1);
  216. int movingYPos = yPos*(i+1);
  217. if(serialInArray[i] >=limitvalue){
  218. }
  219. else{
  220. stroke(255);
  221. //stroke(255,255,0); // YELLOW
  222. strokeWeight(strokewidth);
  223. //line (x1,y1,newX, height of sketch- number)
  224. //line(width/2, height, movingXPos, 0); //original
  225. line(width/2, height, movingXPos, 0); // TOP
  226. line(width/2, height, 0, movingYPos); // LEFT
  227. line(width/2, height, height, movingYPos); //RIGHT
  228. }
  229. }
  230.  
  231. //Top Sensors - Bottom Left IR LED
  232. for(int i = 0; i < 8; i++){
  233. int movingXPos = xPos*(i+1);
  234. int movingYPos = yPos*(i+1);
  235. if(serialInArray[i] >=limitvalue){
  236. }
  237. else{
  238. stroke(255);
  239. //stroke(255,255,0); // YELLOW
  240. strokeWeight(strokewidth);
  241. //line (x1,y1,newX, height of sketch- number)
  242. //line(width/2, height, movingXPos, 0); //original
  243. line(width/2-width/4, height, movingXPos, 0); // TOP
  244. line(width/2-width/4, height, 0, movingYPos); // LEFT
  245. line(width/2-width/4, height, height, movingYPos); //RIGHT
  246. }
  247. }
  248.  
  249. //Top Sensors - Bottom Right IR LED
  250. for(int i = 0; i < 8; i++){
  251. int movingXPos = xPos*(i+1);
  252. int movingYPos = yPos*(i+1);
  253. if(serialInArray[i] >=limitvalue){
  254. }
  255. else{
  256. stroke(255);
  257. //stroke(255,255,0); // YELLOW
  258. strokeWeight(strokewidth);
  259. //line (x1,y1,newX, height of sketch- number)
  260. //line(width/2, height, movingXPos, 0); //original
  261. line(width/2+width/4, height, movingXPos, 0); // TOP
  262. line(width/2+width/4, height, 0, movingYPos); // LEFT
  263. line(width/2+width/4, height, height, movingYPos); //RIGHT
  264. }
  265. }
  266.  
  267. //Bottom Sensors - Top IR LED
  268. for(int i = 0; i < 8; i++){
  269. int movingXPos = xPos*(i+1);
  270. int movingYPos = yPos*(i+1);
  271. if(serialInArray[i] >=limitvalue){
  272. }
  273. else{
  274. stroke(255);
  275. //stroke(255,0,0); // RED
  276. strokeWeight(strokewidth);
  277. //line (x1,y1,newX, height of sketch- number)
  278. //line(width/2, 0, movingXPos, height); //original
  279. line(width/2, 0, movingXPos, height); // BOTTOM
  280. line(width/2, 0, 0, movingYPos); // LEFT
  281. line(width/2, 0, height, movingYPos); //RIGHT
  282. }
  283. }
  284.  
  285. //Bottom Sensors - Top Left IR LED
  286. for(int i = 0; i < 8; i++){
  287. int movingXPos = xPos*(i+1);
  288. int movingYPos = yPos*(i+1);
  289. if(serialInArray[i] >=limitvalue){
  290. }
  291. else{
  292. stroke(255);
  293. //stroke(255,0,0); // RED
  294. strokeWeight(strokewidth);
  295. //line (x1,y1,newX, height of sketch- number)
  296. //line(width/2, 0, movingXPos, height); //original
  297. line(width/2-width/4, 0, movingXPos, height); // BOTTOM
  298. line(width/2-width/4, 0, 0, movingYPos); // LEFT
  299. line(width/2-width/4, 0, height, movingYPos); //RIGHT
  300. }
  301. }
  302.  
  303. //Bottom Sensors - Top Right IR LED
  304. for(int i = 0; i < 8; i++){
  305. int movingXPos = xPos*(i+1);
  306. int movingYPos = yPos*(i+1);
  307. if(serialInArray[i] >=limitvalue){
  308. }
  309. else{
  310. stroke(255);
  311. //stroke(255,0,0); // RED
  312. strokeWeight(strokewidth);
  313. //line (x1,y1,newX, height of sketch- number)
  314. //line(width/2, 0, movingXPos, height); //original
  315. line(width/2+width/4, 0, movingXPos, height); // BOTTOM
  316. line(width/2+width/4, 0, 0, movingYPos); // LEFT
  317. line(width/2+width/4, 0, height, movingYPos); //RIGHT
  318. }
  319. }
  320.  
  321. //Right Sensors - Left IR LED
  322. for(int i = 0; i < 8; i++){
  323. int movingXPos = xPos*(i+1);
  324. int movingYPos = yPos*(i+1);
  325. if(serialInArray[i] >=limitvalue){
  326. }
  327. else{
  328. stroke(255);
  329. //stroke(0,0,255); // BLUE
  330. strokeWeight(strokewidth);
  331. //line (x1,y1,newX, height of sketch- number)
  332. //line(0, height/2, height, movingYPos); //original
  333. line(0, height/2, height, movingYPos); // RIGHT
  334. line(0, height/2, movingXPos, height); // BOTTOM
  335. line(0, height/2, movingXPos, 0); // TOP
  336. }
  337. }
  338.  
  339. //Right Sensors - Left Top IR LED
  340. for(int i = 0; i < 8; i++){
  341. int movingXPos = xPos*(i+1);
  342. int movingYPos = yPos*(i+1);
  343. if(serialInArray[i] >=limitvalue){
  344. }
  345. else{
  346. stroke(255);
  347. //stroke(0,0,255); // BLUE
  348. strokeWeight(strokewidth);
  349. //line (x1,y1,newX, height of sketch- number)
  350. //line(0, height/2, height, movingYPos); //original
  351. line(0, height/2-height/4, height, movingYPos); // RIGHT
  352. line(0, height/2-height/4, movingXPos, height); // BOTTOM
  353. line(0, height/2-height/4, movingXPos, 0); // TOP
  354. }
  355. }
  356.  
  357. //Right Sensors - Left Bottom IR LED
  358. for(int i = 0; i < 8; i++){
  359. int movingXPos = xPos*(i+1);
  360. int movingYPos = yPos*(i+1);
  361. if(serialInArray[i] >=limitvalue){
  362. }
  363. else{
  364. stroke(255);
  365. //stroke(0,0,255); // BLUE
  366. strokeWeight(strokewidth);
  367. //line (x1,y1,newX, height of sketch- number)
  368. //line(0, height/2, height, movingYPos); //original
  369. line(0, height/2+height/4, height, movingYPos); // RIGHT
  370. line(0, height/2+height/4, movingXPos, height); // BOTTOM
  371. line(0, height/2+height/4, movingXPos, 0); // TOP
  372. }
  373. }
  374.  
  375.  
  376. //Left Sensors - Right IR LED
  377. for(int i = 0; i < 8; i++){
  378. int movingXPos = xPos*(i+1);
  379. int movingYPos = yPos*(i+1);
  380. if(serialInArray[i] >=limitvalue){
  381. }
  382. else{
  383. stroke(255);
  384. //stroke(0,255,0); // GREEN
  385. strokeWeight(strokewidth);
  386. //line (x1,y1,newX, height of sketch- number)
  387. //line(width, height/2, 0, movingYPos); //original
  388. line(width, height/2, 0, movingYPos); // LEFT
  389. line(width, height/2, movingXPos, height); // BOTTOM
  390. line(width, height/2, movingXPos, 0); // TOP
  391. }
  392. }
  393.  
  394. //Left Sensors - Right Top IR LED
  395. for(int i = 0; i < 8; i++){
  396. int movingXPos = xPos*(i+1);
  397. int movingYPos = yPos*(i+1);
  398. if(serialInArray[i] >=limitvalue){
  399. }
  400. else{
  401. stroke(255);
  402. //stroke(0,255,0); // GREEN
  403. strokeWeight(strokewidth);
  404. //line (x1,y1,newX, height of sketch- number)
  405. //line(width, height/2, 0, movingYPos); //original
  406. line(width, height/2-height/4, 0, movingYPos); // LEFT
  407. line(width, height/2-height/4, movingXPos, height); // BOTTOM
  408. line(width, height/2-height/4, movingXPos, 0); // TOP
  409. }
  410. }
  411.  
  412. //Left Sensors - Right Bottom IR LED
  413. for(int i = 0; i < 8; i++){
  414. int movingXPos = xPos*(i+1);
  415. int movingYPos = yPos*(i+1);
  416. if(serialInArray[i] >=limitvalue){
  417. }
  418. else{
  419. stroke(255);
  420. //stroke(0,255,0); // GREEN
  421. strokeWeight(strokewidth);
  422. //line (x1,y1,newX, height of sketch- number)
  423. //line(width, height/2, 0, movingYPos); //original
  424. line(width, height/2+height/4, 0, movingYPos); // LEFT
  425. line(width, height/2+height/4, movingXPos, height); // BOTTOM
  426. line(width, height/2+height/4, movingXPos, 0); // TOP
  427. }
  428. }
  429. }
Add Comment
Please, Sign In to add comment