Monday, April 01, 2013

Tricolor LED update: soldered up

I moved the led from breadboard to pc board, added a 9V to barrel plug and I have a nice little night light! I don't know how long the battery will last though...

Monday, March 25, 2013

Tricolor LED Project 3: Color mixing and Crossfades

This project just uses Arduino and the tricolor LED to make random mixed colors and crossfades. The LED is wired like in this diagram:  http://arduino.cc/en/uploads/Tutorial/readASCIIString_bb.png
Program code is below:




Program code:
int r,g,b;
int LEDs[] = {r,g,b};

int brightness = 3; 
int fadeAmount = 3; 
int pick1,pick2,pick3;
int PICKS[] = {pick1,pick2,pick3};

void setup()  { 
  for(int i = 0;i < 3;i++) {
    LEDs[i] = i+9;
    pinMode(LEDs[i],OUTPUT);
    PICKS[i] = random(3);
  }
  //Serial.begin(9600);
} 

void loop()  { 
  if(brightness == 3) {
    for(int i = 0;i < 3;i++) {
      PICKS[i] = random(3);
    }//end for
  }//endif
  for(int i = 0;i < 3;i++) {
      switch(PICKS[i]) {
      case 0:
        analogWrite(LEDs[i], brightness);
        break;
      case 1:
        analogWrite(LEDs[i], -brightness);
        break;
      case 2:
        analogWrite(LEDs[i], 255);
        break;
      }//end switch
  }//end for
  brightness += fadeAmount;
  if (brightness < 4 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
  }     
  delay(30);                            
}


Tricolor LED Project 2: Color Slider


Processing and Arduino project 2 uses a tricolor LED and a screen interface to mix colors with sliders. That's a ping pong ball on the LED. The LED is wired like in this diagram: http://arduino.cc/en/uploads/Tutorial/readASCIIString_bb.png. Remember when doing projects with Arduino thru Processing, follow these steps: http://playground.arduino.cc/interfacing/processing
The code is published below:




Main code:

//arduino begin
import processing.serial.*; //for serial communication with any device
import cc.arduino.*; //for Arduino library methods
Arduino arduino; //create Arduino object from library
int rd = 9; 
int blu = 10; 
int grn = 11; 
//arduino end
Circle circle;
Slider[] slider = new Slider[3];
int[] xpos = new int[3];
int[] ypos = new int[3];

void setup() {
  //arduino begin
  println(Arduino.list());//show me which COM port Arduino is using
  arduino = new Arduino(this, Arduino.list()[4], 57600);
  arduino.pinMode(rd, Arduino.OUTPUT);
  arduino.pinMode(blu, Arduino.OUTPUT);
  arduino.pinMode(grn, Arduino.OUTPUT);
  //arduino end
  size(500,530);
  smooth();
  for (int i = 0; i < xpos.length; i++) {
    xpos[i] = (i+1)*30;
  }
  noStroke();
  circle = new Circle();
  for(int i = 0; i < slider.length; i++) {
    slider[i] = new Slider();
    ypos[i] = height-10;
  }//end for
}//end setup

void draw() {
  background(100);
  circle.setColorVars();
  circle.display();
  for(int i = 0; i < slider.length; i++) {
    int[] r = {255,0,0};
    int[] g = {0,255,0};
    int[] b = {0,0,255};
    slider[i].displayRect(r[i],g[i],b[i],xpos[i]);
    slider[i].displayHandle(xpos[i],ypos[i]);
  }//end for
}//end draw

void mouseDragged() {
  for(int i = 0;i < slider.length; i++) {
    slider[i].dragging();
  }
}

Circle class:

class Circle {
  int r = 0;
  int g = 0;
  int b = 0;
  PFont f;
  
  Circle() {
    f = createFont("Arial", 30,true);
    textFont(f);
  }//end const
  
  void setColorVars() {
    r = 255 - ypos[0]/2+5;
    g = 255 - ypos[1]/2+5;
    b = 255 - ypos[2]/2+5;
  }

