Hello everyone! After finding out about the Arduino I ordered one. And I don't think I've unplugged it from my computer since!
Well I have done many small project and such so far, I'm finding a wealth of information all over the net. But by far this Forum as been one of my favorite resources. Any-who, I have finshed my first little project, it's not much, but as a first project I'm very proud of it! After reading Todbot's Spooky Projects Spooky Projects – Introduction to Microcontrollers with Arduino – todbot blog I converted a pumpkin into a LED lighted pumpkin, complete with glowing eyes! Well that wasn't enough, and in the spirit of Arduino I enhanced my LED pumpkin, and here's where my project comes in! The LED glows, but when I blow across a simple little switch I tossed together, the LEDs flicker like a candle does when you blow on it! Soon after the LEDs return to normal operation. I know this isn't much, but then again its my first Arduino project.
Here's the code: ( Excuse any mess. I need to clean it up a bit )
/*
* Wind Switch with Flickering LED
* by Electrick_RWM (dragoonx@gmail.com)
* Date Oct 18 2007
* Makes the LED on Pin 9 glow sloftly and when Switch or "Wind" Switch is toggled it flickers!
* After the LED flickers it returns to its normal glowing loop until blown on again
*
* Thanks to TodBot for the Spooky Arduino Projects!
* Without his tutorials I would have never been able to create this project
* http://www.arduino.cc
*/
int ledPin = 13; // choose the pin for the LED
int ledCandle = 9; // choose the pin for the LED
int inputPin = 7; // choose the input pin (For Wind Switch)
int val = 0; // variable for reading the pin status
int max_count = 60; // counter for the flicker table
int max_count_Normal = 64; // counter for normal glowing table
int count = 0;
int countTwo = 0;
byte Norm_Glow_table[] = { 10, 10, 10, 10, 20, 30, 30, 30, 40, 50, 60, 70, 80, 90,100, // The table for our normal glowing
110,120,130,140,150,160,170,180,190,200,
210,220,230,240,250,250,250,250,250,250,
240,230,220,210,200,190,180,170,160,150,
140,130,120,110,100, 90, 80, 70, 60, 50,
40, 30, 30, 30, 20, 10, 10, 10, 10 };
byte Flicker_table[] = { 10, 10, 20, 30, 30, 30, 40, 50, 60, 70, 80, 70, 70, // the table that tells us how to flicker
60, 60, 50, 50, 50, 60, 70, 80, 90, 100,
120,140,160,240,250,100,150,250,250,140,
240,230,220,100, 80,70,70, 70, 80, 80,
140,130,120,110,200,210,220,220,100, 90,
40, 30, 30, 30, 20, 10, 10 };
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(ledCandle, OUTPUT); // declare Wind led as output
pinMode(inputPin, INPUT); // declare Wind Switch as input
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
analogWrite(ledCandle, Norm_Glow_table[count]); // Runs through the Norm_Glow_table
count++; // We stay in this loop till the switch is activaled
if(count > max_count_Normal )
count = 0; // Helps makes sure our next normal glow doesnt start in an arbitrary place on the table
} else {
digitalWrite(ledPin, HIGH); // turn LED ON ~ Means our wind Switch worked
delay(30);
digitalWrite(ledPin, LOW);
for ( int i=0; i <= 60; i++) { // This for loop runs untill the flicker table finishes
analogWrite(ledCandle, Flicker_table[countTwo]);
countTwo++;
if(countTwo > max_count ){
countTwo = 0; // Helps makes sure our next flicker doesnt start in an arbitrary place on the table
}
delay(40); // the delay for our flicker, make it faster to to make it flicker a little more violently
}
}
delay(40); // the delay for our normal glow
}
Here's a Picture of the board itself, as you can see, pretty simple::
Well I hope someone out there can put the code and/or info to some use! If you have any questions just email me, or send me a message on here. I'll upload a picture and maybe a video to youtube of the pumpkin in use in the next couple of days if people ask for it.