极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9747|回复: 4

求助-谢了一个密室解谜的小程序 校验的时候出问题了

[复制链接]
发表于 2013-8-13 17:07:57 | 显示全部楼层 |阅读模式
本帖最后由 变态琳纸 于 2013-8-13 17:28 编辑

这个程序我是用于密室解谜时开门前的小谜题··· 这里有6个双色LED,3个轻触开关和1个电磁继电器。只有通过按动轻触开关把6个LED全部转化成绿色之后电磁继电器将会吸合9秒,接通电子锁的电路。与此同时,必须把找到的门禁卡插在合适的位置·· 不然就重新做题···  为此我就写了如下的程序····


程序如下:
  1. */
  2. /*
  3. ledr1Pin=1;
  4. ledg1Pin=2;
  5. ledr2Pin=3;
  6. ledg2Pin=4;
  7. ledr3Pin=5;
  8. ledg3Pin=6;
  9. ledr4Pin=7;
  10. ledg4Pin=8;
  11. ledr5Pin=9;
  12. ledg5Pin=10;
  13. ledr6Pin=11;
  14. ledg6Pin=12;
  15. x1=13;
  16. x2=14;
  17. x3=15;
  18. out1=16*/
  19. void ln()/*不是1,是LOGIC的L,表示的是真值表,我用非门来做的,可以根据喜好更改这个真值表,比如说或门,与门,,当然,混合在一起也是可以的,但是注意别冲突,不能3个真值表函数同时使用*/
  20. {
  21. 11==00+00;
  22. 11==00+01;
  23. 11==00+10;
  24. 11==00+11;
  25. 10==01+01;
  26. 11==01+10;
  27. 10==01+11;
  28. 01==10+10;
  29. 01==10+11;
  30. 00==11+11;
  31. }
  32. /*与门
  33. void la()
  34. {
  35. 00+00=00;
  36. 00+01=01;
  37. 00+10=10;
  38. 00+11=11;
  39. 01+01=01;
  40. 01+10=11;
  41. 01+11=11;
  42. 10+10=10;
  43. 10+11=11;
  44. 11+11=11;
  45. }
  46. */
  47. /*或门
  48. void lo()
  49. {
  50. 00+00=00;
  51. 00+01=01;
  52. 00+10=10;
  53. 00+11=11;
  54. 01+01=01;
  55. 01+10=11;
  56. 01+11=11;
  57. 10+10=10;
  58. 10+11=11;
  59. 11+11=11;
  60. }
  61. */
  62. void a()
  63. {
  64. int a=00;
  65. int b=00;
  66. int c=00;


  67. if(a==00)
  68. {
  69. digitalWrite(1, HIGH);
  70. digitalWrite(2, LOW);
  71. digitalWrite(3, HIGH);
  72. digitalWrite(4, LOW);
  73. }
  74. if(a==01)
  75. {
  76. digitalWrite(1, HIGH);
  77. digitalWrite(2, LOW);
  78. digitalWrite(3, LOW);
  79. digitalWrite(4, HIGH);
  80. }
  81. if(a==10)
  82. {
  83. digitalWrite(1, LOW);
  84. digitalWrite(2, HIGH);
  85. digitalWrite(3, HIGH);
  86. digitalWrite(4, LOW);
  87. }
  88. if(a==11)
  89. {
  90. digitalWrite(1, LOW);
  91. digitalWrite(2, HIGH);
  92. digitalWrite(3, LOW);
  93. digitalWrite(4, HIGH);
  94. }
  95. if(b==00)
  96. {
  97. digitalWrite(5, HIGH);
  98. digitalWrite(6, LOW);
  99. digitalWrite(7, HIGH);
  100. digitalWrite(8, LOW);
  101. }
  102. if(b==01)
  103. {
  104. digitalWrite(5, LOW);
  105. digitalWrite(6, HIGH);
  106. digitalWrite(7, HIGH);
  107. digitalWrite(8, LOW);
  108. }
  109. if(b==10)
  110. {
  111. digitalWrite(5, HIGH);
  112. digitalWrite(6, LOW);
  113. digitalWrite(7, LOW);
  114. digitalWrite(8, HIGH);
  115. }
  116. if(b==11)
  117. {
  118. digitalWrite(5, LOW);
  119. digitalWrite(6, HIGH);
  120. digitalWrite(7, LOW);
  121. digitalWrite(8, HIGH);
  122. }
  123. if(c==00)
  124. {
  125. digitalWrite(9, HIGH);
  126. digitalWrite(10, LOW);
  127. digitalWrite(11, HIGH);
  128. digitalWrite(12, LOW);
  129. }
  130. if(c==01)
  131. {
  132. digitalWrite(9, HIGH);
  133. digitalWrite(10, LOW);
  134. digitalWrite(11, LOW);
  135. digitalWrite(12, HIGH);
  136. }if(c==10)
  137. {
  138. digitalWrite(9, LOW);
  139. digitalWrite(10, HIGH);
  140. digitalWrite(11, HIGH);
  141. digitalWrite(12, LOW);
  142. }
  143. if(c==11)
  144. {
  145. digitalWrite(9, LOW);
  146. digitalWrite(10, HIGH);
  147. digitalWrite(11, LOW);
  148. digitalWrite(12, HIGH);
  149. }
  150. }
  151. void setup()
  152. {
  153. pinMode(1,OUTPUT);
  154. pinMode(2,OUTPUT);
  155. pinMode(3,OUTPUT);
  156. pinMode(4,OUTPUT);
  157. pinMode(5,OUTPUT);
  158. pinMode(6,OUTPUT);
  159. pinMode(7,OUTPUT);
  160. pinMode(8,OUTPUT);
  161. pinMode(9,OUTPUT);
  162. pinMode(10,OUTPUT);
  163. pinMode(11,OUTPUT);
  164. pinMode(12,OUTPUT);
  165. pinMode(13,INPUT);
  166. pinMode(14,INPUT);
  167. pinMode(15,INPUT);
  168. pinMode(16,OUTPUT);
  169. //设定数字I/O口为输出状态等,S1-S3作为轻触开关的输入口,OUT1继电器的输出口
  170. }
  171. void loop()
  172. {
  173. int a1;
  174. int a2;
  175. int a3;
  176. int a4;
  177. a1=random(1,99);
  178. a2=random(1,99);
  179. a3=random(1,99);
  180. a4=random(1,99);


  181. if(a1>a2>a3>a4)
  182. {
  183. int s1=00;
  184. int s2=01;
  185. int s3=10;
  186. }
  187. else if(a1>a2>a4>a3)
  188. {
  189. int s1=00;
  190. int s2=01;
  191. int s3=11;
  192. }
  193. else if(a1>a3>a2>a4)
  194. {
  195. int s1=00;
  196. int s2=10;
  197. int s3=01;
  198. }
  199. else if(a1>a3>a4>a2)
  200. {
  201. int s1=00;
  202. int s2=10;
  203. int s3=11;
  204. }
  205. else if(a1>a4>a3>a2)
  206. {
  207. int s1=00;
  208. int s2=11;
  209. int s3=10;
  210. }
  211. else if(a1>a4>a2>a3)
  212. {
  213. int s1=00;
  214. int s2=11;
  215. int s3=01;
  216. }
  217. else if(a2>a1>a3>a4)
  218. {
  219. int s1=01;
  220. int s2=00;
  221. int s3=10;
  222. }
  223. else if(a2>a1>a4>a3)
  224. {
  225. int s1=01;
  226. int s2=00;
  227. int s3=11;
  228. }
  229. else if(a2>a3>a4>a1)
  230. {
  231. int s1=01;
  232. int s2=10;
  233. int s3=11;
  234. }
  235. else if(a2>a3>a1>a4)
  236. {
  237. int s1=01;
  238. int s2=10;
  239. int s3=00;
  240. }
  241. else if(a2>a4>a3>a1)
  242. {
  243. int s1=01;
  244. int s2=11;
  245. int s3=10;
  246. }
  247. else if(a2>a4>a1>a3)
  248. {
  249. int s1=01;
  250. int s2=11;
  251. int s3=00;
  252. }
  253. else if(a3>a1>a2>a4)
  254. {
  255. int s1=10;
  256. int s2=00;
  257. int s3=01;
  258. }
  259. else if(a3>a1>a4>a2)
  260. {
  261. int s1=10;
  262. int s2=00;
  263. int s3=11;
  264. }
  265. else if(a3>a2>a1>a4)
  266. {
  267. int s1=10;
  268. int s2=01;
  269. int s3=00;
  270. }
  271. else if(a3>a2>a4>a1)
  272. {
  273. int s1=10;
  274. int s2=01;
  275. int s3=11;
  276. }
  277. else if(a3>a4>a2>a1)
  278. {
  279. int s1=10;
  280. int s2=11;
  281. int s3=01;
  282. }
  283. else if(a3>a4>a1>a2)
  284. {
  285. int s1=10;
  286. int s2=11;
  287. int s3=00;
  288. }
  289. else if(a4>a3>a2>a1)
  290. {
  291. int s1=11;
  292. int s2=10;
  293. int s3=01;
  294. }
  295. else if(a4>a3>a1>a2)
  296. {
  297. int s1=11;
  298. int s2=10;
  299. int s3=00;
  300. }
  301. else if(a4>a2>a3>a1)
  302. {
  303. int s1=11;
  304. int s2=01;
  305. int s3=10;
  306. }
  307. else if(a4>a2>a1>a3)
  308. {
  309. int s1=11;
  310. int s2=01;
  311. int s3=00;
  312. }
  313. else if(a4>a1>a2>a3)
  314. {
  315. int s1=11;
  316. int s2=00;
  317. int s3=01;
  318. }
  319. else if(a4>a1>a3>a2)
  320. {
  321. int s1=11;
  322. int s2=00;
  323. int s3=10;
  324. }
  325. whilea(a==00&&a==01&&a==10&&b==00&&b==01&&b==10&&c==00&&c==01&&c==10)
  326. {
  327. if(13==HIGH){
  328. a=s1+a;
  329. if(13==HIGH){
  330. b=s1+b;
  331. if(13==HIGH){
  332. c=s1+c;
  333. }
  334. else if(14==HIGH){
  335. c=s2+c;
  336. }
  337. else if(15==HIGH){
  338. c=s3+c;
  339. }
  340. }
  341. else if(14==HIGH){
  342. b=s2=b;
  343. if(13==HIGH){
  344. c=s1+c;
  345. }
  346. else if(14==HIGH){
  347. c=s2+c;
  348. }
  349. else if(15==HIGH){
  350. c=s3+c;
  351. }
  352. }
  353. else if(15==HIGH){
  354. b=s3+b;
  355. if(13==HIGH){
  356. c=s1+c;
  357. }
  358. else if(14==HIGH){
  359. c=s2+c;
  360. }
  361. else if(15==HIGH){
  362. c=s3+c;
  363. }
  364. }
  365. }
  366. else if(14==HIGH){
  367. a=s2+a;
  368. if(13==HIGH){
  369. b=s1+b;
  370. if(13==HIGH){
  371. c=s1+c;
  372. }
  373. else if(14==HIGH){
  374. c=s2+c;}
  375. else if(15==HIGH){
  376. c=s3+c;}
  377. }
  378. else if(14==HIGH){
  379. b=s2+b;
  380. if(13==HIGH){
  381. c=s1+c;
  382. }
  383. else if(14==HIGH){
  384. c=s2+c;}
  385. else if(15==HIGH){
  386. c=s3+c;}
  387. }
  388. else if(15==HIGH){
  389. b=s3+b;
  390. if(13==HIGH){
  391. c=s1+c;
  392. }
  393. else if(14==HIGH){
  394. c=s2+c;}
  395. else if(15==HIGH){
  396. c=s3+c;}
  397. }
  398. }
  399. else if(15==HIGH){
  400. a=s3+a;
  401. if(13==HIGH){
  402. b=s1+b;
  403. if(13==HIGH){
  404. c=s1+c;
  405. }
  406. else if(14==HIGH){
  407. c=s2+c;}
  408. else if(15==HIGH){
  409. c=s3+c;}
  410. }
  411. else if(14==HIGH){
  412. b=s2+b;
  413. if(13==HIGH){
  414. c=s1+c;
  415. }
  416. else if(14==HIGH){
  417. c=s2+c;}
  418. else if(15==HIGH){
  419. c=s3+c;}
  420. }
  421. else if(15==HIGH){
  422. b=s3+b;
  423. if(13==HIGH){
  424. c=s1+c;
  425. }
  426. else if(14==HIGH){
  427. c=s2+c;}
  428. else if(15==HIGH){
  429. c=s3+c;}
  430. }
  431. }
  432. }
  433. if(a=11&&b=11&&c=11)
  434. {
  435. digitalWrite(16,LOW);
  436. }
  437. else
  438. {
  439. digitalWrite(16,HIGH);
  440. }


  441. delay(10000);
  442. }