  void display() {
    fill(r,g,b);
    ellipse(width/2+50,height/2,250,250);
    textAlign(CENTER);
    text("(" + r + "," + g + "," + b + ")", width/2+50,40);
    arduino.analogWrite(rd,255-r);
    arduino.analogWrite(blu,255-b);
    arduino.analogWrite(grn,255-g);
  }//end void
}//end class
Slider class:

class Slider {
  int btm = height-10;
  int tp = 10;

  Slider() {
  }
  
  void displayRect(int r, int g, int b, int x) {
    fill(r,g,b);
    rectMode(CENTER);
    rect(x,height/2,20,510);
  }
  
  void displayHandle(int x, int y) {
    fill(0);
    rectMode(CENTER);
    rect(x,y,20,20);
  }
  
  void dragging() {
    if(mouseY >= tp && mouseY <= btm) {
      if(dist(mouseX,mouseY,xpos[0],ypos[0]) < 15) {
        ypos[0] = mouseY;
      }//endif
      if(dist(mouseX,mouseY,xpos[1],ypos[1]) < 15) {
        ypos[1] = mouseY;
      }//endif
      if(dist(mouseX,mouseY,xpos[2],ypos[2]) < 15) {
        ypos[2] = mouseY;
      }//endif
    }//endif
  }//end void
} //end class

Tricolor LED Project 1: Color Picker

I'm using Processing and Arduino to make some interactive light projects with a tricolor LED with some nice results. The first is an app that shows how digital colors mix. That's a ping pong ball on the LED. The LED is wired like in this diagram: http://arduino.cc/en/uploads/Tutorial/readASCIIString_bb.png. Remember when doing projects with Arduino thru Processing, follow these steps: http://playground.arduino.cc/interfacing/processing
The code is published below:




//COMMON ANODE TO 5V
import processing.serial.*; //for serial communication with any device
import cc.arduino.*; //for Arduino library methods
Arduino arduino; //create Arduino object from library
Circle circle;
Button[] button = new Button[3];
Led[] led = new Led[3];
boolean r_on,g_on,b_on;

void setup() {
  println(Arduino.list());//show me which COM port Arduino is using
  arduino = new Arduino(this, Arduino.list()[4], 57600);
  size(500,500);
  smooth();
  noStroke();
  circle = new Circle();
  for(int i = 0; i < button.length; i++) {
    button[i] = new Button();
    led[i] = new Led();
  }//end for
}//end setup

void draw() {
  background(100);
  if(r_on && !g_on && !b_on) {
    circle.setColor(255,0,0);
    for(int i = 0;i < button.length; i++) {
      button[i].redOn();
      led[i].redOn();
    }//endfor
  } else if(!r_on && g_on && !b_on) {
    circle.setColor(0,255,0);
    for(int i = 0;i < button.length; i++) {
      button[i].greenOn();
      led[i].greenOn();
    }//endfor
  } else if(!r_on && !g_on && b_on) {
    circle.setColor(0,0,255);
    for(int i=0; i < button.length; i++) {
      button[i].blueOn();
      led[i].blueOn();
   }//endfor
  } else if(r_on && g_on && !b_on) {
    circle.setColor(255,255,0);
    for(int i=0; i < button.length; i++) {
      button[i].yellowOn();
      led[i].yellowOn();
    }//endfor
  } else if(r_on && !g_on && b_on) {
    circle.setColor(255,0,255);
    for(int i=0; i < button.length; i++) {
      button[i].magentaOn();
      led[i].magentaOn();
    }//endfor
  } else if(!r_on && g_on && b_on) {
    circle.setColor(0,255,255);
    for(int i=0; i < button.length; i++) {
      button[i].cyanOn();
      led[i].cyanOn();
    }//endfor
  } else if(r_on && g_on && b_on){
    circle.setColor(255,255,255);
    for(int i=0; i < button.length; i++) {
      button[i].whiteOn();
      led[i].whiteOn();
    }//endfor
  } else {
    circle.setColor(0,0,0);
    for(int i = 0; i < button.length; i++) {
      button[i].blackOn();
      led[i].blackOn();
    }//endfor
  }//endelse
  circle.display();
}//end draw

