Advertisement
Guest User

nixies

a guest
Mar 30th, 2013
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None
  1. int Aa = 2;
  2. int Ba = 3;
  3. int Ca = 4;
  4. int Da = 5;
  5. int Ab = 6;
  6. int Bb = 7;
  7. int Cb = 8;
  8. int Db = 9;
  9. int Ac = 10;
  10. int Bc = 11;
  11. int Cc = 12;
  12. int Dc = 13;
  13. int Ad = 14;
  14. int Bd = 15;
  15. int Cd = 16;
  16. int Dd = 17;
  17. int cash = 18;
  18. int pwm = 19;
  19. int numers[]= {0,0,0,0}; // remembering last 4 numbers
  20. int i = 0;
  21. byte Byte = 0;
  22. boolean debug = true;
  23.  
  24.  
  25. boolean show =true;
  26. boolean reoutput = true;
  27. boolean reseting = false;
  28.  
  29. void setup(){
  30.  
  31. pinMode(Aa,OUTPUT);
  32. pinMode(Ba,OUTPUT);
  33. pinMode(Ca,OUTPUT);
  34. pinMode(Da,OUTPUT);
  35. pinMode(Ab,OUTPUT);
  36. pinMode(Bb,OUTPUT);
  37. pinMode(Cb,OUTPUT);
  38. pinMode(Db,OUTPUT);
  39. pinMode(Dc,OUTPUT);
  40. pinMode(Ac,OUTPUT);
  41. pinMode(Bc,OUTPUT);
  42. pinMode(Cc,OUTPUT);
  43. pinMode(Dc,OUTPUT);
  44. pinMode(Ad,OUTPUT);
  45. pinMode(Bd,OUTPUT);
  46. pinMode(Cd,OUTPUT);
  47. pinMode(Dd,OUTPUT);
  48. pinMode(cash,OUTPUT);
  49. pinMode(pwm,OUTPUT);
  50. Serial.begin(9600);
  51.  
  52. Serial.println("starting up");
  53. delay (25);
  54. tests(1);
  55. reset(5,0);
  56. }
  57.  
  58. void loop (){
  59.  
  60. recive();
  61. convert(numers[0],1);
  62. convert(numers[1],2);
  63. convert(numers[2],3);
  64. convert(numers[3],4);
  65.  
  66. }
  67. void inputreset(){
  68. Byte = 0;
  69. numers[0] = 0;
  70. numers[1] = 0;
  71. numers[2] = 0;
  72. numers[3] = 0;
  73. i = 0;
  74. }
  75. void recive(){ if(Serial.available() ==1){
  76.  
  77. Byte = Serial.read ();}
  78.  
  79. if (Byte == 13){
  80.  
  81. switch(reseting){
  82.  
  83. case false:
  84.  
  85. if (debug ==true){ Serial.println(""); Serial.println("het ingegeven nummer is:");}
  86. int a;
  87. if (debug ==true){
  88.  
  89. Serial.print(numers[0]); Serial.print(numers[1]); Serial.print(numers[2]); Serial.print(numers[3]);
  90. Serial.println("");
  91. Serial.println ("Press enter to reset or ? for variables");
  92. }
  93.  
  94. reoutput = true;
  95. reseting = true;
  96. break;
  97.  
  98. case true:
  99. inputreset();
  100. break;
  101. }}
  102. else { if (reoutput == true){Serial.print(convert1(Byte)); } //show inputted numbers
  103. numers[i] = (convert1(Byte)) ;
  104. i++;}
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. int convert1 (int Byte) { //converting the inputted byte to something usable
  113.  
  114. int nummer = 0;
  115.  
  116. switch(Byte){
  117.  
  118. case 48:
  119. nummer = 0;
  120. break;
  121.  
  122. case 49:
  123. nummer = 1;
  124. break;
  125.  
  126. case 50:
  127. nummer = 2;
  128. break;
  129.  
  130. case 51:
  131. nummer = 3;
  132. break;
  133.  
  134. case 52:
  135. nummer = 4;
  136. break;
  137.  
  138. case 53:
  139. nummer = 5;
  140. break;
  141.  
  142. case 54:
  143. nummer = 6;
  144. break;
  145.  
  146. case 55:
  147. nummer = 7;
  148. break;
  149.  
  150. case 56:
  151. nummer = 8;
  152. break;
  153.  
  154. case 57:
  155. nummer =9 ;
  156. break;
  157. }return nummer;
  158. }
  159.  
  160. void demo (){for(int i =1; i<6;i++){tests(i);}}
  161.  
  162.  
  163. void tests(int test){ //just some fancy test routine for showing the cababilities of the display
  164.  
  165. reset(5,1);
  166. i=0;
  167. if (test == 1){ // count to 9 while scrolling the display to left with blanks
  168. while(i < 11){
  169.  
  170. convert(i,1);
  171. delay(70);
  172. reset(1,1);
  173.  
  174. convert(i,2);
  175. delay(70);
  176. reset(2,1);
  177.  
  178. convert(i,3);
  179. delay(70);
  180. reset(3,1);
  181.  
  182. convert(i,4);
  183. delay(250);
  184. reset(4,1);
  185. i++;
  186. }}
  187.  
  188. if (test == 2){ // count to 9 while scrolling the display to right with blanks
  189.  
  190. while (i < 11){
  191.  
  192. convert(i,4);
  193. delay(70);
  194. reset(4,1);
  195.  
  196. convert(i,3);
  197. delay(70);
  198. reset(3,1);
  199.  
  200. convert(i,2);
  201. delay(70);
  202. reset(2,1);
  203.  
  204. convert(i,1);
  205. delay(250);
  206. reset(1,1);
  207. i++;
  208.  
  209. }}
  210. if (test == 3){ // count to 9 while scrolling the display to left with blanks
  211. while(i < 11){
  212.  
  213. convert(i,1);
  214. delay(70);
  215. reset(1,0);
  216.  
  217. convert(i,2);
  218. delay(70);
  219. reset(2,0);
  220.  
  221. convert(i,3);
  222. delay(70);
  223. reset(3,0);
  224.  
  225. convert(i,4);
  226. delay(250);
  227. reset(4,0);
  228. i++;
  229. }}
  230.  
  231. if (test == 4){ // count to 9 while scrolling the display to right with blanks
  232.  
  233. while (i < 11){
  234.  
  235. convert(i,4);
  236. delay(70);
  237. reset(4,0);
  238.  
  239. convert(i,3);
  240. delay(70);
  241. reset(3,0);
  242.  
  243. convert(i,2);
  244. delay(70);
  245. reset(2,0);
  246.  
  247. convert(i,1);
  248. delay(250);
  249. reset(1,0);
  250. i++;
  251.  
  252. }}
  253.  
  254. if (test == 5){ // count to 9 while scrolling the display to left with blanks
  255. while(i < 11){
  256.  
  257. convert(i,2);
  258. delay(70);
  259. reset(1,1);
  260.  
  261. convert(i,3);
  262. delay(70);
  263. reset(2,1);
  264.  
  265. convert(i,1);
  266. delay(70);
  267. reset(3,1);
  268.  
  269. convert(i,4);
  270. delay(250);
  271. reset(4,1);
  272. i++;
  273. }}
  274.  
  275. }
  276.  
  277. void convert(int nummer,int digit){ //method for converting decimal numbers to thear coresponding bcd numbers and printing them
  278.  
  279. int A = 0;
  280. int B = 0;
  281. int C = 0;
  282. int D = 0; //local variables for temp storing the nibbles
  283.  
  284. reset(digit,1);
  285.  
  286. switch (nummer){ //the conversion statement
  287.  
  288. case 1:
  289. A = 1;
  290. break;
  291.  
  292. case 2:
  293. B = 1;
  294. break;
  295.  
  296. case 3:
  297. A = 1;
  298. B = 1;
  299. break;
  300.  
  301. case 4:
  302. C = 1;
  303. break;
  304.  
  305. case 5:
  306. A = 1;
  307. C = 1;
  308. break;
  309.  
  310. case 6:
  311. B = 1;
  312. C = 1;
  313. break;
  314.  
  315. case 7:
  316. A = 1;
  317. B = 1;
  318. C = 1;
  319. break;
  320.  
  321. case 8:
  322. D = 1;
  323. break;
  324.  
  325. case 9:
  326. A = 1;
  327. D = 1;
  328. break;
  329.  
  330. case 10:
  331. A = 1;
  332. B = 1;
  333. C = 1;
  334. D = 1;
  335. break;
  336. }
  337.  
  338. switch (digit){ // the printing
  339.  
  340. case 1:
  341. digitalWrite(Aa,A);
  342. digitalWrite(Ba,B);
  343. digitalWrite(Ca,C);
  344. digitalWrite(Da,D);
  345. break;
  346.  
  347. case 2:
  348. digitalWrite(Ab,A);
  349. digitalWrite(Bb,B);
  350. digitalWrite(Cb,C);
  351. digitalWrite(Db,D);
  352. break;
  353.  
  354. case 3:
  355. digitalWrite(Ac,A);
  356. digitalWrite(Bc,B);
  357. digitalWrite(Cc,C);
  358. digitalWrite(Dc,D);
  359. break;
  360.  
  361. case 4:
  362. digitalWrite(Ad,A);
  363. digitalWrite(Bd,B);
  364. digitalWrite(Cd,C);
  365. digitalWrite(Dd,D);
  366. break;
  367. }}
  368.  
  369.  
  370. void fancyreset(int mode){}
  371.  
  372. void reset(int digit,boolean state) {
  373.  
  374. switch (digit){
  375.  
  376. case 1:
  377.  
  378. digitalWrite(Aa,state);
  379. digitalWrite(Ba,state);
  380. digitalWrite(Ca,state);
  381. digitalWrite(Da,state);
  382. break;
  383.  
  384. case 2 :
  385.  
  386. digitalWrite(Ab,state);
  387. digitalWrite(Bb,state);
  388. digitalWrite(Cb,state);
  389. digitalWrite(Db,state);
  390. break;
  391.  
  392. case 3 :
  393.  
  394. digitalWrite(Ac,state);
  395. digitalWrite(Bc,state);
  396. digitalWrite(Cc,state);
  397. digitalWrite(Dc,state);
  398. break;
  399.  
  400. case 4 :
  401.  
  402. digitalWrite(Ad,state);
  403. digitalWrite(Bd,state);
  404. digitalWrite(Cd,state);
  405. digitalWrite(Dd,state);
  406. break;
  407.  
  408. default:
  409.  
  410. digitalWrite(Aa,state);
  411. digitalWrite(Ba,state);
  412. digitalWrite(Ca,state);
  413. digitalWrite(Da,state);
  414. digitalWrite(Ab,state);
  415. digitalWrite(Bb,state);
  416. digitalWrite(Cb,state);
  417. digitalWrite(Db,state);
  418. digitalWrite(Ac,state);
  419. digitalWrite(Bc,state);
  420. digitalWrite(Cc,state);
  421. digitalWrite(Dc,state);
  422. digitalWrite(Ad,state);
  423. digitalWrite(Bd,state);
  424. digitalWrite(Cd,state);
  425. digitalWrite(Dd,state);
  426. break;
  427. }}
Advertisement
RAW Paste Data Copied
Advertisement