找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1538|回复: 1
收起左侧

Arduino Processing控制8x8点阵 附源代码(第64位总是不对)

[复制链接]
ID:426684 发表于 2019-4-4 21:08 | 显示全部楼层 |阅读模式
使用:上位机Processing上画出8x8点阵图案,发送数据到Arduino驱动8x8点阵显示.数据很简单就是点阵的 1111100011110000.....(64位)发送串口.

问题: 点阵第64位总是不对(黑圈处),希望有高手指点哪里出问题.


88dz.JPG

IMG_20190404_202140_1.jpg

Arduino代码:
  1. int R[] = {2,7,A5,5,13,A4,12,A2}; //行  
  2. int C[] = {6,11,10,3,A3,4,8,9};   //列   
  3. char command;
  4. int mark = 0;
  5. int numdata[8][8];
  6. int data;
  7. char xh;
  8. void setup(){
  9. Serial.begin(9600);   
  10. for(int i = 0;i<8;i++){
  11. pinMode(R[i],OUTPUT);
  12. pinMode(C[i],OUTPUT);
  13. }

  14. for(int i = 0;i<8;i++){
  15.   for(int j = 0;j<8;j++){
  16.       numdata[i][j]=0;
  17. }
  18. }
  19. }

  20. void loop(){
  21. recv_data();
  22. updateServo();
  23. }

  24. void recv_data(){   
  25. while(Serial.available()){
  26. for(int i=0;i<8;i++){
  27.     numdata[i][0]=Serial.read();
  28.     delay(10);
  29.     numdata[i][1]=Serial.read();
  30.     delay(10);
  31.     numdata[i][2]=Serial.read();
  32.     delay(10);
  33.     numdata[i][3]=Serial.read();
  34.     delay(10);
  35.     numdata[i][4]=Serial.read();
  36.     delay(10);
  37.     numdata[i][5]=Serial.read();
  38.     delay(10);
  39.     numdata[i][6]=Serial.read();
  40.     delay(10);
  41.     numdata[i][7]=Serial.read();
  42.     }
  43.     delay(10);
  44. }
  45. mark = 1;
  46. }


  47. void updateServo(){
  48. if(mark == 1){
  49. for(int i = 0 ; i < 100 ; i++) {      
  50. for(int c = 0; c< 8;c++){  
  51. digitalWrite(C[c],LOW);//选通第c列  
  52. for(int r = 0;r< 8;r++){  
  53. digitalWrite(R[r],numdata[r][c]);  
  54. }  
  55. delay(1);  
  56. Clear();  //清空显示去除余晖  
  57. }  
  58. }
  59. mark == 0;
  60. }
  61. }

  62. void Clear(){  
  63.   for(int i = 0;i<8;i++){  
  64.     digitalWrite(R[i],LOW);  
  65.     digitalWrite(C[i],HIGH);  
  66.   }  
  67. }

  68. Processing 代码:
  69. //processing端程序
  70. import processing.serial.*;
  71. String comname="COM4";
  72. Serial port;
  73. boolean serial;
  74. byte Serial_StopFlag = 0;
  75. boolean Serial_OpenFlag = false;
  76. boolean Serial_DatareadFlag = false;
  77. boolean Serial_GetdataFlag = false;
  78. PFont myFont;
  79. PFont font;

  80. String[] mesg = new String[8];
  81. String[] command = new String[8];

  82. int a1=0;
  83. int a2=0;
  84. int a3=0;
  85. int a4=0;
  86. int a5=0;
  87. int a6=0;
  88. int a7=0;
  89. int a8=0;

  90. int b1=0;
  91. int b2=0;
  92. int b3=0;
  93. int b4=0;
  94. int b5=0;
  95. int b6=0;
  96. int b7=0;
  97. int b8=0;

  98. int c1=0;
  99. int c2=0;
  100. int c3=0;
  101. int c4=0;
  102. int c5=0;
  103. int c6=0;
  104. int c7=0;
  105. int c8=0;

  106. int d1=0;
  107. int d2=0;
  108. int d3=0;
  109. int d4=0;
  110. int d5=0;
  111. int d6=0;
  112. int d7=0;
  113. int d8=0;

  114. int e1=0;
  115. int e2=0;
  116. int e3=0;
  117. int e4=0;
  118. int e5=0;
  119. int e6=0;
  120. int e7=0;
  121. int e8=0;

  122. int f1=0;
  123. int f2=0;
  124. int f3=0;
  125. int f4=0;
  126. int f5=0;
  127. int f6=0;
  128. int f7=0;
  129. int f8=0;

  130. int g1=0;
  131. int g2=0;
  132. int g3=0;
  133. int g4=0;
  134. int g5=0;
  135. int g6=0;
  136. int g7=0;
  137. int g8=0;

  138. int h1=0;
  139. int h2=0;
  140. int h3=0;
  141. int h4=0;
  142. int h5=0;
  143. int h6=0;
  144. int h7=0;
  145. int h8=0;

  146. byte click = 0;

  147. //初试化
  148. void setup(){
  149. size(700,500);
  150. frameRate(53);
  151. port=new Serial(this,"COM4",9600);
  152. font = createFont("宋体.vlw",48);
  153. textFont(font);
  154. frameRate(30);
  155. smooth();
  156. for(int i=0;i<8;i++){
  157. mesg[i]="0,0,0,0,0,0,0,0";
  158. }

  159. for(int j=0;j<8;j++){
  160. command[j]="0,0,0,0,0,0,0,0,0";
  161. }
  162. }
  163. //主程序
  164. void draw(){
  165. background(255);
  166. inter_face();
  167. CheckBoxHandle1();
  168. CheckBoxHandle2();
  169. CheckBoxHandle3();
  170. CheckBoxHandle4();
  171. CheckBoxHandle5();
  172. CheckBoxHandle6();
  173. CheckBoxHandle7();
  174. CheckBoxHandle8();
  175. }

  176. void inter_face(){
  177. textSize(18);
  178. strokeWeight(2);
  179. fill(0);
  180. text("Processing 控制 8 x 8 点阵",280,20);
  181. line(0,25,700,25);
  182. line(0,450,700,450);
  183. line(0,280,700,280);
  184. textSize(16);
  185. strokeWeight(2);
  186. fill(0);
  187. text("向Arduino发送数据:",5,480);
  188. mesg[0]=a1+","+a2+","+a3+","+a4+","+a5+","+a6+","+a7+","+a8+",";
  189. mesg[1]=b1+","+b2+","+b3+","+b4+","+b5+","+b6+","+b7+","+b8+",";
  190. mesg[2]=c1+","+c2+","+c3+","+c4+","+c5+","+c6+","+c7+","+c8+",";
  191. mesg[3]=d1+","+d2+","+d3+","+d4+","+d5+","+d6+","+d7+","+d8+",";
  192. mesg[4]=e1+","+e2+","+e3+","+e4+","+e5+","+e6+","+e7+","+e8+",";
  193. mesg[5]=f1+","+f2+","+f3+","+f4+","+f5+","+f6+","+f7+","+f8+",";
  194. mesg[6]=g1+","+g2+","+g3+","+g4+","+g5+","+g6+","+g7+","+g8+",";
  195. mesg[7]=h1+","+h2+","+h3+","+h4+","+h5+","+h6+","+h7+","+h8+",";

  196. for(int i=0;i<8;i++){
  197. text(mesg[i],400,50+i*20);
  198. }
  199. if(button(500, 400,"发  送") != 0){
  200. send_data();
  201. }
  202. if(button(590, 400,"退  出") != 0){
  203. exit();
  204. }
  205. }

  206. //send data to Arduino
  207. void send_data(){
  208. for(int i=0;i<8;i++){
  209. command=split(mesg[i],',');
  210. print(command[0]);  
  211. print(command[1]);  
  212. print(command[2]);  
  213. print(command[3]);  
  214. print(command[4]);  
  215. print(command[5]);  
  216. print(command[6]);  
  217. print(command[7]);
  218. port.write(int(command[0]));
  219. port.write(int(command[1]));
  220. port.write(int(command[2]));
  221. port.write(int(command[3]));
  222. port.write(int(command[4]));
  223. port.write(int(command[5]));
  224. port.write(int(command[6]));
  225. port.write(int(command[7]));

  226. //delay(1);

  227. }
  228. serial=false;
  229. }



  230. //鼠标
  231. boolean mousePressedFlag = false;
  232. void mousePressed() {
  233. mousePressedFlag = true;
  234. }
  235. boolean SaveFlag = false;

  236. //按钮
  237. byte button(float x , float y , String str){
  238. byte ret = 0;
  239. fill(0,0,0);
  240. strokeWeight(2);
  241. //stroke(255,255,0);
  242. if((mouseX > x) && (mouseY > y) && (mouseX < (x + 100) ) &&(mouseY < (y + 30))){
  243. fill(128,255,255);
  244. if (mousePressedFlag && (mouseButton == LEFT)) {
  245. mousePressedFlag = false;
  246. fill(0,128,128);
  247. ret = 1;
  248. }
  249. }
  250. rect(x,y, 80, 30);
  251. fill(255,255,255);
  252. textSize(16);
  253. text(str, x + 24, y + 22);
  254. return ret;
  255. }
  256. //舵机角度选择
  257. boolean a1_checkBox = false;
  258. boolean a2_checkBox = false;
  259. boolean a3_checkBox = false;
  260. boolean a4_checkBox = false;
  261. boolean a5_checkBox = false;
  262. boolean a6_checkBox = false;
  263. boolean a7_checkBox = false;
  264. boolean a8_checkBox = false;

  265. void CheckBoxHandle1(){
  266. if(CheckBox(20,30,a1_checkBox, "")== 1){
  267. a1_checkBox = (a1_checkBox == false) ? true: false;
  268. if(a1_checkBox == true){
  269. a1=1;
  270. }else{
  271. a1=0;
  272. }
  273. }
  274. if(CheckBox(60,30,a2_checkBox, "") == 1){
  275. a2_checkBox = (a2_checkBox == false) ? true: false;
  276. if(a2_checkBox == true){
  277. a2=1;
  278. }else{
  279. a2=0;
  280. }
  281. }
  282. if(CheckBox(100,30, a3_checkBox, "") == 1){
  283. a3_checkBox = (a3_checkBox == false) ? true: false;
  284. if(a3_checkBox == true){
  285. a3=1;
  286. }else{
  287. a3=0;
  288. }
  289. }
  290. if(CheckBox(140,30, a4_checkBox, "") == 1){
  291. a4_checkBox = (a4_checkBox == false) ? true: false;
  292. if(a4_checkBox == true){
  293. a4=1;
  294. }else{
  295. a4=0;
  296. }
  297. }

  298. if(CheckBox(180,30, a5_checkBox, "") == 1){
  299. a5_checkBox = (a5_checkBox == false) ? true: false;
  300. if(a5_checkBox == true){
  301. a5=1;
  302. }else{
  303. a5=0;
  304. }
  305. }

  306. if(CheckBox(220,30, a6_checkBox, "") == 1){
  307. a6_checkBox = (a6_checkBox == false) ? true: false;
  308. if(a6_checkBox == true){
  309. a6=1;
  310. }else{
  311. a6=0;
  312. }
  313. }

  314. if(CheckBox(260,30, a7_checkBox, "") == 1){
  315. a7_checkBox = (a7_checkBox == false) ? true: false;
  316. if(a7_checkBox == true){
  317. a7=1;
  318. }else{
  319. a7=0;
  320. }
  321. }

  322. if(CheckBox(300,30, a8_checkBox, "") == 1){
  323. a8_checkBox = (a8_checkBox == false) ? true: false;
  324. if(a8_checkBox == true){
  325. a8=1;
  326. }else{
  327. a8=0;
  328. }
  329. }

  330. }
  331. boolean checkBox_Geta1Flag(){
  332. return a1_checkBox;
  333. }
  334. boolean checkBox_Geta2Flag(){
  335. return a2_checkBox;
  336. }
  337. boolean checkBox_Geta3Flag(){
  338. return a3_checkBox;
  339. }
  340. boolean checkBox_Geta4lag(){
  341. return a4_checkBox;
  342. }
  343. boolean checkBox_Geta5Flag(){
  344. return a5_checkBox;
  345. }
  346. boolean checkBox_Geta6Flag(){
  347. return a6_checkBox;
  348. }
  349. boolean checkBox_Geta7Flag(){
  350. return a7_checkBox;
  351. }
  352. boolean checkBox_Geta8lag(){
  353. return a8_checkBox;
  354. }


  355. //舵机角度选择
  356. boolean b1_checkBox = false;
  357. boolean b2_checkBox = false;
  358. boolean b3_checkBox = false;
  359. boolean b4_checkBox = false;
  360. boolean b5_checkBox = false;
  361. boolean b6_checkBox = false;
  362. boolean b7_checkBox = false;
  363. boolean b8_checkBox = false;

  364. void CheckBoxHandle2(){
  365. if(CheckBox(20,60,b1_checkBox, "")== 1){
  366. b1_checkBox = (b1_checkBox == false) ? true: false;
  367. if(b1_checkBox == true){
  368. b1=1;
  369. }else{
  370. b1=0;
  371. }
  372. }
  373. if(CheckBox(60,60,b2_checkBox, "") == 1){
  374. b2_checkBox = (b2_checkBox == false) ? true: false;
  375. if(b2_checkBox == true){
  376. b2=1;
  377. }else{
  378. b2=0;
  379. }
  380. }
  381. if(CheckBox(100,60, b3_checkBox, "") == 1){
  382. b3_checkBox = (b3_checkBox == false) ? true: false;
  383. if(b3_checkBox == true){
  384. b3=1;
  385. }else{
  386. b3=0;
  387. }
  388. }
  389. if(CheckBox(140,60, b4_checkBox, "") == 1){
  390. b4_checkBox = (b4_checkBox == false) ? true: false;
  391. if(b4_checkBox == true){
  392. b4=1;
  393. }else{
  394. b4=0;
  395. }
  396. }

  397. if(CheckBox(180,60, b5_checkBox, "") == 1){
  398. b5_checkBox = (b5_checkBox == false) ? true: false;
  399. if(b5_checkBox == true){
  400. b5=1;
  401. }else{
  402. b5=0;
  403. }
  404. }

  405. if(CheckBox(220,60, b6_checkBox, "") == 1){
  406. b6_checkBox = (b6_checkBox == false) ? true: false;
  407. if(b6_checkBox == true){
  408. b6=1;
  409. }else{
  410. b6=0;
  411. }
  412. }

  413. if(CheckBox(260,60, b7_checkBox, "") == 1){
  414. b7_checkBox = (b7_checkBox == false) ? true: false;
  415. if(b7_checkBox == true){
  416. b7=1;
  417. }else{
  418. b7=0;
  419. }
  420. }

  421. if(CheckBox(300,60, b8_checkBox, "") == 1){
  422. b8_checkBox = (b8_checkBox == false) ? true: false;
  423. if(b8_checkBox == true){
  424. b8=1;
  425. }else{
  426. b8=0;
  427. }
  428. }

  429. }
  430. boolean checkBox_Getb1Flag(){
  431. return b1_checkBox;
  432. }
  433. boolean checkBox_Getb2Flag(){
  434. return b2_checkBox;
  435. }
  436. boolean checkBox_Getb3Flag(){
  437. return b3_checkBox;
  438. }
  439. boolean checkBox_Getb4lag(){
  440. return b4_checkBox;
  441. }
  442. boolean checkBox_Getb5Flag(){
  443. return b5_checkBox;
  444. }
  445. boolean checkBox_Getb6Flag(){
  446. return b6_checkBox;
  447. }
  448. boolean checkBox_Getb7Flag(){
  449. return b7_checkBox;
  450. }
  451. boolean checkBox_Getb8lag(){
  452. return b8_checkBox;
  453. }

  454. //舵机角度选择
  455. boolean c1_checkBox = false;
  456. boolean c2_checkBox = false;
  457. boolean c3_checkBox = false;
  458. boolean c4_checkBox = false;
  459. boolean c5_checkBox = false;
  460. boolean c6_checkBox = false;
  461. boolean c7_checkBox = false;
  462. boolean c8_checkBox = false;

  463. void CheckBoxHandle3(){
  464. if(CheckBox(20,90,c1_checkBox, "")== 1){
  465. c1_checkBox = (c1_checkBox == false) ? true: false;
  466. if(c1_checkBox == true){
  467. c1=1;
  468. }else{
  469. c1=0;
  470. }
  471. }
  472. if(CheckBox(60,90,c2_checkBox, "") == 1){
  473. c2_checkBox = (c2_checkBox == false) ? true: false;
  474. if(c2_checkBox == true){
  475. c2=1;
  476. }else{
  477. c2=0;
  478. }
  479. }
  480. if(CheckBox(100,90, c3_checkBox, "") == 1){
  481. c3_checkBox = (c3_checkBox == false) ? true: false;
  482. if(c3_checkBox == true){
  483. c3=1;
  484. }else{
  485. c3=0;
  486. }
  487. }
  488. if(CheckBox(140,90, c4_checkBox, "") == 1){
  489. c4_checkBox = (c4_checkBox == false) ? true: false;
  490. if(c4_checkBox == true){
  491. c4=1;
  492. }else{
  493. c4=0;
  494. }
  495. }

  496. if(CheckBox(180,90, c5_checkBox, "") == 1){
  497. c5_checkBox = (c5_checkBox == false) ? true: false;
  498. if(c5_checkBox == true){
  499. c5=1;
  500. }else{
  501. c5=0;
  502. }
  503. }

  504. if(CheckBox(220,90, c6_checkBox, "") == 1){
  505. c6_checkBox = (c6_checkBox == false) ? true: false;
  506. if(c6_checkBox == true){
  507. c6=1;
  508. }else{
  509. c6=0;
  510. }
  511. }

  512. if(CheckBox(260,90, c7_checkBox, "") == 1){
  513. c7_checkBox = (c7_checkBox == false) ? true: false;
  514. if(c7_checkBox == true){
  515. c7=1;
  516. }else{
  517. c7=0;
  518. }
  519. }

  520. if(CheckBox(300,90, c8_checkBox, "") == 1){
  521. c8_checkBox = (c8_checkBox == false) ? true: false;
  522. if(c8_checkBox == true){
  523. c8=1;
  524. }else{
  525. c8=0;
  526. }
  527. }

  528. }
  529. boolean checkBox_Getc1Flag(){
  530. return c1_checkBox;
  531. }
  532. boolean checkBox_Getc2Flag(){
  533. return c2_checkBox;
  534. }
  535. boolean checkBox_Getc3Flag(){
  536. return c3_checkBox;
  537. }
  538. boolean checkBox_Getc4lag(){
  539. return c4_checkBox;
  540. }
  541. boolean checkBox_Getc5Flag(){
  542. return c5_checkBox;
  543. }
  544. boolean checkBox_Getc6Flag(){
  545. return c6_checkBox;
  546. }
  547. boolean checkBox_Getc7Flag(){
  548. return c7_checkBox;
  549. }
  550. boolean checkBox_Getc8lag(){
  551. return c8_checkBox;
  552. }

  553. //舵机角度选择
  554. boolean d1_checkBox = false;
  555. boolean d2_checkBox = false;
  556. boolean d3_checkBox = false;
  557. boolean d4_checkBox = false;
  558. boolean d5_checkBox = false;
  559. boolean d6_checkBox = false;
  560. boolean d7_checkBox = false;
  561. boolean d8_checkBox = false;

  562. void CheckBoxHandle4(){
  563. if(CheckBox(20,120,d1_checkBox, "")== 1){
  564. d1_checkBox = (d1_checkBox == false) ? true: false;
  565. if(d1_checkBox == true){
  566. d1=1;
  567. }else{
  568. d1=0;
  569. }
  570. }
  571. if(CheckBox(60,120,d2_checkBox, "") == 1){
  572. d2_checkBox = (d2_checkBox == false) ? true: false;
  573. if(d2_checkBox == true){
  574. d2=1;
  575. }else{
  576. d2=0;
  577. }
  578. }
  579. if(CheckBox(100,120, d3_checkBox, "") == 1){
  580. d3_checkBox = (d3_checkBox == false) ? true: false;
  581. if(d3_checkBox == true){
  582. d3=1;
  583. }else{
  584. d3=0;
  585. }
  586. }
  587. if(CheckBox(140,120, d4_checkBox, "") == 1){
  588. d4_checkBox = (d4_checkBox == false) ? true: false;
  589. if(d4_checkBox == true){
  590. d4=1;
  591. }else{
  592. d4=0;
  593. }
  594. }

  595. if(CheckBox(180,120, d5_checkBox, "") == 1){
  596. d5_checkBox = (d5_checkBox == false) ? true: false;
  597. if(d5_checkBox == true){
  598. d5=1;
  599. }else{
  600. d5=0;
  601. }
  602. }

  603. if(CheckBox(220,120, d6_checkBox, "") == 1){
  604. d6_checkBox = (d6_checkBox == false) ? true: false;
  605. if(d6_checkBox == true){
  606. d6=1;
  607. }else{
  608. d6=0;
  609. }
  610. }

  611. if(CheckBox(260,120, d7_checkBox, "") == 1){
  612. d7_checkBox = (d7_checkBox == false) ? true: false;
  613. if(d7_checkBox == true){
  614. d7=1;
  615. }else{
  616. d7=0;
  617. }
  618. }

  619. if(CheckBox(300,120, d8_checkBox, "") == 1){
  620. d8_checkBox = (d8_checkBox == false) ? true: false;
  621. if(d8_checkBox == true){
  622. d8=1;
  623. }else{
  624. d8=0;
  625. }
  626. }

  627. }
  628. boolean checkBox_Getd1Flag(){
  629. return d1_checkBox;
  630. }
  631. boolean checkBox_Getd2Flag(){
  632. return d2_checkBox;
  633. }
  634. boolean checkBox_Getd3Flag(){
  635. return d3_checkBox;
  636. }
  637. boolean checkBox_Getd4lag(){
  638. return d4_checkBox;
  639. }
  640. boolean checkBox_Getd5Flag(){
  641. return d5_checkBox;
  642. }
  643. boolean checkBox_Getd6Flag(){
  644. return d6_checkBox;
  645. }
  646. boolean checkBox_Getd7Flag(){
  647. return d7_checkBox;
  648. }
  649. boolean checkBox_Getd8lag(){
  650. return d8_checkBox;
  651. }

  652. //舵机角度选择
  653. boolean e1_checkBox = false;
  654. boolean e2_checkBox = false;
  655. boolean e3_checkBox = false;
  656. boolean e4_checkBox = false;
  657. boolean e5_checkBox = false;
  658. boolean e6_checkBox = false;
  659. boolean e7_checkBox = false;
  660. boolean e8_checkBox = false;

  661. void CheckBoxHandle5(){
  662. if(CheckBox(20,150,e1_checkBox, "")== 1){
  663. e1_checkBox = (e1_checkBox == false) ? true: false;
  664. if(e1_checkBox == true){
  665. e1=1;
  666. }else{
  667. e1=0;
  668. }
  669. }
  670. if(CheckBox(60,150,e2_checkBox, "") == 1){
  671. e2_checkBox = (e2_checkBox == false) ? true: false;
  672. if(e2_checkBox == true){
  673. e2=1;
  674. }else{
  675. e2=0;
  676. }
  677. }
  678. if(CheckBox(100,150, e3_checkBox, "") == 1){
  679. e3_checkBox = (e3_checkBox == false) ? true: false;
  680. if(e3_checkBox == true){
  681. e3=1;
  682. }else{
  683. e3=0;
  684. }
  685. }
  686. if(CheckBox(140,150, e4_checkBox, "") == 1){
  687. e4_checkBox = (e4_checkBox == false) ? true: false;
  688. if(e4_checkBox == true){
  689. e4=1;
  690. }else{
  691. e4=0;
  692. }
  693. }

  694. if(CheckBox(180,150, e5_checkBox, "") == 1){
  695. e5_checkBox = (e5_checkBox == false) ? true: false;
  696. if(e5_checkBox == true){
  697. e5=1;
  698. }else{
  699. e5=0;
  700. }
  701. }

  702. if(CheckBox(220,150, e6_checkBox, "") == 1){
  703. e6_checkBox = (e6_checkBox == false) ? true: false;
  704. if(e6_checkBox == true){
  705. e6=1;
  706. }else{
  707. e6=0;
  708. }
  709. }

  710. if(CheckBox(260,150, e7_checkBox, "") == 1){
  711. e7_checkBox = (e7_checkBox == false) ? true: false;
  712. if(e7_checkBox == true){
  713. e7=1;
  714. }else{
  715. e7=0;
  716. }
  717. }

  718. if(CheckBox(300,150, e8_checkBox, "") == 1){
  719. e8_checkBox = (e8_checkBox == false) ? true: false;
  720. if(e8_checkBox == true){
  721. e8=1;
  722. }else{
  723. e8=0;
  724. }
  725. }

  726. }
  727. boolean checkBox_Gete1Flag(){
  728. return e1_checkBox;
  729. }
  730. boolean checkBox_Gete2Flag(){
  731. return e2_checkBox;
  732. }
  733. boolean checkBox_Gete3Flag(){
  734. return e3_checkBox;
  735. }
  736. boolean checkBox_Gete4lag(){
  737. return e4_checkBox;
  738. }
  739. boolean checkBox_Gete5Flag(){
  740. return e5_checkBox;
  741. }
  742. boolean checkBox_Gete6Flag(){
  743. return e6_checkBox;
  744. }
  745. boolean checkBox_Gete7Flag(){
  746. return e7_checkBox;
  747. }
  748. boolean checkBox_Gete8lag(){
  749. return e8_checkBox;
  750. }

  751. //舵机角度选择
  752. boolean f1_checkBox = false;
  753. boolean f2_checkBox = false;
  754. boolean f3_checkBox = false;
  755. boolean f4_checkBox = false;
  756. boolean f5_checkBox = false;
  757. boolean f6_checkBox = false;
  758. boolean f7_checkBox = false;
  759. boolean f8_checkBox = false;

  760. void CheckBoxHandle6(){
  761. if(CheckBox(20,180,f1_checkBox, "")== 1){
  762. f1_checkBox = (f1_checkBox == false) ? true: false;
  763. if(f1_checkBox == true){
  764. f1=1;
  765. }else{
  766. f1=0;
  767. }
  768. }
  769. if(CheckBox(60,180,f2_checkBox, "") == 1){
  770. f2_checkBox = (f2_checkBox == false) ? true: false;
  771. if(f2_checkBox == true){
  772. f2=1;
  773. }else{
  774. f2=0;
  775. }
  776. }
  777. if(CheckBox(100,180, f3_checkBox, "") == 1){
  778. f3_checkBox = (f3_checkBox == false) ? true: false;
  779. if(f3_checkBox == true){
  780. f3=1;
  781. }else{
  782. f3=0;
  783. }
  784. }
  785. if(CheckBox(140,180, f4_checkBox, "") == 1){
  786. f4_checkBox = (f4_checkBox == false) ? true: false;
  787. if(f4_checkBox == true){
  788. f4=1;
  789. }else{
  790. f4=0;
  791. }
  792. }

  793. if(CheckBox(180,180, f5_checkBox, "") == 1){
  794. f5_checkBox = (f5_checkBox == false) ? true: false;
  795. if(f5_checkBox == true){
  796. f5=1;
  797. }else{
  798. f5=0;
  799. }
  800. }

  801. if(CheckBox(220,180, f6_checkBox, "") == 1){
  802. f6_checkBox = (f6_checkBox == false) ? true: false;
  803. if(f6_checkBox == true){
  804. f6=1;
  805. }else{
  806. f6=0;
  807. }
  808. }

  809. if(CheckBox(260,180, f7_checkBox, "") == 1){
  810. f7_checkBox = (f7_checkBox == false) ? true: false;
  811. if(f7_checkBox == true){
  812. f7=1;
  813. }else{
  814. f7=0;
  815. }
  816. }

  817. if(CheckBox(300,180, f8_checkBox, "") == 1){
  818. f8_checkBox = (f8_checkBox == false) ? true: false;
  819. if(f8_checkBox == true){
  820. f8=1;
  821. }else{
  822. f8=0;
  823. }
  824. }

  825. }
  826. boolean checkBox_Getf1Flag(){
  827. return f1_checkBox;
  828. }
  829. boolean checkBox_Getf2Flag(){
  830. return f2_checkBox;
  831. }
  832. boolean checkBox_Getf3Flag(){
  833. return f3_checkBox;
  834. }
  835. boolean checkBox_Getf4lag(){
  836. return f4_checkBox;
  837. }
  838. boolean checkBox_Getf5Flag(){
  839. return f5_checkBox;
  840. }
  841. boolean checkBox_Getf6Flag(){
  842. return f6_checkBox;
  843. }
  844. boolean checkBox_Getf7Flag(){
  845. return f7_checkBox;
  846. }
  847. boolean checkBox_Getf8lag(){
  848. return f8_checkBox;
  849. }


  850. //舵机角度选择
  851. boolean g1_checkBox = false;
  852. boolean g2_checkBox = false;
  853. boolean g3_checkBox = false;
  854. boolean g4_checkBox = false;
  855. boolean g5_checkBox = false;
  856. boolean g6_checkBox = false;
  857. boolean g7_checkBox = false;
  858. boolean g8_checkBox = false;

  859. void CheckBoxHandle7(){
  860. if(CheckBox(20,210,g1_checkBox, "")== 1){
  861. g1_checkBox = (g1_checkBox == false) ? true: false;
  862. if(g1_checkBox == true){
  863. g1=1;
  864. }else{
  865. g1=0;
  866. }
  867. }
  868. if(CheckBox(60,210,g2_checkBox, "") == 1){
  869. g2_checkBox = (g2_checkBox == false) ? true: false;
  870. if(g2_checkBox == true){
  871. g2=1;
  872. }else{
  873. g2=0;
  874. }
  875. }
  876. if(CheckBox(100,210, g3_checkBox, "") == 1){
  877. g3_checkBox = (g3_checkBox == false) ? true: false;
  878. if(g3_checkBox == true){
  879. g3=1;
  880. }else{
  881. g3=0;
  882. }
  883. }
  884. if(CheckBox(140,210, g4_checkBox, "") == 1){
  885. g4_checkBox = (g4_checkBox == false) ? true: false;
  886. if(g4_checkBox == true){
  887. g4=1;
  888. }else{
  889. g4=0;
  890. }
  891. }

  892. if(CheckBox(180,210, g5_checkBox, "") == 1){
  893. g5_checkBox = (g5_checkBox == false) ? true: false;
  894. if(g5_checkBox == true){
  895. g5=1;
  896. }else{
  897. g5=0;
  898. }
  899. }

  900. if(CheckBox(220,210, g6_checkBox, "") == 1){
  901. g6_checkBox = (g6_checkBox == false) ? true: false;
  902. if(g6_checkBox == true){
  903. g6=1;
  904. }else{
  905. g6=0;
  906. }
  907. }

  908. if(CheckBox(260,210, g7_checkBox, "") == 1){
  909. g7_checkBox = (g7_checkBox == false) ? true: false;
  910. if(g7_checkBox == true){
  911. g7=1;
  912. }else{
  913. g7=0;
  914. }
  915. }

  916. if(CheckBox(300,210, g8_checkBox, "") == 1){
  917. g8_checkBox = (g8_checkBox == false) ? true: false;
  918. if(g8_checkBox == true){
  919. g8=1;
  920. }else{
  921. g8=0;
  922. }
  923. }
  924. }

  925. boolean checkBox_Getg1Flag(){
  926. return g1_checkBox;
  927. }
  928. boolean checkBox_Getg2Flag(){
  929. return g2_checkBox;
  930. }
  931. boolean checkBox_Getg3Flag(){
  932. return g3_checkBox;
  933. }
  934. boolean checkBox_Getg4lag(){
  935. return g4_checkBox;
  936. }
  937. boolean checkBox_Getg5Flag(){
  938. return g5_checkBox;
  939. }
  940. boolean checkBox_Getg6Flag(){
  941. return g6_checkBox;
  942. }
  943. boolean checkBox_Getg7Flag(){
  944. return g7_checkBox;
  945. }
  946. boolean checkBox_Getg8lag(){
  947. return g8_checkBox;
  948. }

  949. //舵机角度选择
  950. boolean h1_checkBox = false;
  951. boolean h2_checkBox = false;
  952. boolean h3_checkBox = false;
  953. boolean h4_checkBox = false;
  954. boolean h5_checkBox = false;
  955. boolean h6_checkBox = false;
  956. boolean h7_checkBox = false;
  957. boolean h8_checkBox = false;

  958. void CheckBoxHandle8(){
  959. if(CheckBox(20,240,h1_checkBox, "")== 1){
  960. h1_checkBox = (h1_checkBox == false) ? true: false;
  961. if(h1_checkBox == true){
  962. h1=1;
  963. }else{
  964. h1=0;
  965. }
  966. }
  967. if(CheckBox(60,240,h2_checkBox, "") == 1){
  968. h2_checkBox = (h2_checkBox == false) ? true: false;
  969. if(h2_checkBox == true){
  970. h2=1;
  971. }else{
  972. h2=0;
  973. }
  974. }
  975. if(CheckBox(100,240, h3_checkBox, "") == 1){
  976. h3_checkBox = (h3_checkBox == false) ? true: false;
  977. if(h3_checkBox == true){
  978. h3=1;
  979. }else{
  980. h3=0;
  981. }
  982. }
  983. if(CheckBox(140,240, h4_checkBox, "") == 1){
  984. h4_checkBox = (h4_checkBox == false) ? true: false;
  985. if(h4_checkBox == true){
  986. h4=1;
  987. }else{
  988. h4=0;
  989. }
  990. }

  991. if(CheckBox(180,240, h5_checkBox, "") == 1){
  992. h5_checkBox = (h5_checkBox == false) ? true: false;
  993. if(h5_checkBox == true){
  994. h5=1;
  995. }else{
  996. h5=0;
  997. }
  998. }

  999. if(CheckBox(220,240, h6_checkBox, "") == 1){
  1000. h6_checkBox = (h6_checkBox == false) ? true: false;
  1001. if(h6_checkBox == true){
  1002. h6=1;
  1003. }else{
  1004. h6=0;
  1005. }
  1006. }

  1007. if(CheckBox(260,240, h7_checkBox, "") == 1){
  1008. h7_checkBox = (h7_checkBox == false) ? true: false;
  1009. if(h7_checkBox == true){
  1010. h7=1;
  1011. }else{
  1012. h7=0;
  1013. }
  1014. }

  1015. if(CheckBox(300,240, h8_checkBox, "") == 1){
  1016. h8_checkBox = (h8_checkBox == false) ? true: false;
  1017. if(h8_checkBox == true){
  1018. h8=1;
  1019. }else{
  1020. h8=0;
  1021. }
  1022. }
  1023. }

  1024. boolean checkBox_Geth1Flag(){
  1025. return h1_checkBox;
  1026. }
  1027. boolean checkBox_Geth2Flag(){
  1028. return h2_checkBox;
  1029. }
  1030. boolean checkBox_Geth3Flag(){
  1031. return h3_checkBox;
  1032. }
  1033. boolean checkBox_Geth4lag(){
  1034. return h4_checkBox;
  1035. }
  1036. boolean checkBox_Geth5Flag(){
  1037. return h5_checkBox;
  1038. }
  1039. boolean checkBox_Geth6Flag(){
  1040. return h6_checkBox;
  1041. }
  1042. boolean checkBox_Geth7Flag(){
  1043. return h7_checkBox;
  1044. }
  1045. boolean checkBox_Geth8lag(){
  1046. return h8_checkBox;
  1047. }

  1048. byte CheckBox(float x, float y, boolean sL, String str){
  1049. noFill();
  1050. //stroke(255,255,0);
  1051. if(sL){
  1052. fill(0,255,0);
  1053. }
  1054. rect(x, y, 22, 22);
  1055. textSize(16);
  1056. fill(0);
  1057. strokeWeight(2);
  1058. text(str, x + 30, y + 20);
  1059. if((mouseX > x) && (mouseY > y) && (mouseX < (x + 20) ) &&(mouseY < (y + 20))){
  1060. if (mousePressedFlag && (mouseButton == LEFT)) {
  1061. mousePressedFlag = false;
  1062. return 1;
  1063. }
  1064. }
  1065. return 0;
  1066. }

  1067. void Serial_SetClick()
  1068. {
  1069. click = 1;
  1070. }
复制代码



回复

使用道具 举报

ID:423926 发表于 2019-4-6 15:48 | 显示全部楼层
认真向你学习!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表