void mousePressed() {
  if(dist(mouseX,mouseY,width/4,height/5*4) < 25) {
    r_on = !r_on;
  }
  if(dist(mouseX,mouseY,width/2,height/5*4) < 25) {
    g_on = !g_on;
  }
  if(dist(mouseX,mouseY,width/4*3,height/5*4) < 25) {
    b_on = !b_on;
  }
}//end void
Circle class:
class Circle {
  int rC = 0;
  int gC = 0;
  int bC = 0;
  PFont f;
  
  Circle() {
    f = createFont("Arial", 30,true);
    textFont(f);
  }//end const
  
  void setColor(int red,int green, int blue) {
    rC = red;
    gC = green;
    bC = blue;
  }//end void
  
  void display() {
    fill(rC,gC,bC);
    ellipse(width/2,height/2-50,250,250);
    textAlign(CENTER);
    text("(" + rC + "," + gC + "," + bC + ")", width/2,40);
  }//end void  
}//end class

Button class:
class Button {
  //arrays for r,g,b values for 3 buttons
  int[] r = new int[3];
  int[] g = new int[3];
  int[] b = new int[3];
  int[] xpos = new int[3];

  Button() {
  xpos[0] = width/4;
  xpos[1] = width/2;
  xpos[2] = width/4*3;
}
  
  void display(int br, int bg, int bb, int x) {
    fill(br,bg,bb);
    ellipse(x,height/5*4,50,50);
  }
  
  void redOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
      g[i] = 0;
      b[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }
  }
  
  void greenOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
      r[i] = 0;
      b[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void blueOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      r[i] = 0;
      g[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void yellowOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
       if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
      b[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void magentaOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
       if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      g[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void cyanOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
       if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      r[i] = 0;
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void whiteOn() {
    for(int i=0; i < button.length; i++) {
       if(i == 0) {
        r[i] = 255;
      } else {
        r[i] = 0;
      }
       if(i == 1) {
        g[i] = 255;
      } else {
        g[i] = 0;
      }
       if(i == 2) {
        b[i] = 255;
      } else {
        b[i] = 0;
      }
      button[i].display(r[i],g[i],b[i],xpos[i]);
    }//endfor
  }//endvoid

  void blackOn() {
    for(int i=0; i < button.length; i++) {
      button[i].display(0,0,0,xpos[i]);
    }//endfor
  }//endvoid
}//end class

Led class:
class Led{
  int rd,blu,grn;
  int colors[] = {rd,blu,grn};//array for LED colors
  
  Led() {
    for(int i = 0; i < colors.length; i++) {
      colors[i] = i+9;//assign arduino pins
      arduino.pinMode(colors[i], Arduino.OUTPUT);//pins to output
    }
  }
  
  void redOn() {
    for(int i=0; i < button.length; i++) {
      //array is "rd,blu,grn", LOW is on, HIGH is off!
      if(i == 0) {
        arduino.digitalWrite(colors[i], Arduino.LOW);
      } else {
        arduino.digitalWrite(colors[i], Arduino.HIGH);
      }
    }//endfor
  }//endvoid
  
  void greenOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 2) {
        arduino.digitalWrite(colors[i], Arduino.LOW);
      } else {
        arduino.digitalWrite(colors[i], Arduino.HIGH);
      }
    }//endfor
  }//end void

  void blueOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 1) {
        arduino.digitalWrite(colors[i], Arduino.LOW);
      } else {
        arduino.digitalWrite(colors[i], Arduino.HIGH);
      }
    }//endfor
  }//end void
  
  void yellowOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 1) {
        arduino.digitalWrite(colors[i], Arduino.HIGH);
      } else {
        arduino.digitalWrite(colors[i], Arduino.LOW);
      }
    }//endfor
  }//end void
  
  void magentaOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 2) {
        arduino.digitalWrite(colors[i], Arduino.HIGH);
      } else {
        arduino.digitalWrite(colors[i], Arduino.LOW);
      }
    }//endfor
  }//end void

  void cyanOn() {
    for(int i=0; i < button.length; i++) {
      if(i == 0) {
        arduino.digitalWrite(colors[i], Arduino.HIGH);
      } else {
        arduino.digitalWrite(colors[i], Arduino.LOW);
      }
    }//endfor
  }//end void

  void whiteOn() {
    for(int i=0; i < button.length; i++) {
      arduino.digitalWrite(colors[i], Arduino.LOW);
    }//endfor
  }//end void

  void blackOn() {
    for(int i=0; i < button.length; i++) {
      arduino.digitalWrite(colors[i], Arduino.HIGH);
    }//endfor
  }//end void
}//endclass

