SHARE
TWEET

4x4x4 Charlieplexed LED Matrix Arduino Test Code

WhiteTea Sep 18th, 2013 35 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 output mode so they can light up the LEDs
  16.         pinMode(led0, OUTPUT);
  17.         pinMode(led1, OUTPUT);
  18.         pinMode(led2, OUTPUT);
  19.         pinMode(led3, OUTPUT);
  20.         pinMode(led4, OUTPUT);
  21.         pinMode(led5, OUTPUT);
  22.         pinMode(led6, OUTPUT);
  23.         pinMode(led7, OUTPUT);
  24.         off(); //ensure all the LEDs are off
  25. }
  26.  
  27.  
  28. void loop(){ //this method will be repeated once the setup is finished
  29.         splash1(); //we basicly keep calling this method
  30. }
  31.  
  32. void splash1(){
  33.         all();  //puts on all the LEDs for one second
  34.         a();    //puts on the first LED
  35.         b();    //puts on the second LED (turns first one off)
  36.         c();    //...
  37.         d();
  38.         e();
  39.         f();
  40.         g();
  41.         h();
  42.         i();
  43.         j();
  44.         k();
  45.         l();
  46.         m();
  47.         n();
  48.         o();
  49.         p();
  50.         off();  //turns all LEDs off
  51. }
  52.  
  53. void off(){
  54.         digitalWrite(led0, HIGH);
  55.         digitalWrite(led1, HIGH);
  56.         digitalWrite(led2, HIGH);
  57.         digitalWrite(led3, HIGH);
  58.  
  59.         digitalWrite(led4, LOW);
  60.         digitalWrite(led5, LOW);
  61.         digitalWrite(led6, LOW);
  62.         digitalWrite(led7, LOW);
  63.         delay (time);
  64. }
  65.  
  66. void a(){
  67.         digitalWrite(led0, LOW);
  68.         digitalWrite(led1, HIGH);
  69.         digitalWrite(led2, HIGH);
  70.         digitalWrite(led3, HIGH);
  71.  
  72.         digitalWrite(led4, HIGH);
  73.         digitalWrite(led5, LOW);
  74.         digitalWrite(led6, LOW);
  75.         digitalWrite(led7, LOW);
  76.         delay (time);
  77. }
  78.  
  79. void b(){
  80.         digitalWrite(led0, HIGH);
  81.         digitalWrite(led1, LOW);
  82.         digitalWrite(led2, HIGH);
  83.         digitalWrite(led3, HIGH);
  84.  
  85.         digitalWrite(led4, HIGH);
  86.         digitalWrite(led5, LOW);
  87.         digitalWrite(led6, LOW);
  88.         digitalWrite(led7, LOW);
  89.         delay (time);
  90. }
  91.  
  92. void c(){
  93.         digitalWrite(led0, HIGH);
  94.         digitalWrite(led1, HIGH);
  95.         digitalWrite(led2, LOW);
  96.         digitalWrite(led3, HIGH);
  97.  
  98.         digitalWrite(led4, HIGH);
  99.         digitalWrite(led5, LOW);
  100.         digitalWrite(led6, LOW);
  101.         digitalWrite(led7, LOW);
  102.         delay (time);
  103. }
  104.  
  105. void d(){
  106.         digitalWrite(led0, HIGH);
  107.         digitalWrite(led1, HIGH);
  108.         digitalWrite(led2, HIGH);
  109.         digitalWrite(led3, LOW);
  110.  
  111.         digitalWrite(led4, HIGH);
  112.         digitalWrite(led5, LOW);
  113.         digitalWrite(led6, LOW);
  114.         digitalWrite(led7, LOW);
  115.         delay (time);
  116. }
  117.  
  118. void e(){
  119.         digitalWrite(led0, LOW);
  120.         digitalWrite(led1, HIGH);
  121.         digitalWrite(led2, HIGH);
  122.         digitalWrite(led3, HIGH);
  123.  
  124.         digitalWrite(led4, LOW);
  125.         digitalWrite(led5, HIGH);
  126.         digitalWrite(led6, LOW);
  127.         digitalWrite(led7, LOW);
  128.         delay (time);
  129. }
  130.  
  131. void f(){
  132.         digitalWrite(led0, HIGH);
  133.         digitalWrite(led1, LOW);
  134.         digitalWrite(led2, HIGH);
  135.         digitalWrite(led3, HIGH);
  136.  
  137.         digitalWrite(led4, LOW);
  138.         digitalWrite(led5, HIGH);
  139.         digitalWrite(led6, LOW);
  140.         digitalWrite(led7, LOW);
  141.         delay (time);
  142. }
  143.  
  144. void g(){
  145.         digitalWrite(led0, HIGH);
  146.         digitalWrite(led1, HIGH);
  147.         digitalWrite(led2, LOW);
  148.         digitalWrite(led3, HIGH);
  149.  
  150.         digitalWrite(led4, LOW);
  151.         digitalWrite(led5, HIGH);
  152.         digitalWrite(led6, LOW);
  153.         digitalWrite(led7, LOW);
  154.         delay (time);
  155. }
  156.  
  157. void h(){
  158.         digitalWrite(led0, HIGH);
  159.         digitalWrite(led1, HIGH);
  160.         digitalWrite(led2, HIGH);
  161.         digitalWrite(led3, LOW);
  162.  
  163.         digitalWrite(led4, LOW);
  164.         digitalWrite(led5, HIGH);
  165.         digitalWrite(led6, LOW);
  166.         digitalWrite(led7, LOW);
  167.         delay (time);
  168. }
  169.  
  170. void i(){
  171.         digitalWrite(led0, LOW);
  172.         digitalWrite(led1, HIGH);
  173.         digitalWrite(led2, HIGH);
  174.         digitalWrite(led3, HIGH);
  175.  
  176.         digitalWrite(led4, LOW);
  177.         digitalWrite(led5, LOW);
  178.         digitalWrite(led6, HIGH);
  179.         digitalWrite(led7, LOW);
  180.         delay (time);
  181. }
  182.  
  183. void j(){
  184.         digitalWrite(led0, HIGH);
  185.         digitalWrite(led1, LOW);
  186.         digitalWrite(led2, HIGH);
  187.         digitalWrite(led3, HIGH);
  188.  
  189.         digitalWrite(led4, LOW);
  190.         digitalWrite(led5, LOW);
  191.         digitalWrite(led6, HIGH);
  192.         digitalWrite(led7, LOW);
  193.         delay (time);
  194. }
  195.  
  196. void k(){
  197.         digitalWrite(led0, HIGH);
  198.         digitalWrite(led1, HIGH);
  199.         digitalWrite(led2, LOW);
  200.         digitalWrite(led3, HIGH);
  201.  
  202.         digitalWrite(led4, LOW);
  203.         digitalWrite(led5, LOW);
  204.         digitalWrite(led6, HIGH);
  205.         digitalWrite(led7, LOW);
  206.         delay (time);
  207. }
  208.  
  209. void l(){
  210.         digitalWrite(led0, HIGH);
  211.         digitalWrite(led1, HIGH);
  212.         digitalWrite(led2, HIGH);
  213.         digitalWrite(led3, LOW);
  214.  
  215.         digitalWrite(led4, LOW);
  216.         digitalWrite(led5, LOW);
  217.         digitalWrite(led6, HIGH);
  218.         digitalWrite(led7, LOW);
  219.         delay (time);
  220. }
  221.  
  222. void m(){
  223.         digitalWrite(led0, LOW);
  224.         digitalWrite(led1, HIGH);
  225.         digitalWrite(led2, HIGH);
  226.         digitalWrite(led3, HIGH);
  227.  
  228.         digitalWrite(led4, LOW);
  229.         digitalWrite(led5, LOW);
  230.         digitalWrite(led6, LOW);
  231.         digitalWrite(led7, HIGH);
  232.         delay (time);
  233. }
  234.  
  235. void n(){
  236.         digitalWrite(led0, HIGH);
  237.         digitalWrite(led1, LOW);
  238.         digitalWrite(led2, HIGH);
  239.         digitalWrite(led3, HIGH);
  240.  
  241.         digitalWrite(led4, LOW);
  242.         digitalWrite(led5, LOW);
  243.         digitalWrite(led6, LOW);
  244.         digitalWrite(led7, HIGH);
  245.         delay (time);
  246. }
  247.  
  248. void o(){
  249.         digitalWrite(led0, HIGH);
  250.         digitalWrite(led1, HIGH);
  251.         digitalWrite(led2, LOW);
  252.         digitalWrite(led3, HIGH);
  253.  
  254.         digitalWrite(led4, LOW);
  255.         digitalWrite(led5, LOW);
  256.         digitalWrite(led6, LOW);
  257.         digitalWrite(led7, HIGH);
  258.         delay (time);
  259. }
  260.  
  261. void p(){
  262.         digitalWrite(led0, HIGH);
  263.         digitalWrite(led1, HIGH);
  264.         digitalWrite(led2, HIGH);
  265.         digitalWrite(led3, LOW);
  266.  
  267.         digitalWrite(led4, LOW);
  268.         digitalWrite(led5, LOW);
  269.         digitalWrite(led6, LOW);
  270.         digitalWrite(led7, HIGH);
  271.         delay (time);
  272. }
  273.  
  274. void all(){
  275.         digitalWrite(led0, LOW);
  276.         digitalWrite(led1, LOW);
  277.         digitalWrite(led2, LOW);
  278.         digitalWrite(led3, LOW);
  279.  
  280.         digitalWrite(led4, HIGH);
  281.         digitalWrite(led5, HIGH);
  282.         digitalWrite(led6, HIGH);
  283.         digitalWrite(led7, HIGH);
  284.         delay (1000);
  285. }
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