SHARE
TWEET

4x4x2 Charlieplexed Arduino LED Cube Test

WhiteTea Sep 18th, 2013 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //initialize the port numbers. You can easily change them here if you connected your LEDs in another way than I suggested
  2. int led0 = 0;
  3. int led1 = 1;
  4. int led2 = 2;
  5. int led3 = 3;
  6. int led4 = 4;
  7. int led5 = 5;
  8. int led6 = 6;
  9. int led7 = 7;
  10.  
  11. //the time we will wait after lighting one LED (in ms)
  12. int time = 500;
  13.  
  14. void setup(){ //this method will be run once after powering up the arduino
  15.         //put all the pins in input mode so we can use the charlieplexing technique
  16.         //depending on which pins we put on OUTPUT and HIGH/LOW another LED will light up
  17.         pinMode(led0, INPUT);
  18.         pinMode(led1, INPUT);
  19.         pinMode(led2, INPUT);
  20.         pinMode(led3, INPUT);
  21.         pinMode(led4, INPUT);
  22.         pinMode(led5, INPUT);
  23.         pinMode(led6, INPUT);
  24.         pinMode(led7, INPUT);
  25.         off(); //ensure all the LEDs are off
  26. }
  27.  
  28.  
  29. void loop(){ //this method will be repeated once the setup is finished
  30.         splash1(); //we basicly keep calling this method
  31. }
  32.  
  33. void splash1(){ //puts on all leds, then tests all leds one by one
  34.         test();
  35.         a1(); b1(); c1(); d1(); e1(); f1(); g1(); h1(); i1(); j1(); k1(); l1(); m1(); n1(); o1(); p1();
  36.         p2(); o2(); n2(); m2(); l2(); k2(); j2(); i2(); h2(); g2(); f2(); e2(); d2(); c2(); b2(); a2();
  37.         off();
  38.         delay (time);
  39. }
  40.  
  41. void off(){
  42.         pinMode(led0, INPUT);
  43.         pinMode(led1, INPUT);
  44.         pinMode(led2, INPUT);
  45.         pinMode(led3, INPUT);
  46.         pinMode(led4, INPUT);
  47.         pinMode(led5, INPUT);
  48.         pinMode(led6, INPUT);
  49.         pinMode(led7, INPUT);
  50. }
  51.  
  52. void a1(){
  53. pinMode(led0, OUTPUT);
  54. digitalWrite(led0, LOW);
  55. pinMode(led4, OUTPUT);
  56. digitalWrite(led4, HIGH);
  57. delay (time);
  58. off();
  59. }
  60.  
  61. void b1(){
  62. pinMode(led1, OUTPUT);
  63. digitalWrite(led1, LOW);
  64. pinMode(led4, OUTPUT);
  65. digitalWrite(led4, HIGH);
  66. delay (time);
  67. off();
  68. }
  69.  
  70. void c1(){
  71. pinMode(led2, OUTPUT);
  72. digitalWrite(led2, LOW);
  73. pinMode(led4, OUTPUT);
  74. digitalWrite(led4, HIGH);
  75. delay (time);
  76. off();
  77. }
  78.  
  79. void d1(){
  80. pinMode(led3, OUTPUT);
  81. digitalWrite(led3, LOW);
  82. pinMode(led4, OUTPUT);
  83. digitalWrite(led4, HIGH);
  84. delay (time);
  85. off();
  86. }
  87.  
  88. void e1(){
  89. pinMode(led0, OUTPUT);
  90. digitalWrite(led0, LOW);
  91. pinMode(led5, OUTPUT);
  92. digitalWrite(led5, HIGH);
  93. delay (time);
  94. off();
  95. }
  96.  
  97. void f1(){
  98. pinMode(led1, OUTPUT);
  99. digitalWrite(led1, LOW);
  100. pinMode(led5, OUTPUT);
  101. digitalWrite(led5, HIGH);
  102. delay (time);
  103. off();
  104. }
  105.  
  106. void g1(){
  107. pinMode(led2, OUTPUT);
  108. digitalWrite(led2, LOW);
  109. pinMode(led5, OUTPUT);
  110. digitalWrite(led5, HIGH);
  111. delay (time);
  112. off();
  113. }
  114.  
  115. void h1(){
  116. pinMode(led3, OUTPUT);
  117. digitalWrite(led3, LOW);
  118. pinMode(led5, OUTPUT);
  119. digitalWrite(led5, HIGH);
  120. delay (time);
  121. off();
  122. }
  123.  
  124. void i1(){
  125. pinMode(led0, OUTPUT);
  126. digitalWrite(led0, LOW);
  127. pinMode(led6, OUTPUT);
  128. digitalWrite(led6, HIGH);
  129. delay (time);
  130. off();
  131. }
  132.  
  133. void j1(){
  134. pinMode(led1, OUTPUT);
  135. digitalWrite(led1, LOW);
  136. pinMode(led6, OUTPUT);
  137. digitalWrite(led6, HIGH);
  138. delay (time);
  139. off();
  140. }
  141.  
  142. void k1(){
  143. pinMode(led2, OUTPUT);
  144. digitalWrite(led2, LOW);
  145. pinMode(led6, OUTPUT);
  146. digitalWrite(led6, HIGH);
  147. delay (time);
  148. off();
  149. }
  150.  
  151. void l1(){
  152. pinMode(led3, OUTPUT);
  153. digitalWrite(led3, LOW);
  154. pinMode(led6, OUTPUT);
  155. digitalWrite(led6, HIGH);
  156. delay (time);
  157. off();
  158. }
  159.  
  160. void m1(){
  161. pinMode(led0, OUTPUT);
  162. digitalWrite(led0, LOW);
  163. pinMode(led7, OUTPUT);
  164. digitalWrite(led7, HIGH);
  165. delay (time);
  166. off();
  167. }
  168.  
  169. void n1(){
  170. pinMode(led1, OUTPUT);
  171. digitalWrite(led1, LOW);
  172. pinMode(led7, OUTPUT);
  173. digitalWrite(led7, HIGH);
  174. delay (time);
  175. off();
  176. }
  177.  
  178. void o1(){
  179. pinMode(led2, OUTPUT);
  180. digitalWrite(led2, LOW);
  181. pinMode(led7, OUTPUT);
  182. digitalWrite(led7, HIGH);
  183. delay (time);
  184. off();
  185. }
  186.  
  187. void p1(){
  188. pinMode(led3, OUTPUT);
  189. digitalWrite(led3, LOW);
  190. pinMode(led7, OUTPUT);
  191. digitalWrite(led7, HIGH);
  192. delay (time);
  193. off();
  194. }
  195.  
  196. void a2(){
  197. pinMode(led0, OUTPUT);
  198. digitalWrite(led0, HIGH);
  199. pinMode(led4, OUTPUT);
  200. digitalWrite(led4, LOW);
  201. delay (time);
  202. off();
  203. }
  204.  
  205. void b2(){
  206. pinMode(led1, OUTPUT);
  207. digitalWrite(led1, HIGH);
  208. pinMode(led4, OUTPUT);
  209. digitalWrite(led4, LOW);
  210. delay (time);
  211. off();
  212. }
  213.  
  214. void c2(){
  215. pinMode(led2, OUTPUT);
  216. digitalWrite(led2, HIGH);
  217. pinMode(led4, OUTPUT);
  218. digitalWrite(led4, LOW);
  219. delay (time);
  220. off();
  221. }
  222.  
  223. void d2(){
  224. pinMode(led3, OUTPUT);
  225. digitalWrite(led3, HIGH);
  226. pinMode(led4, OUTPUT);
  227. digitalWrite(led4, LOW);
  228. delay (time);
  229. off();
  230. }
  231.  
  232. void e2(){
  233. pinMode(led0, OUTPUT);
  234. digitalWrite(led0, HIGH);
  235. pinMode(led5, OUTPUT);
  236. digitalWrite(led5, LOW);
  237. delay (time);
  238. off();
  239. }
  240.  
  241. void f2(){
  242. pinMode(led1, OUTPUT);
  243. digitalWrite(led1, HIGH);
  244. pinMode(led5, OUTPUT);
  245. digitalWrite(led5, LOW);
  246. delay (time);
  247. off();
  248. }
  249.  
  250. void g2(){
  251. pinMode(led2, OUTPUT);
  252. digitalWrite(led2, HIGH);
  253. pinMode(led5, OUTPUT);
  254. digitalWrite(led5, LOW);
  255. delay (time);
  256. off();
  257. }
  258.  
  259. void h2(){
  260. pinMode(led3, OUTPUT);
  261. digitalWrite(led3, HIGH);
  262. pinMode(led5, OUTPUT);
  263. digitalWrite(led5, LOW);
  264. delay (time);
  265. off();
  266. }
  267.  
  268. void i2(){
  269. pinMode(led0, OUTPUT);
  270. digitalWrite(led0, HIGH);
  271. pinMode(led6, OUTPUT);
  272. digitalWrite(led6, LOW);
  273. delay (time);
  274. off();
  275. }
  276.  
  277. void j2(){
  278. pinMode(led1, OUTPUT);
  279. digitalWrite(led1, HIGH);
  280. pinMode(led6, OUTPUT);
  281. digitalWrite(led6, LOW);
  282. delay (time);
  283. off();
  284. }
  285.  
  286. void k2(){
  287. pinMode(led2, OUTPUT);
  288. digitalWrite(led2, HIGH);
  289. pinMode(led6, OUTPUT);
  290. digitalWrite(led6, LOW);
  291. delay (time);
  292. off();
  293. }
  294.  
  295. void l2(){
  296. pinMode(led3, OUTPUT);
  297. digitalWrite(led3, HIGH);
  298. pinMode(led6, OUTPUT);
  299. digitalWrite(led6, LOW);
  300. delay (time);
  301. off();
  302. }
  303.  
  304. void m2(){
  305. pinMode(led0, OUTPUT);
  306. digitalWrite(led0, HIGH);
  307. pinMode(led7, OUTPUT);
  308. digitalWrite(led7, LOW);
  309. delay (time);
  310. off();
  311. }
  312.  
  313. void n2(){
  314. pinMode(led1, OUTPUT);
  315. digitalWrite(led1, HIGH);
  316. pinMode(led7, OUTPUT);
  317. digitalWrite(led7, LOW);
  318. delay (time);
  319. off();
  320. }
  321.  
  322. void o2(){
  323. pinMode(led2, OUTPUT);
  324. digitalWrite(led2, HIGH);
  325. pinMode(led7, OUTPUT);
  326. digitalWrite(led7, LOW);
  327. delay (time);
  328. off();
  329. }
  330.  
  331. void p2(){
  332. pinMode(led3, OUTPUT);
  333. digitalWrite(led3, HIGH);
  334. pinMode(led7, OUTPUT);
  335. digitalWrite(led7, LOW);
  336. delay (time);
  337. off();
  338. }
  339.  
  340.  
  341. void test(){
  342. pinMode(led0, OUTPUT);
  343. pinMode(led1, OUTPUT);
  344. pinMode(led2, OUTPUT);
  345. pinMode(led3, OUTPUT);
  346. pinMode(led4, OUTPUT);
  347. pinMode(led5, OUTPUT);
  348. pinMode(led6, OUTPUT);
  349. pinMode(led7, OUTPUT);
  350. digitalWrite(led0, LOW);
  351. digitalWrite(led1, LOW);
  352. digitalWrite(led2, LOW);
  353. digitalWrite(led3, LOW);
  354.  
  355. digitalWrite(led4, HIGH);
  356. digitalWrite(led5, HIGH);
  357. digitalWrite(led6, HIGH);
  358. digitalWrite(led7, HIGH);
  359. delay (1000);
  360. digitalWrite(led0, HIGH);
  361. digitalWrite(led1, HIGH);
  362. digitalWrite(led2, HIGH);
  363. digitalWrite(led3, HIGH);
  364.  
  365. digitalWrite(led4, LOW);
  366. digitalWrite(led5, LOW);
  367. digitalWrite(led6, LOW);
  368. digitalWrite(led7, LOW);
  369. delay (1000);
  370. off();
  371. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top