See Spiritual Pumpkins in action.
Here is my midterm project. I call them Spiritual Pumpkins. The midterm project was due in October, Halloween time, so I thought it would be fun to do a Halloween-themed project. I love carving pumpkins, and I love the Legend of Zelda.
The idea of Spiritual Pumpkins came from the Spiritual Stones in the Legend of Zelda video game. While working on this project I took the opportunity to share the process with the kids that I teach programming to. They had a blast learning about LED’s.
Watch my student’s having fun with LED’s.
Close-ups for details of the carving and light shining from the LED’s.
SO MUCH SOLDERING.
I don’t even understand how I got burnt there.
//FADE////////////////////////////////////////////////////////////
int led = 9; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by//CHASE////////////////////////////////////////////////////////////
// Simple macros to remember which direction to shift LEDs
#define UP true
#define DOWN false
// Will be used to track how long since last event “fired”
unsigned long previousMillis=0;
// Delay to determine when we see the next LED
unsigned long interval = 250;
// Array with Arduino pins containing LEDs in sequence
byte LEDpins[] = {2,3,4,5,6};
// Variable to track which LED to turn on, start at 000001
int LEDstate=0x01;
// State variable to know which direction to shift
boolean direction=UP;//FLICKER////////////////////////////////////////////////////////////
int ledPin3 = 11;//////////////////////////////////////////////////////////////////////
//////////////////////////////VOID_SETUP//////////////////////////////
//////////////////////////////////////////////////////////////////////void setup() {
//FADE////////////////////////////////////////////////////////////
// declare pin 9 to be an output:
pinMode(led, OUTPUT);//CHASE////////////////////////////////////////////////////////////
// Set Pins with LEDs to OUTPUT
for (int x=0; x < 5; x++)
pinMode(LEDpins[x], OUTPUT);//FLICKER////////////////////////////////////////////////////////////
pinMode(ledPin3, OUTPUT);
}//////////////////////////////////////////////////////////////////////
//////////////////////////////VOID_LOOP///////////////////////////////
//////////////////////////////////////////////////////////////////////void loop() {
//FADE////////////////////////////////////////////////////////////
// set the brightness of pin 9
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);//CHASE////////////////////////////////////////////////////////////
// Set the pins of each LED during each iteration
// You’ll only see something change when “LEDpins” gets updated
for (int x=0; x < 5; x++)
digitalWrite(LEDpins[x], bitRead(LEDstate,x));
// Get current time and determine how long since last check
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis – previousMillis) >= interval) {
// We’ve waited “interval” amount of time, so let’s do some stuff!
// “Reset” our clock
previousMillis = currentMillis;
if (direction==UP) {
// Use “<<” to “bit-shift” everything to the left once
LEDstate = LEDstate << 1;
// 0x20 is the “last” LED, another shift makes the value 0x40
if (LEDstate == 0x40) {
// turn on the one before “0x20” and reverse direction
LEDstate = 0x10;
direction = DOWN;
}
} else {
// use “>>” to “bit-shift” all bits in LEDstate once to the right
LEDstate = LEDstate >> 1;
// This means we ran out of bits!
if (LEDstate == 0x00) {
// set one ahead so no extra delay
LEDstate = 0x02;
direction = UP;
}
}
}
//FLICKER////////////////////////////////////////////////////////////
analogWrite(ledPin3, random(120)+135);
delay(random(100));
}