Sunday, February 10, 2013

Pygame on 64-bit Mac OS

I'm in the process of porting my instructional programming environment from Windows to Mac (10.8). That's Processing, Arduino, Python, Pygame, HTML editors and FTP apps, Scratch, Logo for GoGo Board.

  • Processing: easy, but connecting to an Arduino through Processing, still working on it
  • Arduino: easy
  • Python: tricky, downgrade to 2.7.3 for 32-bit, then Pygame will run.
  • Pygame: easy, once above is done
  • FileZilla: easy
  • HTML editor, TextWrangler
  • Scratch: easy, 2.0 is now online!
  • Logo for GoGo Board: no Mac driver? Not sure but working on it.

Tuesday, August 14, 2012

Raspberry Pi in the Classroom


I posted this today on an ed tech listserv and figured it's worth getting out here, too.

The Raspberry Pi is ready for prime time in the sense that the one-per-order restriction has been lifted and you can now purchase as many as you want. I've been tinkering with one this summer and I keep coming back to the question of what will we do with them in our schools. I think it's an urgent question which I'll explain as I go (sorry for the tl;dr).
The Raspberry Pi is a $35 computer. $35! (The one with only 1 USB port and no Ethernet is $25!) It's the size of a bar of soap. It comes with no case (yet); you have to make one. No I/O devices, just a board and ports. That number still doesn't compute for me, but consider how many you could get for an iPad. But you might say well then you have to get a monitor, keyboard, and mouse, at least. Actually, all you really need are a power supply (mine runs on a Blackberry charger, even 4 AA batteries will work), an SD card (the only storage!), and a network connection-either Ethernet or several wireless adapters will work. Then what? It's Linux, so you can hook it up to a monitor and keyboard just to enable SSH and create a few accounts and tunnel in from any computer on your network. And besides, the educational value of an iPad lies in all the apps you have to purchase, not to mention the time and expense of setting up an infrastructure that makes collective use feasible.
But cost is somewhat beside the point. Well, though, certainly not for public schools or cash-strapped independent schools. The main point is that it is nothing like the experience of an iPad, in fact it's the antithesis, and a sorely needed one, which is really the point made by the Raspberry Pi Foundation. Where the iPad (sorry, I really mean all proprietary devices) should work out of the box, you must hack your world and the Raspi just to make it work (hmm, i have to buy a charger...do I have any 5v chargers around? How do I know if it's 5v? wait I don’t have enough USB ports for a mouse, keyboard, and wifi adapter…ok a non-powered USB hub won’t work but a powered one will, why is that? Oh, there’s some help here, http://elinux.org/RPi_VerifiedPeripherals#Working_USB_Hubs, …now, a monitor, what, no VGA? Wait, I can plug it right into my 64” TV?!? And it looks awesome! etc, etc). Where the iPad wants you to think you don’t need to know anything about computers to use it, the Raspi forces you to learn just to get it to do anything. I didn’t know anything about Linux before I got this and now Linux is blowing my mind. I’m realizing the power, control, and options you can have with a computer if it’s designed to let you have those. Combing Linux forums for basic information I’ve read so many answers to queries that start, “Well, here are 4 ways you could do that…”
So getting back to the question of what to do with this device I can see it doesn’t belong as a standard integrated device like the iPad is becoming or laptops have been. It’s all about getting back to the basics of computer science and even physical computing. It belongs as a standard device in these makerspaces we are talking about and developing. It can do anything you want it to, really (though running it as a media server at home was a bit more than it could handle with 256MB of memory on board). We need to be alongside interested students helping them think about what they want to do with it and then guiding them through the mind blowing experience of learning how to get Linux to do anything you want with the decades of crowdsourced information you can tap into out there. I can see coming up with some really creative applications and having people see it and say, “What, a computer can do that?!? Wait, that’s a computer?” It’s really akin to the Arduino, in fact people are figuring out how to get the two to work together (http://www.raspberrypi.org/archives/1171). Interesting side note, this link is to a post about some resentment on the part of some in the Arduino community and makes the point that the two are fundamentally different and in fact can work well together, and I realized in looking at the accompanying photo that that difference is represented in a striking way by looking at the USB ports, where one uses the host type A port and the other the target type B.
Anyway if you’ve read all this thank you and I would love to hear your thoughts. 

Friday, August 10, 2012

Hack Time Machine Backup with Linux

If you need to get your files out of a Time Machine backup but you don't have a Mac, look no further. Get a computer with Linux on it. I'm using Ubuntu 12.04 but mostly you will just need to use the standard Linux shell terminal. It will be a painful experience, but hopefully a few things I've learned will help ease the pain a bit.
I started with Carson Baker's very helpful blog post on this which draws the basic map very clearly and succinctly. I needed to do a little research to clarify what he meant by cd'ing to the /media/Time Machine/.HFS+ Private Directory Data folder because you can't just type that in the terminal and get anywhere. In his comments he explains the use of tab-completion, which is amazingly helpful to know about.
In my case I cd'ed to the root level of my external drive, then typed .H, hit tab, and the rest filled itself in. That's voila for you! You can see it does mess with the spacing on the terminal command line, overwriting itself. But you get used to it.
Following his directions to figure out the hard link codes I found my backed up Pictures folder, which contained a Shoebox folder, for the app I had been using to store photos. Inside that is a folder for each year I've been using it for photo storage.
Listing the folders I discovered a huge problem. The photos for 2012 were there but the other years were simply more hard links! I had to find their hidden directory codes and cd to their folders. One thing I did to make the task a little easier is to write those codes to a file: ls -ls > /home/usr/Desktop/dirs.txt.
Looking further into the sub-folders for each year, my next problem was some contained a mixture of actual folders and hard links, which I had to get codes for, etc.
The above was the result of listing the contents of 2011, the folders being the months. So I needed to write those to a file for reference.
What a mess. Now the intact folders could be copied directly over very easily:
cp -rv . /home/usr/Pictures/2011. The copied hard links had to be deleted: rm -v /home/usr/Pictures/2011/01, etc.
Now one more level down are the folders for each day there were pictures. Inside those are the actual image files. These were also mixed folders and hard links. Rather than going through these one by one, finding the code, copying each day's folder, I made a script to automate at least this part. It creates the directories in the target drive for each missing folder (represented by a hard link), cd's to the coded directory for each, and copies the pictures over. All of that data has to be hard coded so that's a pain, but here's what it looked like.
The folders for July, 2011 looked like the above. Only 2 folders could be copied straight over. I saved the long form data to a text file: ls -ls > /home/usr/Desktop/dirs.txt.
That revealed the codes for each missing folder. I used that to write the following script and run it from the terminal in the top level of the .HFS+ Private Directory Data folder.
When it's moving all those files it's a beautiful thing to see, but it sure is a pain to create.

Saturday, August 04, 2012

RasPi Wi-Fi

I looked on this list of working wifi adapters for one to try out and found the Linksys WUSB100 adapter worked out of the box. I just had to add my network details to a config file as described at the bottom of this blog post. Now the problem is I need a powered USB hub to get enough juice to my keyboard, mouse, and wifi adapter. I can only plug in two at a time for now so I tried out text browsing the Internet with the command line browser Lynx. It's a different experience, cool!

Thursday, July 26, 2012

Raspberry Pi, Blazing Fast

I just re-imaged the Raspi with a new Raspbian "wheezy" image supplied on the raspberrypi.org website. They said it would be faster and it's a LOT faster. Great job, Alex and Dom! Instructions on how to load the OS on your SD card are here.

Saturday, July 21, 2012

Switches and Arduino

Both pins are digital pin 3. The right one goes to the EL Wire
and the left one can go to whatever you want!
I was wiring up momentary switches to control some EL Wire when I discovered something interesting. The El Escudo Dos (Electroluminescent Wire sequencer) has double digital pins after you solder in the headers that allow it to stack onto an Arduino. What that means is you can assign one pin to multiple functions. If you connect a LED to the header pin and write it high you will see both the EL Wire on that pin and the LED light up. In my project linked above I unwittingly assigned the header pins as input for the switches and the same pins as output for the EL Wire, effectively programming them into a circuit so pressing the switch would automatically light the wire. I only figured this out because I wanted to program functions for different flashing sequences to each switch and they wouldn't work, just turn the wire on and off. I finally moved the switches to pins 6, 7, and 8 and everything worked. So it turns out all the code you need to make the EL Wire light up with a switch press is the following which simply assigns the input and output in setup:
int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {3,4,5};              // same with switch pins

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
  }
}

