Skip to content

Commit d237f29

Browse files
author
Mike Grusin
committed
added LPP Activity Guide code
1 parent 99d87cf commit d237f29

File tree

21 files changed

+1038
-0
lines changed

21 files changed

+1038
-0
lines changed

IDE_Board_Manager/package_sparkfun_index.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,55 @@
150150
],
151151
"toolsDependencies": []
152152
},
153+
{
154+
"name": "SparkFun AVR Boards",
155+
"architecture": "avr",
156+
"version": "1.1.8.beta",
157+
"category": "Contributed",
158+
"url": "https://github.com/sparkfun/Arduino_Boards/raw/master/IDE_Board_Manager/sparkfunboards.1.1.8.beta.tar.bz2",
159+
"archiveFileName": "sparkfunboards.1.1.8.beta.tar.bz2",
160+
"checksum": "SHA-256:15699A30A9A6701B0658611939B8CBB8A2B1FE60F5F9A1636253C80A41D11B57",
161+
"size": "1238535",
162+
"help": {
163+
"online": "https://forums.sparkfun.com"
164+
},
165+
"boards": [
166+
{
167+
"name": "RedBoard"
168+
},
169+
{
170+
"name": "MaKey MaKey"
171+
},
172+
{
173+
"name": "Pro Micro"
174+
},
175+
{
176+
"name": "Fio v3"
177+
},
178+
{
179+
"name": "Qduino Mini"
180+
},
181+
{
182+
"name": "Digital Sandbox"
183+
},
184+
{
185+
"name": "Mega Pro"
186+
},
187+
{
188+
"name": "RedBot"
189+
},
190+
{
191+
"name": "Serial 7-segment Display"
192+
},
193+
{
194+
"name": "ATmega128RFA1 Dev Board"
195+
},
196+
{
197+
"name": "LilyPad USB Plus"
198+
}
199+
],
200+
"toolsDependencies": []
201+
},
153202
{
154203
"name": "SparkFun SAMD Boards (dependency: Arduino SAMD Boards 1.6.5)",
155204
"architecture": "samd",
Binary file not shown.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
LilyPad ProtoSnap Plus Activity 10: Twinkling Night Light
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Create a twinkling night light that turns on when it gets dark.
7+
8+
Follow the tutorial at: https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide#10-twinkling-night-light-project
9+
10+
This code is released under the MIT License (http://opensource.org/licenses/MIT)
11+
12+
******************************************************************************/
13+
14+
// Create variables for the pins we'll be using:
15+
16+
int lightSensor = A2;
17+
18+
// Array of all the LEDs we'll be twinkling. You can set these to the sewtabs
19+
// you'll be using in your project. Remember to only choose outputs that
20+
// have the "~" symbol that are compatible with analogWrite.
21+
22+
int numLEDs = 3;
23+
int LED[3] = {6,A7,A8};
24+
25+
int blueLED = 14;
26+
27+
// Threshold for light level (when it's darker than this, twinkle LEDs)
28+
29+
int threshold = 50;
30+
31+
void setup()
32+
{
33+
int x;
34+
35+
// Initialize the pins we'll be using
36+
37+
pinMode(lightSensor, INPUT);
38+
39+
for (x = 0; x <= numLEDs; x++)
40+
{
41+
pinMode(LED[x],OUTPUT);
42+
}
43+
44+
pinMode(blueLED,OUTPUT);
45+
46+
// Initialize the serial monitor
47+
48+
Serial.begin(9600);
49+
}
50+
51+
void loop()
52+
{
53+
int x,lightLevel,brightness;
54+
55+
// Read the sensor value (will be 0 to 255):
56+
57+
lightLevel = analogRead(lightSensor);
58+
59+
// Print out the sensor reading:
60+
61+
Serial.print("light level: ");
62+
Serial.print(lightLevel);
63+
Serial.print(" threshold: ");
64+
Serial.print(threshold);
65+
Serial.print(" twinkle: ");
66+
67+
// If the light level is below the threshold, twinkle LEDs:
68+
69+
if (lightLevel < threshold)
70+
{
71+
Serial.println("ON");
72+
digitalWrite(blueLED,HIGH);
73+
74+
// Pick a random LED:
75+
76+
x = random(numLEDs);
77+
78+
// Quickly ramp up the brightness of the LED from off to on:
79+
80+
for (brightness = 0; brightness <= 255; brightness++)
81+
{
82+
analogWrite(LED[x],brightness);
83+
delay(1);
84+
}
85+
86+
// Quickly ramp down the brightness of the LED from on to off:
87+
88+
for (brightness = 255; brightness >= 0; brightness--)
89+
{
90+
analogWrite(LED[x],brightness);
91+
delay(1);
92+
}
93+
94+
// Wait a random amount of time (up to 2 seconds)
95+
96+
delay(random(2000));
97+
}
98+
else
99+
{
100+
Serial.println("off");
101+
digitalWrite(blueLED,LOW);
102+
}
103+
}
104+
105+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
LilyPad ProtoSnap Plus Activity 1: Blinking LEDs
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Blink the pair of yellow LEDs attached to sew tab A5 on the LilyPad USB Plus
7+
8+
Follow the tutorial at: https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide#1-blinking-leds
9+
10+
This example is based on: Blink by Scott Fitzgerald
11+
https://www.arduino.cc/en/Tutorial/Blink
12+
13+
This code is released under the MIT License (http://opensource.org/licenses/MIT)
14+
15+
******************************************************************************/
16+
17+
// The setup function runs once when the microcontroller starts up or resets:
18+
19+
void setup()
20+
{
21+
// Before you use a sew tab (pin), you must set it to be either an input or output:
22+
23+
pinMode(A5, OUTPUT); // Set pin A5 to be an output
24+
}
25+
26+
// After the setup function runs, the loop function runs over and over forever:
27+
28+
void loop()
29+
{
30+
digitalWrite(A5, HIGH); // Give pin A5 a HIGH voltage level (on), which lights up the LED
31+
delay(1000); // Pause for 1000 milliseconds (one second), the LED stays on
32+
digitalWrite(A5, LOW); // Give pin A5 a LOW voltage level (off), which turns off the LED
33+
delay(1000); // Pause for 1000 milliseconds (one second), the LED stays off
34+
}
35+
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/*
2+
LilyPad ProtoSnap Plus Activity 2: Basic Color Mixing
3+
SparkFun Electronics
4+
https://www.sparkfun.com/products/14346
5+
6+
Create primary and secondary colors on the built-in RGB (Red/Green/Blue) LED
7+
8+
Follow the tutorial at: https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide#2-basic-color-mixing
9+
10+
This code is released under the MIT License (http://opensource.org/licenses/MIT)
11+
12+
******************************************************************************/
13+
14+
// The LilyPad USB Plus has a built-in RGB (Red / Green / Blue) LED.
15+
// In this activity we'll use digitalWrite to tun the three LEDs on and off
16+
// in various combinations to create eight primary and secondary colors.
17+
18+
// Create integer variables for our LED pins:
19+
20+
// The built-in LED:
21+
22+
int RGB_red = 12;
23+
int RGB_green = 13;
24+
int RGB_blue = 14;
25+
26+
// The colored LEDs along the bottom edge of the board:
27+
28+
int redLED = 6;
29+
int greenLED = A7;
30+
int blueLED = A8;
31+
32+
void setup()
33+
{
34+
// Make all of our LED pins outputs:
35+
36+
pinMode(RGB_red, OUTPUT);
37+
pinMode(RGB_green, OUTPUT);
38+
pinMode(RGB_blue, OUTPUT);
39+
pinMode(redLED, OUTPUT);
40+
pinMode(greenLED, OUTPUT);
41+
pinMode(blueLED, OUTPUT);
42+
}
43+
44+
void loop()
45+
{
46+
47+
// This code will step through the six primary and secondary colors, plus white and black.
48+
49+
// For each of these colors, we'll turn the necessary RGB LEDs on or off.
50+
// We'll also turn on the same LEDs on the bottom edge, so you can see what's being mixed.
51+
52+
// Black (all LEDs off)
53+
54+
// RGB LEDs:
55+
56+
digitalWrite(RGB_red, LOW);
57+
digitalWrite(RGB_green, LOW);
58+
digitalWrite(RGB_blue, LOW);
59+
60+
// Bottom-edge LEDs
61+
62+
digitalWrite(redLED, LOW);
63+
digitalWrite(greenLED, LOW);
64+
digitalWrite(blueLED, LOW);
65+
delay(1000);
66+
67+
// Red (red LED on)
68+
69+
digitalWrite(RGB_red, HIGH);
70+
digitalWrite(RGB_green, LOW);
71+
digitalWrite(RGB_blue, LOW);
72+
73+
digitalWrite(redLED, HIGH);
74+
digitalWrite(greenLED, LOW);
75+
digitalWrite(blueLED, LOW);
76+
delay(1000);
77+
78+
// Yellow (red and green LEDs on)
79+
80+
digitalWrite(RGB_red, HIGH);
81+
digitalWrite(RGB_green, HIGH);
82+
digitalWrite(RGB_blue, LOW);
83+
84+
digitalWrite(redLED, HIGH);
85+
digitalWrite(greenLED, HIGH);
86+
digitalWrite(blueLED, LOW);
87+
delay(1000);
88+
89+
// Green (green LED on)
90+
91+
digitalWrite(RGB_red, LOW);
92+
digitalWrite(RGB_green, HIGH);
93+
digitalWrite(RGB_blue, LOW);
94+
95+
digitalWrite(redLED, LOW);
96+
digitalWrite(greenLED, HIGH);
97+
digitalWrite(blueLED, LOW);
98+
delay(1000);
99+
100+
// Cyan (blue and green LEDs on)
101+
102+
digitalWrite(RGB_red, LOW);
103+
digitalWrite(RGB_green, HIGH);
104+
digitalWrite(RGB_blue, HIGH);
105+
106+
digitalWrite(redLED, LOW);
107+
digitalWrite(greenLED, HIGH);
108+
digitalWrite(blueLED, HIGH);
109+
delay(1000);
110+
111+
// Blue (blue LED on)
112+
113+
digitalWrite(RGB_red, LOW);
114+
digitalWrite(RGB_green, LOW);
115+
digitalWrite(RGB_blue, HIGH);
116+
117+
digitalWrite(redLED, LOW);
118+
digitalWrite(greenLED, LOW);
119+
digitalWrite(blueLED, HIGH);
120+
delay(1000);
121+
122+
// Magenta (red and blue LEDs on)
123+
124+
digitalWrite(RGB_red, HIGH);
125+
digitalWrite(RGB_green, LOW);
126+
digitalWrite(RGB_blue, HIGH);
127+
128+
digitalWrite(redLED, HIGH);
129+
digitalWrite(greenLED, LOW);
130+
digitalWrite(blueLED, HIGH);
131+
delay(1000);
132+
133+
// White (all LEDs on)
134+
135+
digitalWrite(RGB_red, HIGH);
136+
digitalWrite(RGB_green, HIGH);
137+
digitalWrite(RGB_blue, HIGH);
138+
139+
digitalWrite(redLED, HIGH);
140+
digitalWrite(greenLED, HIGH);
141+
digitalWrite(blueLED, HIGH);
142+
delay(1000);
143+
}

0 commit comments

Comments
 (0)