复制代码
校验报错如下:



sketch_aug13a:0: error: expected unqualified-id before '/' token
sketch_aug13a:0: error: expected constructor, destructor, or type conversion before '/' token
sketch_aug13a.cpp: In function 'void loop()':
sketch_aug13a:328: error: ISO C++ forbids comparison between pointer and integer
sketch_aug13a:328: error: ISO C++ forbids comparison between pointer and integer
sketch_aug13a:328: error: 'b' was not declared in this scope
sketch_aug13a:328: error: 'c' was not declared in this scope
sketch_aug13a:328: error: 'whilea' was not declared in this scope
sketch_aug13a:329: error: expected `;' before '{' token
sketch_aug13a:447: error: expected `}' at end of input

百思不得其解的是就连自己怎么错都不知道····
回复

使用道具 举报

发表于 2013-8-13 19:57:51 | 显示全部楼层
錯誤訊息:
1. 一開始的註解寫反了,應該是 /*...*/
2. 第329行寫成whilea
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-8-13 20:35:13 | 显示全部楼层
Be1ieve 发表于 2013-8-13 19:57
錯誤訊息:
1. 一開始的註解寫反了,應該是 /*...*/
2. 第329行寫成whilea

这个我复制代码的时候忘了删了 =。=
329行那里真的不知道怎么改··· 查了好多资料都看的不明不白的··
回复 支持 反对

使用道具 举报

发表于 2013-8-13 20:53:53 | 显示全部楼层
嗯...329是while()不是whilea()
而且這個根本不會滿足吧

然後上面那一串數字是怎麼回事...
可以講解一下你想要做什麼嗎
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-8-13 22:16:44 | 显示全部楼层
Be1ieve 发表于 2013-8-13 20:53
嗯...329是while()不是whilea()
而且這個根本不會滿足吧

我想做一个密室解谜时开门前的小谜题··· 这里有6个双色LED(红绿),3个轻触开关和1个电磁继电器。只有通过按动不同的轻触开关把6个LED全部转化成绿色之后电磁继电器将会吸合9秒,接通电子锁的电路。与此同时,必须把找到的门禁卡插在合适的位置·· 不然就重新做题···  
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-9 06:43 , Processed in 0.037892 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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