void loop() {
//nothing needs to loop!
}
In the project linked above I initially had all that extra code because I was using the Lady Ada tutorial on programming switches with the Arduino and since on an Arduino each pin can only do one thing they used pin 2 for input and pin 12 for output. Their code had to use conditional statements to get the switch to work the LED.
Here is another program version using functions to assign different patterns to the 3 switches:

int wirePin[] = {3,4,5};                // create array values corresponding to wire pinOuts
int switchPin[] = {6,7,8};              // same with switch pins
int val[3];                        // variable for reading the pin status

void setup() {
  for(int i = 0;i<3;i++) {
    pinMode(wirePin[i], OUTPUT);    // Set the wire pins as output
    pinMode(switchPin[i], INPUT);    // Set the switch pins as input
    val[i] = 0;                    // Set val array to 0
  }
}

void loop(){
  for(int i = 0;i<3;i++) {
    val[i] = digitalRead(switchPin[i]);   // read input values and store it in val array
    if (val[0] == HIGH) {
      sequence(5);
    }
    if (val[1] == HIGH) {
      flash(5);
    }
    if (val[2] == HIGH) {
      alternate(2);
    }
    // check if buttons are not pressed
    if (val[i] == LOW) {
      digitalWrite(wirePin[i], LOW);    // turn wires off
    }
  }
}
  
