Skip to content

Commit 88fcfe1

Browse files
author
Mike Grusin
committed
Updated LilyPad Proto Board code examples
1 parent 39d62ae commit 88fcfe1

File tree

18 files changed

+865
-424
lines changed

18 files changed

+865
-424
lines changed

IDE_Board_Manager/package_sparkfun_index.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
"category": "Contributed",
109109
"url": "https://github.com/sparkfun/Arduino_Boards/raw/LilyProtoBoard/IDE_Board_Manager/sparkfunboards.1.1.7.tar.bz2",
110110
"archiveFileName": "sparkfunboards.1.1.7.tar.bz2",
111-
"checksum": "SHA-256:5baa562d9be578b2888088c70c167851b667ad559dad9cc6d93a496681915e2f",
112-
"size": "1237425",
111+
"checksum": "SHA-256:AAA4F6614BB9BD89400E595B406720F60A895810F9D7E884E7A2DEA866DFF90D",
112+
"size": "1238374",
113113
"help": {
114114
"online": "https://forums.sparkfun.com"
115115
},
949 Bytes
Binary file not shown.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
LilyPad Prototyping Board Activity 10: LilyPixel
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Make external LilyPixel boards fade through a rainbow of colors
7+
8+
This sketch was written by SparkFun Electronics,
9+
and is based on NeoPixel Ring simple sketch (c) 2013 Shae Erisson
10+
released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
11+
12+
******************************************************************************/
13+
14+
// Include the NeoPixel library, used to drive addressable LEDs
15+
16+
#include <Adafruit_NeoPixel.h>
17+
#ifdef __AVR__
18+
#include <avr/power.h>
19+
#endif
20+
21+
// We'll hook up the "DI" sew tab of the LilyPixel
22+
// to pin 10 on the LilyPad Development Board:
23+
24+
#define pixelPin 10
25+
26+
// You can daisy chain many LilyPixel boards together,
27+
// In this demo we're just using one:
28+
29+
#define numPixels 1
30+
31+
// The NeoPixel library needs to know what type of
32+
// addressable LED we're connecting to it.
33+
// This command makes those settings:
34+
35+
Adafruit_NeoPixel lilyPixels = Adafruit_NeoPixel(numPixels, pixelPin, NEO_GRB + NEO_KHZ800);
36+
37+
// Delay value in milliseconds between color changes, make smaller to go faster:
38+
39+
int delayval = 5;
40+
41+
void setup() {
42+
43+
// Initialize the NeoPixel library:
44+
45+
lilyPixels.begin();
46+
}
47+
48+
void loop() {
49+
int hue, address;
50+
unsigned char r,g,b;
51+
52+
// We'll make all the LilyPixels smoothly change colors through a rainbow.
53+
// The "hue" is the color value, for the rainbow function we're using
54+
// it will range from 0 to 767.
55+
56+
for(hue = 0; hue < 767; hue++){
57+
58+
// Each LilyPixel you've daisy-chained together has an address.
59+
// The address starts at 0 for the nearest one, 1 for the next, etc.
60+
// This for loop will step through all the LilyPixels:
61+
62+
for(address=0; address<numPixels; address++){
63+
64+
// Compute the rainbow r,g,b values from the "hue" (0 to 767)
65+
66+
rainbow(hue,r,g,b);
67+
68+
// Set a LilyPixel chosen with address, to a RGB color
69+
70+
lilyPixels.setPixelColor(address,r,g,b);
71+
72+
// We now must send the color set in the above step to the actual LilyPixel:
73+
74+
lilyPixels.show();
75+
76+
delay(delayval);
77+
}
78+
}
79+
}
80+
81+
void rainbow(int hue, unsigned char &r, unsigned char &b, unsigned char &g){
82+
83+
hue = constrain(hue, 0, 767); // constrain the input value to a range of values from 0 to 767
84+
85+
// if statement breaks down the "hue" into three ranges:
86+
87+
if (hue <= 255) // RANGE 1 (0 - 255) - red to green
88+
{
89+
r = 255 - hue; // red goes from on to off
90+
g = hue; // green goes from off to on
91+
b = 0; // blue is always off
92+
}
93+
94+
else if (hue <= 511) // RANGE 2 (256 - 511) - green to blue
95+
{
96+
r = 0; // red is always off
97+
g = 511 - hue; // green on to off
98+
b = hue - 256; // blue off to on
99+
}
100+
101+
else // RANGE 3 ( >= 512)- blue to red
102+
{
103+
r = hue - 512; // red off to on
104+
g = 0; // green is always off
105+
b = 767 - hue; // blue on to off
106+
}
107+
}
108+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
LilyPad Prototyping Board Activity 1: Blink
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Turns on the LEDs attached to the LilyPad Prototyping Board's sew tab 6 on for one
7+
second,then off for one second, forever.
8+
9+
This sketch was written by SparkFun Electronics,
10+
and is based on Blink by Scott Fitzgerald
11+
https://www.arduino.cc/en/Tutorial/Blink
12+
This code is covered by the MTT license and is completely free for any use.
13+
14+
******************************************************************************/
15+
16+
// The setup function runs once when the LilyMini turns on:
17+
18+
void setup() {
19+
pinMode(6, OUTPUT); // Initialize pin 6 as a digital output:
20+
}
21+
22+
// Once the setup function runs, the loop function runs over and over:
23+
24+
void loop() {
25+
digitalWrite(6, HIGH); // Give pin 6 a HIGH voltage level (on), which lights up the LED
26+
delay(1000); // Wait for one second (the LED stays on)
27+
digitalWrite(6, LOW); // Give pin 6 a LOW voltage level (off), which turns off the LED
28+
delay(1000); // Wait for one second (the LED stays off)
29+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
LilyPad Prototyping Board Activity 2: Buttons and Switches
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Read a button (digital input) on pin 4
7+
Turn on the LED on pin 5 when pressed, and off when released.
8+
Read a switch (digital input) on pin 9
9+
Turn on the LED on pin 8 when switch is set to ON, and off when OFF
10+
11+
This sketch was written by SparkFun Electronics,
12+
and is based on InputPullupSerial code by Scott Fitzgerald
13+
http://www.arduino.cc/en/Tutorial/InputPullupSerial
14+
This code is covered by the MTT license and is completely free for any use.
15+
16+
******************************************************************************/
17+
18+
// Create integer variables for the pins we're using:
19+
20+
int buttonPin = 4;
21+
int switchPin = 9;
22+
int ledPin1 = 5;
23+
int ledPin2 = 8;
24+
25+
// Create variables to hold switch/button readings:
26+
27+
int buttonState;
28+
int switchState;
29+
30+
void setup() {
31+
32+
// Configure the switch and button as inputs with pullup resistors:
33+
34+
pinMode(buttonPin, INPUT_PULLUP);
35+
pinMode(switchPin, INPUT_PULLUP);
36+
37+
// The pullup is a small internal resistor between the sewtab and HIGH voltage.
38+
// This weakly "pulls up" the input to HIGH if the button is disconnected (not
39+
// being pressed). This keeps the input from "floating" (randomly reading either
40+
// HIGH or LOW) when the button is not being pressed.
41+
42+
// Configure both ledPins as outputs:
43+
44+
pinMode(ledPin1, OUTPUT);
45+
pinMode(ledPin2, OUTPUT);
46+
}
47+
48+
void loop() {
49+
50+
// Read the button and switch states (HIGH or LOW) and store them:
51+
52+
buttonState = digitalRead(buttonPin);
53+
switchState = digitalRead(switchPin);
54+
55+
// Note that LOW = pressed and HIGH = released, the opposite of what you might expect.
56+
// This is because the button is attached to ground, which is the LOW voltage level.
57+
// When you push the button, it's attached to ground, and digitalRead returns LOW.
58+
// When the button is released, the pullup resistor pulls the signal to HIGH.
59+
60+
// This "if" statement handles the button state (pressed = LOW, released = HIGH)
61+
62+
if (buttonState == LOW) { // If LOW, the button is pressed
63+
digitalWrite(ledPin1, HIGH); // Turn the LEDs on
64+
} else { // Otherwise it's HIGH, or unpressed
65+
digitalWrite(ledPin1, LOW); // Turn the LEDs off
66+
}
67+
68+
// This "if" statement handles the switch state (switched on = LOW, switched off = HIGH)
69+
70+
if (switchState == HIGH) { // If LOW, the switch is on
71+
digitalWrite(ledPin2, HIGH); // Turn the LEDs on
72+
} else { // Otherwise it's HIGH, or off
73+
digitalWrite(ledPin2, LOW); // Turn the LEDs off
74+
}
75+
}
76+
77+
78+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
LilyPad Prototyping Board Activity 3: Color Mixing
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Make an RGB LED display a rainbow of colors!
7+
8+
An RGB LED is actually three LEDs (red, green, and blue) in
9+
one package. When you turn them on and off in various combinations,
10+
the red, green and blue mix to form new colors.
11+
12+
The RGB LED is permanently connected to the following pins:
13+
14+
Red - pin 12
15+
Green - pin 13
16+
Blue - pin 14
17+
18+
This sketch was written by SparkFun Electronics,
19+
with lots of help from the Arduino community.
20+
This code is covered by the MTT license and is completely free for any use.
21+
22+
******************************************************************************/
23+
24+
// Create and set variables for the RGB LED pins:
25+
26+
int RED_PIN = 12;
27+
int GREEN_PIN = 13;
28+
int BLUE_PIN = 14;
29+
30+
// Set a variable delayTime for the pause between color changes
31+
// This variable controls how fast we loop through the colors.
32+
// (Try changing this to make the colors change faster or slower.)
33+
34+
int delayTime = 1000; // 1000 milliseconds = 1 second
35+
36+
void setup()
37+
{
38+
// Here we'll configure the LilyMini pins we're using to
39+
// drive the LED to be outputs:
40+
41+
pinMode(RED_PIN, OUTPUT);
42+
pinMode(GREEN_PIN, OUTPUT);
43+
pinMode(BLUE_PIN, OUTPUT);
44+
}
45+
46+
void loop()
47+
{
48+
// We're going to turn the individual LEDs (red, blue, and green)
49+
// on and off in various combinations. This gives you a total of
50+
// eight colors (if you count "black" as a color).
51+
// Note that we use delay between each color to slow it down so
52+
// you can see them.
53+
54+
// Black (all LEDs off)
55+
digitalWrite(RED_PIN, LOW);
56+
digitalWrite(GREEN_PIN, LOW);
57+
digitalWrite(BLUE_PIN, LOW);
58+
59+
delay(delayTime);
60+
61+
// Red (turn just the red LED on):
62+
63+
digitalWrite(RED_PIN, HIGH);
64+
digitalWrite(GREEN_PIN, LOW);
65+
digitalWrite(BLUE_PIN, LOW);
66+
67+
delay(delayTime);
68+
69+
// Green (turn just the green LED on):
70+
71+
digitalWrite(RED_PIN, LOW);
72+
digitalWrite(GREEN_PIN, HIGH);
73+
digitalWrite(BLUE_PIN, LOW);
74+
75+
delay(delayTime);
76+
77+
// Blue (turn just the blue LED on):
78+
79+
digitalWrite(RED_PIN, LOW);
80+
digitalWrite(GREEN_PIN, LOW);
81+
digitalWrite(BLUE_PIN, HIGH);
82+
83+
delay(delayTime);
84+
85+
// Yellow (turn red and green on):
86+
87+
digitalWrite(RED_PIN, HIGH);
88+
digitalWrite(GREEN_PIN, HIGH);
89+
digitalWrite(BLUE_PIN, LOW);
90+
91+
delay(delayTime);
92+
93+
// Cyan (turn green and blue on):
94+
95+
digitalWrite(RED_PIN, LOW);
96+
digitalWrite(GREEN_PIN, HIGH);
97+
digitalWrite(BLUE_PIN, HIGH);
98+
99+
delay(delayTime);
100+
101+
// Purple (turn red and blue on):
102+
103+
digitalWrite(RED_PIN, HIGH);
104+
digitalWrite(GREEN_PIN, LOW);
105+
digitalWrite(BLUE_PIN, HIGH);
106+
107+
delay(delayTime);
108+
109+
// White (turn all the LEDs on):
110+
111+
digitalWrite(RED_PIN, HIGH);
112+
digitalWrite(GREEN_PIN, HIGH);
113+
digitalWrite(BLUE_PIN, HIGH);
114+
115+
delay(delayTime);
116+
}
117+
118+

0 commit comments

Comments
 (0)