Step 3Sewing LEDs
We are going to use a fairly common trick. We know that later we will have to attach a power supply to the LilyPad and it can be difficult to combine thread lines. Therefore, we can use a little trick by declaring pin 5 as output and setting the pin to low (a fake ground). In your code, you will write this:
int ground = 5;
void setup() {
pinMode(ground,OUTPUT);
digitalWrite(ground,LOW);
}
Note: while we can set any pin to ground, usually, it is not recommend to set a pin HIGH as another PLUS pin. LilyPads can only output 40mA from each digital I/O pin.
We can stitch all of the minus sides of the LEDs together and then to pin 5.
After you complete your sewing, plug-in your LilyPad to your computer and use the following code to flash all the lights.
int ledPin13 = 13; // LED connected to digital pin 13
int ledPin12 = 12; // LED connected to digital pin 12
int ledPin11 = 11; // LED connected to digital pin 11
int ledPin10 = 10; // LED connected to digital pin 10
int ledPin9 = 9; // LED connected to digital pin 9
int ledPin8 = 8; // LED connected to digital pin 8
int ledPin7 = 7; // LED connected to digital pin 7
int ledPin6 = 6; // LED connected to digital pin 6
int ground = 5; // LED connected to digital 5 "ground"
int ledPinArray[8] = {6,7,8,9,10,11,12,13};
void setup() {
// initialize the digital pin as an output:
for(int i = 0; i < 8; i++){
pinMode(ledPinArray[i],OUTPUT);
}
pinMode(ground, OUTPUT);
digitalWrite(ground, LOW);
}
{
for(int i = 0; i < 8; i++){
digitalWrite(ledPinArray[i],HIGH);
}
delay(1000); // wait for a second
for(int i = 0; i < 8; i++){
digitalWrite(ledPinArray[i],LOW);
}
delay(1000); // wait for a second
}
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|














































