Advertisement
Guest User

the code

a guest
Mar 30th, 2013
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None
  1. // todo timeout and pwm dimming
  2. //Recive varibles
  3.  
  4. byte Byte = 0;
  5. int nummer = 0;
  6. int Prijs[4] = {0,0,0,0};
  7. int i = 0;
  8. boolean reset = false;
  9. boolean toon = false;
  10. boolean reoutput = true;
  11. boolean easter = true;
  12.  
  13. // Show variables
  14. int old[4] = {0,0,0,0};
  15. int latch1 = 2;
  16. int latch2 = 3;
  17. int pwmpin = 6;
  18. int value = 255;
  19. int timeout = 0;
  20.  
  21.  
  22. // the output
  23.  
  24.  
  25.  
  26.  
  27. void setup(){
  28.  
  29. Serial.begin(9600);
  30.  
  31. pinMode(latch1,OUTPUT);
  32. pinMode(latch2,OUTPUT);
  33.  
  34. Serial.println ("insert your numbers:");
  35. analogWrite(pwmpin,255);
  36. }
  37.  
  38. void loop(){
  39. recive();
  40. show();
  41.  
  42. }
  43.  
  44.  
  45.  
  46. // the main display method
  47.  
  48. void show()
  49. {
  50.  
  51. if( old[0] != Prijs[0])
  52. {
  53. old[0] = Prijs[0];
  54. timeout = 0;
  55. value = 255;
  56.  
  57. }
  58. if( old[1] != Prijs[1])
  59. {
  60. old[1] = Prijs[1];
  61. timeout = 0;
  62. value = 255;
  63.  
  64. }
  65. if( old[2] != Prijs[2])
  66. {
  67. old[2] = Prijs[2];
  68. timeout = 0;
  69. value = 255;
  70.  
  71. }
  72. if( old[3] != Prijs[3])
  73. {
  74. old[3] = Prijs[3];
  75. timeout = 0;
  76. value = 255;
  77.  
  78. } if (timeout = 10){fade();}
  79. }
  80.  
  81. void fade(){
  82.  
  83. if (value > 0){analogWrite (pwmpin,value);
  84. value = value -10;
  85.  
  86.  
  87.  
  88. }
  89. }
  90.  
  91. //the main recive method
  92. void recive(){ if(Serial.available() ==1){
  93.  
  94. Byte = Serial.read ();
  95.  
  96. if (Byte == 13){
  97.  
  98. switch(reset){
  99.  
  100. case false:
  101.  
  102. Serial.println(""); Serial.println("het ingegeven nummer is:");
  103. int a;
  104. Serial.print(Prijs[0]); Serial.print(Prijs[1]); Serial.print(Prijs[2]); Serial.print(Prijs[3]);
  105. Serial.println("");
  106.  
  107. Serial.println ("Press enter to reset or ? for variables");
  108. reoutput = false;
  109. reset = true;
  110. break;
  111.  
  112. case true:
  113. inputreset();
  114. break;
  115. }}
  116.  
  117. else { if (reoutput == true){Serial.print(convert1(Byte)); } //convert and show inputted numbers
  118.  
  119. Prijs[i] = (convert1(Byte)) ;
  120.  
  121. i++;}
  122. }
  123. if ( Byte == 63){ if (toon == false){Serial.println("");
  124. Serial.println("┌-------------------------------------┐");
  125. Serial.print("| old1: ");Serial.print(old[0]);
  126. Serial.print("| old2: ");Serial.print(old[1]);
  127. Serial.print(" | old3: ");Serial.print(old[2]);
  128. Serial.print("| old4: ");Serial.print(old[3]);
  129. Serial.print(" |");
  130. Serial.println("");
  131. Serial.print("| toon: ");Serial.print(toon);
  132. Serial.print("| reset: ");Serial.print(reset);
  133. Serial.print("| reoutput: ");Serial.print(reoutput);
  134. Serial.print(" |");
  135. Serial.println("");
  136. Serial.println("└-------------------------------------┘");
  137. Serial.println(" ");
  138. Serial.println("Press enter to reset");
  139. }
  140. toon = true; }
  141.  
  142. if( Byte == 33){ if(easter == true){if (Prijs[0]==0 and Prijs[1] == 0 and Prijs[2] == 0 and Prijs[3] ==0){
  143. Serial.println("");
  144. Serial.println(" ||||||||||||||||||||||");
  145. Serial.println(" |||| ||||| ||||||");
  146. Serial.println(" |||||||||| |||| ||||||");
  147. Serial.println(" |||||||||| |||| ||||||");
  148. Serial.println(" ||||||||| ||||| ||||||");
  149. Serial.println(" ||||||| ||||||| ||||||");
  150. Serial.println(" ||||||| ||||||| ||||||");
  151. Serial.println(" ||||||| ||||||| ||||||");
  152. Serial.println(" ||||||||||||||||||||||");
  153. Serial.println(" ||||||||||||||||||||||");
  154. Serial.println(" ||||||| ||||||| ||||||");
  155. Serial.println(" ||||||||||||||||||||||");
  156.  
  157. }
  158.  
  159. else {
  160.  
  161. Serial.println(" -------------------");
  162. Serial.print(" |");Serial.print("The Numbers: ");Serial.print(Prijs[0]); Serial.print(Prijs[1]); Serial.print(Prijs[2]); Serial.print(Prijs[3]);Serial.println("|");
  163. Serial.println(" -------------------");
  164.  
  165.  
  166. }
  167. Serial.println(" ( ( ( o");
  168. Serial.println("/---\\:::/---\\ o");
  169. Serial.println("| 0 | | 0 | o");
  170. Serial.println("\\---/:::\\---/");
  171. Serial.println(" | / \\ |");
  172. Serial.println(" \\ \\ / /");
  173. Serial.println(" | \\| |/ |");
  174. Serial.println(" \\ \\ / /");
  175. Serial.println(" |---|");
  176. Serial.println(" | |");
  177. Serial.println(" /|\\ /|\\");
  178.  
  179. Serial.println("");
  180.  
  181.  
  182. Serial.println("Press enter to reset");
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190. } easter = false;}
  191.  
  192.  
  193.  
  194. }
  195.  
  196.  
  197. void nixiereset(){
  198.  
  199. old[0] = 0;
  200. old[1] = 0;
  201. old[2] = 0;
  202. old[3] = 0;
  203.  
  204. value = 0;
  205. timeout =0;
  206.  
  207. digitalWrite(latch2,LOW);
  208. digitalWrite(latch1,LOW);
  209.  
  210. }
  211.  
  212. void inputreset(){
  213. Byte = 0;
  214. nummer = 0;
  215. Prijs[0] = 0;
  216. Prijs[1] = 0;
  217. Prijs[2] = 0;
  218. Prijs[3] = 0;
  219. i = 0;
  220. reset = 0;
  221. reoutput = true;
  222. toon = false;
  223. easter = true;
  224. Serial.println("gereset");
  225. delay(100);
  226. Serial.println ("insert your numbers:");
  227. }
  228.  
  229.  
  230. int convert1 (int Byte) {
  231.  
  232. switch(Byte){
  233.  
  234. case 48:
  235. nummer = 0;
  236. break;
  237.  
  238. case 49:
  239. nummer = 1;
  240. break;
  241.  
  242. case 50:
  243. nummer = 2;
  244. break;
  245.  
  246. case 51:
  247. nummer = 3;
  248. break;
  249.  
  250. case 52:
  251. nummer = 4;
  252. break;
  253.  
  254. case 53:
  255. nummer = 5;
  256. break;
  257.  
  258. case 54:
  259. nummer = 6;
  260. break;
  261.  
  262. case 55:
  263. nummer = 7;
  264. break;
  265.  
  266. case 56:
  267. nummer = 8;
  268. break;
  269.  
  270. case 57:
  271. nummer =9 ;
  272. break;
  273. }return nummer;
  274. }
  275.  
  276. byte convert2 (int nummer) {
  277.  
  278.  
  279.  
  280. switch(nummer){
  281.  
  282. case 0:
  283. PORTB = B00000000;
  284. break;
  285.  
  286. case 1:
  287. PORTB = B00000100; // pin 8
  288. break;
  289.  
  290. case 2:
  291. PORTB = B00001000; // pin 9
  292. break;
  293.  
  294. case 3:
  295. PORTB = B00001100; // pin 8 en 9
  296. break;
  297.  
  298. case 4:
  299. PORTB = B00010000; // pin 10
  300. break;
  301.  
  302. case 5:
  303. PORTB = B00010100; // pin 8 en 10
  304. break;
  305.  
  306. case 6:
  307. PORTB = B00011000; // pin 9 en 10
  308.  
  309. break;
  310. case 7:
  311. PORTB = B00011100; // pin 8,9 en 10
  312. break;
  313.  
  314. case 8:
  315. PORTB = B00100000; // pin 11
  316. break;
  317.  
  318. case 9:
  319. PORTB = B00100100; // pin 8 en 11
  320. break;
  321. }
  322. }
Advertisement
RAW Paste Data Copied
Advertisement