void sequence(int times) {
  for(int i = 0;i<times;i++) {
    digitalWrite(wirePin[0], HIGH);
    delay(90);
    digitalWrite(wirePin[0], LOW);
    digitalWrite(wirePin[1], HIGH);
    delay(90);
    digitalWrite(wirePin[1], LOW);
    digitalWrite(wirePin[2], HIGH);
    delay(90);
    digitalWrite(wirePin[2], LOW);
  }
}

void flash(int times) {
  for(int i = 0;i<times;i++) {
    for(int j = 0;j<3;j++) {
      digitalWrite(wirePin[j], HIGH);
    }
    delay(100);
    for(int j = 0;j<3;j++) {
      digitalWrite(wirePin[j], LOW);
    }
    delay(100);
  }
}

void alternate(int times) {
  for(int i = 0;i<times;i++) {
      digitalWrite(wirePin[0], HIGH);
      digitalWrite(wirePin[1], HIGH);
      delay(170);
      digitalWrite(wirePin[0], LOW);
      digitalWrite(wirePin[1], LOW);
      digitalWrite(wirePin[2], HIGH);
      delay(170);
      digitalWrite(wirePin[2], LOW);

      digitalWrite(wirePin[2], HIGH);
      digitalWrite(wirePin[1], HIGH);
      delay(170);
      digitalWrite(wirePin[2], LOW);
      digitalWrite(wirePin[1], LOW);
      digitalWrite(wirePin[0], HIGH);
      delay(170);
      digitalWrite(wirePin[0], LOW);

      digitalWrite(wirePin[0], HIGH);
      digitalWrite(wirePin[2], HIGH);
      delay(170);
      digitalWrite(wirePin[0], LOW);
      digitalWrite(wirePin[2], LOW);
      digitalWrite(wirePin[1], HIGH);
      delay(170);
      digitalWrite(wirePin[1], LOW);
  }
}