From 8b07d3fa00e0881f4d67e7ade74a236a483d7d76 Mon Sep 17 00:00:00 2001 From: Brian Huang Date: Fri, 13 Feb 2015 14:39:11 -0700 Subject: [PATCH 1/9] Updating for new project based SIK guide --- .gitignore | 28 + Circuit_01/Circuit_01.ino | 143 ------ Circuit_02/Circuit_02.ino | 173 ------- Circuit_03/Circuit_03.ino | 317 ------------ Circuit_04/Circuit_04.ino | 328 ------------ Circuit_05/Circuit_05.ino | 172 ------- Circuit_06/Circuit_06.ino | 195 ------- Circuit_07/Circuit_07.ino | 182 ------- Circuit_08/Circuit_08.ino | 139 ----- Circuit_09/Circuit_09.ino | 135 ----- Circuit_10/Circuit_10.ino | 161 ------ Circuit_11/Circuit_11.ino | 154 ------ Circuit_12/Circuit_12.ino | 217 -------- Circuit_13/Circuit_13.ino | 119 ----- Circuit_14/Circuit_14.ino | 379 -------------- Circuit_15/Circuit_15.ino | 209 -------- Circuit_16/Circuit_16.ino | 563 --------------------- Project01_LightHouse/01-Blink/01-Blink.ino | 0 README.md | 59 +-- 19 files changed, 30 insertions(+), 3643 deletions(-) create mode 100644 .gitignore delete mode 100644 Circuit_01/Circuit_01.ino delete mode 100644 Circuit_02/Circuit_02.ino delete mode 100644 Circuit_03/Circuit_03.ino delete mode 100644 Circuit_04/Circuit_04.ino delete mode 100644 Circuit_05/Circuit_05.ino delete mode 100644 Circuit_06/Circuit_06.ino delete mode 100644 Circuit_07/Circuit_07.ino delete mode 100644 Circuit_08/Circuit_08.ino delete mode 100644 Circuit_09/Circuit_09.ino delete mode 100644 Circuit_10/Circuit_10.ino delete mode 100644 Circuit_11/Circuit_11.ino delete mode 100644 Circuit_12/Circuit_12.ino delete mode 100644 Circuit_13/Circuit_13.ino delete mode 100644 Circuit_14/Circuit_14.ino delete mode 100644 Circuit_15/Circuit_15.ino delete mode 100644 Circuit_16/Circuit_16.ino create mode 100644 Project01_LightHouse/01-Blink/01-Blink.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8bd026 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app diff --git a/Circuit_01/Circuit_01.ino b/Circuit_01/Circuit_01.ino deleted file mode 100644 index 497358f..0000000 --- a/Circuit_01/Circuit_01.ino +++ /dev/null @@ -1,143 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 01 - -BLINKING A LED - - Turn an LED on for one second, off for one second, - and repeat forever. - -Hardware connections: - - Most Arduinos already have an LED and resistor connected to - pin 13, so you may not need any additional circuitry. - - But if you'd like to connect a second LED to pin 13, or use - a different pin, follow these steps: - - Connect the positive side of your LED (longer leg) to Arduino - digital pin 13 (or another digital pin, don't forget to change - the code to match). - - Connect the negative side of your LED (shorter leg) to a - 330 Ohm resistor (orange-orange-brown). Connect the other side - of the resistor to ground. - - pin 13 _____ + LED - _____ 330 Ohm _____ GND - - (We always use resistors between the Arduino and and LEDs - to keep the LEDs from burning out due to too much current.) - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// Welcome to Arduino! - -// If you're brand-new to this, there will be some new things to -// learn, but we'll jump right in and explain things as we go. - -// The Arduino is a tiny computer that runs programs called -// "sketches". These are text files written using instructions -// the computer understances. You're reading a sketch right now. - -// Sketches have computer code in them, but also (hopefully) -// "comments" that explain what the code does. Comments and code -// will have different colors in the editor so you can tell them -// apart. - -// This is a comment - anything on a line after "//" is ignored -// by the computer. - -/* This is also a comment - this one can be multi-line, but it -must start and end with these characters */ - -// A "function" is a named block of code, that performs a specific, -// well, function. Many useful functions are already built-in to -// the Arduino; others you'll name and write yourself for your -// own purposes. - -// All Arduino sketches MUST have two specific functions, named -// "setup()" and "loop()". The Arduino runs these functions -// automatically when it starts up or if you press the reset -// button. You'll typically fill these function "shells" with your -// own code. Let's get started! - - -// The setup() function runs once when the sketch starts. -// You'll use it for things you need to do first, or only once: - - -void setup() -{ - // The Arduino has 13 digital input/output pins. These pins - // can be configured as either inputs or outputs. We set this - // up with a built-in function called pinMode(). - - // The pinMode() function takes two values, which you type in - // the parenthesis after the function name. The first value is - // a pin number, the second value is the word INPUT or OUTPUT. - - // Here we'll set up pin 13 (the one connected to a LED) to be - // an output. We're doing this because we need to send voltage - // "out" of the Arduino to the LED. - - pinMode(13, OUTPUT); - - // By the way, the Arduino offers many useful built-in functions - // like this one. You can find information on all of them at the - // Arduino website: http://arduino.cc/en/Reference -} - - -// After setup() finishes, the loop() function runs over and over -// again, forever (or until you turn off or reset the Arduino). -// This is usually where the bulk of your program lives: - - -void loop() -{ - // The 13 digital pins on your Arduino are great at inputting - // and outputting on/off, or "digital" signals. These signals - // will always be either 5 Volts (which we call "HIGH"), or - // 0 Volts (which we call "LOW"). - - // Because we have an LED connected to pin 13, if we make that - // output HIGH, the LED will get voltage and light up. If we make - // that output LOW, the LED will have no voltage and turn off. - - // digitalWrite() is the built-in function we use to make an - // output pin HIGH or LOW. It takes two values; a pin number, - // followed by the word HIGH or LOW: - - digitalWrite(13, HIGH); // Turn on the LED - - // delay() is a function that pauses for a given amount of time. - // It takes one value, the amount of time to wait, measured in - // milliseconds. There are 1000 milliseconds in a second, so if - // you delay(1000), it will pause for exactly one second: - - delay(1000); // Wait for one second - - digitalWrite(13, LOW); // Turn off the LED - - delay(1000); // Wait for one second - - // All together, the above code turns the LED on, waits one - // second, turns it off, and waits another second. - - // When the computer gets to the end of the loop() function, - // it starts loop() over again. So this program will continue - // blinking the LED on and off! - - // Try changing the 1000 in the above delay() functions to - // different numbers and see how it affects the timing. Smaller - // values will make the loop run faster. (Why?) -} - diff --git a/Circuit_02/Circuit_02.ino b/Circuit_02/Circuit_02.ino deleted file mode 100644 index 2094b93..0000000 --- a/Circuit_02/Circuit_02.ino +++ /dev/null @@ -1,173 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 02 - -POTENTIOMETER - - Measure the position of a potentiometer and use it to - control the blink rate of an LED. Turn the knob to make - it blink faster or slower! - -What's a potentiometer? - - A potentiometer, or "pot" for short, is a control knob. - It's the same type of control you'd use to change volume, - dim a lamp, etc. A potentiometer changes resistance as it - is turned. By using it as a "voltage divider", the Arduino - can sense the position of the knob, and use that value to - control whatever you wish (like the blink rate of an LED, - as we're doing here). - -Hardware connections: - - Potentiometer: - - Potentiometers have three pins. When we're using it as a - voltage divider, we connect the outside pins to power and - ground. The middle pin will be the signal (a voltage which - varies from 0 Volts to 5 Volts depending on the position of - the knob). - - Connect the middle pin to ANALOG IN pin 0 on the Arduino. - Connect one of the outside pins to 5V. - Connect the other outside pin to GND. - - (TIP: if once your program is running, the knob feels - "backwards", you can swap the 5V and GND pins to reverse - the direction.) - - LED: - - Most Arduinos already have an LED and resistor connected to - pin 13, so you may not need any additional circuitry. - - But if you'd like to connect a second LED to pin 13, or use - a different pin, follow these steps: - - Connect the positive side of your LED (longer leg) to - Arduino digital pin 13 (or another digital pin, but don't - forget to change the code to match). - - Connect the negative side of your LED (shorter leg) to a - 330 Ohm resistor (orange-orange-brown). - - Connect the other side of the resistor to ground. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// Welcome back! In this sketch we'll start using "variables". - -// A variable is a named number. We'll often use these to store -// numbers that change, such as measurements from the outside -// world, or to make a sketch easier to understand (sometimes a -// descriptive name makes more sense than looking at a number). - -// Variables can be different "data types", which is the kind of -// number we're using (can it be negative? Have a decimal point?) -// We'll introduce more data types later, but for the moment we'll -// stick with good old "integers" (called "int" in your sketch). - -// Integers are whole numbers (0, 3, 5643), can be negative, and -// for reasons we won't go into right now, can range from -32768 -// to 32767. (Don't worry, if you need to work with larger numbers, -// there are other data types for that. See: -// http://arduino.cc/en/Reference/VariableDeclaration -// for a list of all the data types you can use). - -// You must "declare" variables before you use them, so that the -// computer knows about them. Here we'll declare two integer -// variables, and at the same time, initialize them to specific -// values. We're doing this so that further down, we can refer to -// the pins by name rather than number. - -// Note that variable names are case-sensitive! If you get an -// "(variable) was not declared in this scope" error, double-check -// that you typed the name correctly. - -// Here we're creating a variable called "sensorPin" of type "int" -// and initializing it to have the value "0": - -int sensorPin = 0; // The potentiometer is connected to - // analog pin 0 - -int ledPin = 13; // The LED is connected to digital pin 13 - -// One more thing. If you declare variables outside of a function, -// as we have here, they are called "global variables" and can be -// seen by all the functions. If you declare variables within a -// function, they can only be seen within that function. It's good -// practice to "limit the scope" of a variable whenever possible, -// but as we're getting started, global variables are just fine. - - -void setup() // this function runs once when the sketch starts up -{ - // We'll be using pin 13 to light a LED, so we must configure it - // as an output. - - // Because we already created a variable called ledPin, and - // set it equal to 13, we can use "ledPin" in place of "13". - // This makes the sketch easier to follow. - - pinMode(ledPin, OUTPUT); - - // The above line is the same as "pinMode(13, OUTPUT);" - - // You might be wondering why we're not also configuring - // sensorPin as an input. The reason is that this is an - // "analog in" pin. These pins have the special ability to - // read varying voltages from sensors like the potentiometer. - // Since they're always used as inputs, there is no need to - // specifically configure them. -} - - -void loop() // this function runs repeatedly after setup() finishes -{ - // First we'll declare another integer variable - // to store the value of the potentiometer: - - int sensorValue; - - // The potentiometer is set up as a voltage divider, so that - // when you turn it, the voltage on the center pin will vary - // from 0V to 5V. We've connected the center pin on the - // potentiometer to the Arduino's analog input 0. - - // The Arduino can read external voltages on the analog input - // pins using a built-in function called analogRead(). This - // function takes one input value, the analog pin we're using - // (sensorPin, which we earlier set to 0). It returns an integer - // number that ranges from 0 (0 Volts) to 1023 (5 Volts). - // We're sticking this value into the sensorValue variable: - - sensorValue = analogRead(sensorPin); - - // Now we'll blink the LED like in the first example, but we'll - // use the sensorValue variable to change the blink speed - // (the smaller the number, the faster it will blink). - - // Note that we're using the ledPin variable here as well: - - digitalWrite(ledPin, HIGH); // Turn the LED on - - delay(sensorValue); // Pause for sensorValue - // milliseconds - - digitalWrite(ledPin, LOW); // Turn the LED off - - delay(sensorValue); // Pause for sensorValue - // milliseconds - - // Remember that loop() repeats forever, so we'll do all this - // again and again. -} - diff --git a/Circuit_03/Circuit_03.ino b/Circuit_03/Circuit_03.ino deleted file mode 100644 index 149ce22..0000000 --- a/Circuit_03/Circuit_03.ino +++ /dev/null @@ -1,317 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 03 - -RGB LED - - Make an RGB LED display a rainbow of colors! - -Hardware connections: - - An RGB LED is actually three LEDs (red, green, and blue) in - one package. When you run them at different brightnesses, - the red, green and blue mix to form new colors. - - Starting at the flattened edge of the flange on the LED, - the pins are ordered RED, COMMON, GREEN, BLUE. - - Connect RED to a 330 Ohm resistor. Connect the other end - of the resistor to Arduino digital pin 9. - - Connect COMMON pin to GND. - - Connect GREEN to a 330 Ohm resistor. Connect the other end - of the resistor to Arduino digital pin 10. - - Connect BLUE to a 330 Ohm resistor. Connect the other end - of the resistor to Arduino digital pin 11. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// First we'll define the pins by name to make the sketch -// easier to follow. - -// Here's a new trick: putting the word "const" in front of a -// variable indicates that this is a "constant" value that will -// never change. (You don't have to do this, but if you do, the -// Arduino will give you a friendly warning if you accidentally -// try to change the value, so it's considered good form.) - -const int RED_PIN = 9; -const int GREEN_PIN = 10; -const int BLUE_PIN = 11; - -// This variable controls how fast we loop through the colors. -// (Try changing this to make the fading faster or slower.) - -int DISPLAY_TIME = 100; // In milliseconds - - -void setup() -{ - // Here we'll configure the Arduino pins we're using to - // drive the LED to be outputs: - - pinMode(RED_PIN, OUTPUT); - pinMode(GREEN_PIN, OUTPUT); - pinMode(BLUE_PIN, OUTPUT); -} - - -void loop() -{ - // In this sketch, we'll start writing our own functions. - // This makes the sketch easier to follow by dividing up - // the sketch into sections, and not having everything in - // setup() or loop(). - - // We'll show you two ways to run the RGB LED. - - // The first way is to turn the individual LEDs (red, blue, - // and green) on and off in various combinations. This gives you - // a total of eight colors (if you count "black" as a color). - - // We've written a function called mainColors() that steps - // through all eight of these colors. We're only "calling" the - // function here (telling it to run). The actual function code - // is further down in the sketch. - - mainColors(); - - // The above function turns the individual LEDs full-on and - // full-off. If you want to generate more than eight colors, - // you can do so by varying the brightness of the individual - // LEDs between full-on and full-off. - - // The analogWrite() function lets us do this. This function - // lets you dim a LED from full-off to full-on over 255 steps. - - // We've written a function called showSpectrum() that smoothly - // steps through all the colors. Again we're just calling it - // here; the actual code is further down in this sketch. - - showSpectrum(); -} - - -// Here's the mainColors() function we've written. - -// This function displays the eight "main" colors that the RGB LED -// can produce. If you'd like to use one of these colors in your -// own sketch, you cancopy and paste that section into your code. - -void mainColors() -{ - // Off (all LEDs off): - - digitalWrite(RED_PIN, LOW); - digitalWrite(GREEN_PIN, LOW); - digitalWrite(BLUE_PIN, LOW); - - delay(1000); - - // Red (turn just the red LED on): - - digitalWrite(RED_PIN, HIGH); - digitalWrite(GREEN_PIN, LOW); - digitalWrite(BLUE_PIN, LOW); - - delay(1000); - - // Green (turn just the green LED on): - - digitalWrite(RED_PIN, LOW); - digitalWrite(GREEN_PIN, HIGH); - digitalWrite(BLUE_PIN, LOW); - - delay(1000); - - // Blue (turn just the blue LED on): - - digitalWrite(RED_PIN, LOW); - digitalWrite(GREEN_PIN, LOW); - digitalWrite(BLUE_PIN, HIGH); - - delay(1000); - - // Yellow (turn red and green on): - - digitalWrite(RED_PIN, HIGH); - digitalWrite(GREEN_PIN, HIGH); - digitalWrite(BLUE_PIN, LOW); - - delay(1000); - - // Cyan (turn green and blue on): - - digitalWrite(RED_PIN, LOW); - digitalWrite(GREEN_PIN, HIGH); - digitalWrite(BLUE_PIN, HIGH); - - delay(1000); - - // Purple (turn red and blue on): - - digitalWrite(RED_PIN, HIGH); - digitalWrite(GREEN_PIN, LOW); - digitalWrite(BLUE_PIN, HIGH); - - delay(1000); - - // White (turn all the LEDs on): - - digitalWrite(RED_PIN, HIGH); - digitalWrite(GREEN_PIN, HIGH); - digitalWrite(BLUE_PIN, HIGH); - - delay(1000); -} - - -// Below are two more functions we've written, -// showSpectrum() and showRGB(). - -// showRGB() displays a single color on the RGB LED. -// You call showRGB() with the number of a color you want -// to display. - -// showSpectrum() steps through all the colors of the RGB LED, -// displaying a rainbow. showSpectrum() actually calls showRGB() -// over and over to do this. - -// We'll often break tasks down into individual functions like -// this, which makes your sketches easier to follow, and once -// you have a handy function, you can reuse it in your other -// programs. - - -// showSpectrum() - -// This function steps through all the colors of the RGB LED. -// It does this by stepping a variable from 0 to 768 (the total -// number of colors), and repeatedly calling showRGB() to display -// the individual colors. - -// In this function, we're using a "for() loop" to step a variable -// from one value to another, and perform a set of instructions -// for each step. For() loops are a very handy way to get numbers -// to count up or down. - -// Every for() loop has three statements separated by semicolons: - -// 1. Something to do before starting - -// 2. A test to perform; as long as it's true, -// it will keep looping - -// 3. Something to do after each loop (usually -// increase a variable) - -// For the for() loop below, these are the three statements: - -// 1. x = 0; Before starting, make x = 0. - -// 2. x < 768; While x is less than 768, run the -// following code. - -// 3. x++ Putting "++" after a variable means -// "add one to it". (You can also use "x = x + 1") - -// Every time you go through the loop, the statements following -// the loop (those within the brackets) will run. - -// And when the test in statement 2 is finally false, the sketch -// will continue. - - -void showSpectrum() -{ - int x; // define an integer variable called "x" - - // Now we'll use a for() loop to make x count from 0 to 767 - // (Note that there's no semicolon after this line! - // That's because the for() loop will repeat the next - // "statement", which in this case is everything within - // the following brackets {} ) - - for (x = 0; x < 768; x++) - - // Each time we loop (with a new value of x), do the following: - - { - showRGB(x); // Call RGBspectrum() with our new x - delay(10); // Delay for 10 ms (1/100th of a second) - } -} - - -// showRGB() - -// This function translates a number between 0 and 767 into a -// specific color on the RGB LED. If you have this number count -// through the whole range (0 to 767), the LED will smoothly -// change color through the entire spectrum. - -// The "base" numbers are: -// 0 = pure red -// 255 = pure green -// 511 = pure blue -// 767 = pure red (again) - -// Numbers between the above colors will create blends. For -// example, 640 is midway between 512 (pure blue) and 767 -// (pure red). It will give you a 50/50 mix of blue and red, -// resulting in purple. - -// If you count up from 0 to 767 and pass that number to this -// function, the LED will smoothly fade between all the colors. -// (Because it starts and ends on pure red, you can start over -// at 0 without any break in the spectrum). - - -void showRGB(int color) -{ - int redIntensity; - int greenIntensity; - int blueIntensity; - - // Here we'll use an "if / else" statement to determine which - // of the three (R,G,B) zones x falls into. Each of these zones - // spans 255 because analogWrite() wants a number from 0 to 255. - - // In each of these zones, we'll calculate the brightness - // for each of the red, green, and blue LEDs within the RGB LED. - - if (color <= 255) // zone 1 - { - redIntensity = 255 - color; // red goes from on to off - greenIntensity = color; // green goes from off to on - blueIntensity = 0; // blue is always off - } - else if (color <= 511) // zone 2 - { - redIntensity = 0; // red is always off - greenIntensity = 255 - (color - 256); // green on to off - blueIntensity = (color - 256); // blue off to on - } - else // color >= 512 // zone 3 - { - redIntensity = (color - 512); // red off to on - greenIntensity = 0; // green is always off - blueIntensity = 255 - (color - 512); // blue on to off - } - - // Now that the brightness values have been set, command the LED - // to those values - - analogWrite(RED_PIN, redIntensity); - analogWrite(BLUE_PIN, blueIntensity); - analogWrite(GREEN_PIN, greenIntensity); -} diff --git a/Circuit_04/Circuit_04.ino b/Circuit_04/Circuit_04.ino deleted file mode 100644 index b375c29..0000000 --- a/Circuit_04/Circuit_04.ino +++ /dev/null @@ -1,328 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 04 - -MULTIPLE LEDs - - Make eight LEDs dance. Dance LEDs, dance! - -Hardware connections: - - You'll need eight LEDs, and eight 330 Ohm resistors - (orange-orange-brown). - - For each LED, connect the negative side (shorter leg) - to a 330 Ohm resistor. - - Connect the other side of the resistors to GND. - - Connect the positive side (longer leg) of the LEDs - to Arduino digital pins 2 through 9. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// To keep track of all the LED pins, we'll use an "array". -// An array lets you store a group of variables, and refer to them -// by their position, or "index". Here we're creating an array of -// eight integers, and initializing them to a set of values: - -int ledPins[] = {2,3,4,5,6,7,8,9}; - -// The first element of an array is index 0. -// We've put the value "2" in index 0, "3" in index 1, etc. -// The final index in the above array is 7, which contains -// the value "9". - -// We're using the values in this array to specify the pin numbers -// that the eight LEDs are connected to. LED 0 is connected to -// pin 2, LED 1 is connected to pin 3, etc. - - -void setup() -{ - int index; - - // In this sketch, we'll use "for() loops" to step variables from - // one value to another, and perform a set of instructions for - // each step. For() loops are a very handy way to get numbers to - // count up or down. - - // Every for() loop has three statements separated by - // semicolons (;): - - // 1. Something to do before starting - // 2. A test to perform; as long as it's true, keep looping - // 3. Something to do after each loop (increase a variable) - - // For the for() loop below, these are the three statements: - - // 1. index = 0; Before starting, make index = 0. - // 2. index <= 7; If index is less or equal to 7, - // run the following code. - // (When index = 8, continue with the sketch.) - // 3. index++ Putting "++" after a variable means - // "add one to it". - // (You can also use "index = index + 1".) - - // Every time you go through the loop, the statements following - // the for() (within the brackets) will run. - - // When the test in statement 2 is finally false, the sketch - // will continue. - - - // Here we'll use a for() loop to initialize all the LED pins - // to outputs. This is much easier than writing eight separate - // statements to do the same thing. - - // This for() loop will make index = 0, then run the pinMode() - // statement within the brackets. It will then do the same thing - // for index = 2, index = 3, etc. all the way to index = 7. - - for(index = 0; index <= 7; index++) - { - pinMode(ledPins[index],OUTPUT); - // ledPins[index] is replaced by the value in the array. - // For example, ledPins[0] is 2 - } -} - - -void loop() -{ - // This loop() calls functions that we've written further below. - // We've disabled some of these by commenting them out (putting - // "//" in front of them). To try different LED displays, remove - // the "//" in front of the ones you'd like to run, and add "//" - // in front of those you don't to comment out (and disable) those - // lines. - - oneAfterAnotherNoLoop(); // Light up all the LEDs in turn - - //oneAfterAnotherLoop(); // Same as oneAfterAnotherNoLoop, - // but with much less typing - - //oneOnAtATime(); // Turn on one LED at a time, - // scrolling down the line - - //pingPong(); // Light the LEDs middle to the edges - - //marquee(); // Chase lights like you see on signs - - //randomLED(); // Blink LEDs randomly -} - - -/* -oneAfterAnotherNoLoop() - -This function will light one LED, delay for delayTime, then light -the next LED, and repeat until all the LEDs are on. It will then -turn them off in the reverse order. - -This function does NOT use a for() loop. We've done it the hard way -to show you how much easier life can be when you use for() loops. -Take a look at oneAfterAnotherLoop() further down, which does -exactly the same thing with much less typing. -*/ - -void oneAfterAnotherNoLoop() -{ - int delayTime = 100; // time (milliseconds) to pause between LEDs - // make this smaller for faster switching - - // turn all the LEDs on: - - digitalWrite(ledPins[0], HIGH); //Turns on LED #0 (pin 2) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[1], HIGH); //Turns on LED #1 (pin 3) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[2], HIGH); //Turns on LED #2 (pin 4) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[3], HIGH); //Turns on LED #3 (pin 5) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[4], HIGH); //Turns on LED #4 (pin 6) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[5], HIGH); //Turns on LED #5 (pin 7) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[6], HIGH); //Turns on LED #6 (pin 8) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[7], HIGH); //Turns on LED #7 (pin 9) - delay(delayTime); //wait delayTime milliseconds - - // turn all the LEDs off: - - digitalWrite(ledPins[7], LOW); //Turn off LED #7 (pin 9) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[6], LOW); //Turn off LED #6 (pin 8) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[5], LOW); //Turn off LED #5 (pin 7) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[4], LOW); //Turn off LED #4 (pin 6) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[3], LOW); //Turn off LED #3 (pin 5) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[2], LOW); //Turn off LED #2 (pin 4) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[1], LOW); //Turn off LED #1 (pin 3) - delay(delayTime); //wait delayTime milliseconds - digitalWrite(ledPins[0], LOW); //Turn off LED #0 (pin 2) - delay(delayTime); //wait delayTime milliseconds -} - - -/* -oneAfterAnotherLoop() - -This function does exactly the same thing as oneAfterAnotherNoLoop(), -but it takes advantage of for() loops and the array to do it with -much less typing. -*/ - -void oneAfterAnotherLoop() -{ - int index; - int delayTime = 100; // milliseconds to pause between LEDs - // make this smaller for faster switching - - // Turn all the LEDs on: - - // This for() loop will step index from 0 to 7 - // (putting "++" after a variable means add one to it) - // and will then use digitalWrite() to turn that LED on. - - for(index = 0; index <= 7; index++) - { - digitalWrite(ledPins[index], HIGH); - delay(delayTime); - } - - // Turn all the LEDs off: - - // This for() loop will step index from 7 to 0 - // (putting "--" after a variable means subtract one from it) - // and will then use digitalWrite() to turn that LED off. - - for(index = 7; index >= 0; index--) - { - digitalWrite(ledPins[index], LOW); - delay(delayTime); - } -} - - -/* -oneOnAtATime() - -This function will step through the LEDs, -lighting only one at at time. -*/ - -void oneOnAtATime() -{ - int index; - int delayTime = 100; // milliseconds to pause between LEDs - // make this smaller for faster switching - - // step through the LEDs, from 0 to 7 - - for(index = 0; index <= 7; index++) - { - digitalWrite(ledPins[index], HIGH); // turn LED on - delay(delayTime); // pause to slow down - digitalWrite(ledPins[index], LOW); // turn LED off - } -} - - -/* -pingPong() - -This function will step through the LEDs, -lighting one at at time in both directions. -*/ - -void pingPong() -{ - int index; - int delayTime = 100; // milliseconds to pause between LEDs - // make this smaller for faster switching - - // step through the LEDs, from 0 to 7 - - for(index = 0; index <= 7; index++) - { - digitalWrite(ledPins[index], HIGH); // turn LED on - delay(delayTime); // pause to slow down - digitalWrite(ledPins[index], LOW); // turn LED off - } - - // step through the LEDs, from 7 to 0 - - for(index = 7; index >= 0; index--) - { - digitalWrite(ledPins[index], HIGH); // turn LED on - delay(delayTime); // pause to slow down - digitalWrite(ledPins[index], LOW); // turn LED off - } -} - - -/* -marquee() - -This function will mimic "chase lights" like those around signs. -*/ - -void marquee() -{ - int index; - int delayTime = 200; // milliseconds to pause between LEDs - // Make this smaller for faster switching - - // Step through the first four LEDs - // (We'll light up one in the lower 4 and one in the upper 4) - - for(index = 0; index <= 3; index++) // Step from 0 to 3 - { - digitalWrite(ledPins[index], HIGH); // Turn a LED on - digitalWrite(ledPins[index+4], HIGH); // Skip four, and turn that LED on - delay(delayTime); // Pause to slow down the sequence - digitalWrite(ledPins[index], LOW); // Turn the LED off - digitalWrite(ledPins[index+4], LOW); // Skip four, and turn that LED off - } -} - - -/* -randomLED() - -This function will turn on random LEDs. Can you modify it so it -also lights them for random times? -*/ - -void randomLED() -{ - int index; - int delayTime; - - // The random() function will return a semi-random number each - // time it is called. See http://arduino.cc/en/Reference/Random - // for tips on how to make random() even more random. - - index = random(8); // pick a random number between 0 and 7 - delayTime = 100; - - digitalWrite(ledPins[index], HIGH); // turn LED on - delay(delayTime); // pause to slow down - digitalWrite(ledPins[index], LOW); // turn LED off -} - diff --git a/Circuit_05/Circuit_05.ino b/Circuit_05/Circuit_05.ino deleted file mode 100644 index f793076..0000000 --- a/Circuit_05/Circuit_05.ino +++ /dev/null @@ -1,172 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 05 - -PUSH BUTTONS - - Use pushbuttons for digital input - - Previously we've used the analog pins for input, now we'll use - the digital pins for input as well. Because digital pins only - know about HIGH and LOW signals, they're perfect for interfacing - to pushbuttons and switches that also only have "on" and "off" - states. - - We'll connect one side of the pushbutton to GND, and the other - side to a digital pin. When we press down on the pushbutton, - the pin will be connected to GND, and therefore will be read - as "LOW" by the Arduino. - - But wait - what happens when you're not pushing the button? - In this state, the pin is disconnected from everything, which - we call "floating". What will the pin read as then, HIGH or LOW? - It's hard to say, because there's no solid connection to either - 5 Volts or GND. The pin could read as either one. - - To deal with this issue, we'll connect a small (10K, or 10,000 Ohm) - resistance between the pin and 5 Volts. This "pullup" resistor - will ensure that when you're NOT pushing the button, the pin will - still have a weak connection to 5 Volts, and therefore read as - HIGH. - - (Advanced: when you get used to pullup resistors and know when - they're required, you can activate internal pullup resistors - on the ATmega processor in the Arduino. See - http://arduino.cc/en/Tutorial/DigitalPins for information.) - -Hardware connections: - - Pushbuttons: - - Pushbuttons have two contacts that are connected if you're - pushing the button, and disconnected if you're not. - - The pushbuttons we're using have four pins, but two pairs - of these are connected together. The easiest way to hook up - the pushbutton is to connect two wires to any opposite corners. - - Connect any pin on pushbutton 1 to ground (GND). - Connect the opposite diagonal pin of the pushbutton to - digital pin 2. - - Connect any pin on pushbutton 2 to ground (GND). - Connect the opposite diagonal pin of the pushbutton to - digital pin 3. - - Also connect 10K resistors (brown/black/red) between - digital pins 2 and 3 and GND. These are called "pullup" - resistors. They ensure that the input pin will be either - 5V (unpushed) or GND (pushed), and not somewhere in between. - (Remember that unlike analog inputs, digital inputs are only - HIGH or LOW.) - - LED: - - Most Arduinos, including the Uno, already have an LED - and resistor connected to pin 13, so you don't need any - additional circuitry. - - But if you'd like to connect a second LED to pin 13, - - Connect the positive side of your LED to Arduino digital pin 13 - Connect the negative side of your LED to a 330 Ohm resistor - Connect the other side of the resistor to ground - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// First we'll set up constants for the pin numbers. -// This will make it easier to follow the code below. - -const int button1Pin = 2; // pushbutton 1 pin -const int button2Pin = 3; // pushbutton 2 pin -const int ledPin = 13; // LED pin - - -void setup() -{ - // Set up the pushbutton pins to be an input: - pinMode(button1Pin, INPUT); - pinMode(button2Pin, INPUT); - - // Set up the LED pin to be an output: - pinMode(ledPin, OUTPUT); -} - - -void loop() -{ - int button1State, button2State; // variables to hold the pushbutton states - - // Since a pushbutton has only two states (pushed or not pushed), - // we've run them into digital inputs. To read an input, we'll - // use the digitalRead() function. This function takes one - // parameter, the pin number, and returns either HIGH (5V) - // or LOW (GND). - - // Here we'll read the current pushbutton states into - // two variables: - - button1State = digitalRead(button1Pin); - button2State = digitalRead(button2Pin); - - // Remember that if the button is being pressed, it will be - // connected to GND. If the button is not being pressed, - // the pullup resistor will connect it to 5 Volts. - - // So the state will be LOW when it is being pressed, - // and HIGH when it is not being pressed. - - // Now we'll use those states to control the LED. - // Here's what we want to do: - - // "If either button is being pressed, light up the LED" - // "But, if BOTH buttons are being pressed, DON'T light up the LED" - - // Let's translate that into computer code. The Arduino gives you - // special logic functions to deal with true/false logic: - - // A == B means "EQUIVALENT". This is true if both sides are the same. - // A && B means "AND". This is true if both sides are true. - // A || B means "OR". This is true if either side is true. - // !A means "NOT". This makes anything after it the opposite (true or false). - - // We can use these operators to translate the above sentences - // into logic statements (Remember that LOW means the button is - // being pressed) - - // "If either button is being pressed, light up the LED" - // becomes: - // if ((button1State == LOW) || (button2State == LOW)) // light the LED - - // "If BOTH buttons are being pressed, DON'T light up the LED" - // becomes: - // if ((button1State == LOW) && (button2State == LOW)) // don't light the LED - - // Now let's use the above functions to combine them into one statement: - - if (((button1State == LOW) || (button2State == LOW)) // if we're pushing button 1 OR button 2 - && ! // AND we're NOT - ((button1State == LOW) && (button2State == LOW))) // pushing button 1 AND button 2 - // then... - { - digitalWrite(ledPin, HIGH); // turn the LED on - } - else - { - digitalWrite(ledPin, LOW); // turn the LED off - } - - // As you can see, logic operators can be combined to make - // complex decisions! - - // Don't forget that we use = when we're assigning a value, - // and use == when we're testing a value for equivalence. -} diff --git a/Circuit_06/Circuit_06.ino b/Circuit_06/Circuit_06.ino deleted file mode 100644 index 785d235..0000000 --- a/Circuit_06/Circuit_06.ino +++ /dev/null @@ -1,195 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 06 - -PHOTO RESISTOR - - Use a photoresistor (light sensor) to control the brightness - of a LED. - -Hardware connections: - - Photo resistor: - - Connect one side of the photoresistor to 5 Volts (5V). - Connect the other side of the photoresistor to ANALOG pin 0. - Connect a 10K resistor between ANALOG pin 0 and GND. - - This creates a voltage divider, with the photoresistor one - of the two resistors. The output of the voltage divider - (connected to A0) will vary with the light level. - - LED: - - Connect the positive side (long leg) of the LED to - digital pin 9. (To vary the brightness, this pin must - support PWM, which is indicated by "~" or "PWM" on the - Arduino itself.) - - Connect the negative side of the LED (short leg) to a - 330 Ohm resistor. - - Connect the other side of the resistor to GND. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// As usual, we'll create constants to name the pins we're using. -// This will make it easier to follow the code below. - -const int sensorPin = 0; -const int ledPin = 9; - -// We'll also set up some global variables for the light level: - -int lightLevel, high = 0, low = 1023; - - -void setup() -{ - // We'll set up the LED pin to be an output. - // (We don't need to do anything special to use the analog input.) - - pinMode(ledPin, OUTPUT); -} - - -void loop() -{ - // Just as we've done in the past, we'll use the analogRead() - // function to measure the voltage coming from the photoresistor - // resistor pair. This number can range between 0 (0 Volts) and - // 1023 (5 Volts), but this circuit will have a smaller range - // between dark and light. - - lightLevel = analogRead(sensorPin); - - // We now want to use this number to control the brightness of - // the LED. But we have a problem: the analogRead() function - // returns values between 0 and 1023, and the analogWrite() - // function wants values from 0 to 255. - - // We can solve this by using two handy functions called map() - // and constrain(). Map will change one range of values into - // another range. If we tell map() our "from" range is 0-1023, - // and our "to" range is 0-255, map() will squeeze the larger - // range into the smaller. (It can do this for any two ranges.) - - // lightLevel = map(lightLevel, 0, 1023, 0, 255); - - // Because map() could still return numbers outside the "to" - // range, (if they're outside the "from" range), we'll also use - // a function called constrain() that will "clip" numbers into - // a given range. If the number is above the range, it will reset - // it to be the highest number in the range. If the number is - // below the range, it will reset it to the lowest number. - // If the number is within the range, it will stay the same. - - // lightLevel = constrain(lightLevel, 0, 255); - - // Here's one last thing to think about. The circuit we made - // won't have a range all the way from 0 to 5 Volts. It will - // be a smaller range, such as 300 (dark) to 800 (light). - // If we just pass this number directly to map(), the LED will - // change brightness, but it will never be completely off or - // completely on. - - // You can fix this two ways, each of which we'll show - // in the functions below. Uncomment ONE of them to - // try it out: - - manualTune(); // manually change the range from light to dark - - //autoTune(); // have the Arduino do the work for us! - - // The above functions will alter lightLevel to be cover the - // range from full-on to full-off. Now we can adjust the - // brightness of the LED: - - analogWrite(ledPin, lightLevel); - - // The above statement will brighten the LED along with the - // light level. To do the opposite, replace "lightLevel" in the - // above analogWrite() statement with "255-lightLevel". - // Now you've created a night-light! -} - - -void manualTune() -{ - // As we mentioned above, the light-sensing circuit we built - // won't have a range all the way from 0 to 1023. It will likely - // be more like 300 (dark) to 800 (light). If you run this sketch - // as-is, the LED won't fully turn off, even in the dark. - - // You can accommodate the reduced range by manually - // tweaking the "from" range numbers in the map() function. - // Here we're using the full range of 0 to 1023. - // Try manually changing this to a smaller range (300 to 800 - // is a good guess), and try it out again. If the LED doesn't - // go completely out, make the low number larger. If the LED - // is always too bright, make the high number smaller. - - // Remember you're JUST changing the 0, 1023 in the line below! - - lightLevel = map(lightLevel, 0, 1023, 0, 255); - lightLevel = constrain(lightLevel, 0, 255); - - // Now we'll return to the main loop(), and send lightLevel - // to the LED. -} - - -void autoTune() -{ - // As we mentioned above, the light-sensing circuit we built - // won't have a range all the way from 0 to 1023. It will likely - // be more like 300 (dark) to 800 (light). - - // In the manualTune() function above, you need to repeatedly - // change the values and try the program again until it works. - // But why should you have to do that work? You've got a - // computer in your hands that can figure things out for itself! - - // In this function, the Arduino will keep track of the highest - // and lowest values that we're reading from analogRead(). - - // If you look at the top of the sketch, you'll see that we've - // initialized "low" to be 1023. We'll save anything we read - // that's lower than that: - - if (lightLevel < low) - { - low = lightLevel; - } - - // We also initialized "high" to be 0. We'll save anything - // we read that's higher than that: - - if (lightLevel > high) - { - high = lightLevel; - } - - // Once we have the highest and lowest values, we can stick them - // directly into the map() function. No manual tweaking needed! - - // One trick we'll do is to add a small offset to low and high, - // to ensure that the LED is fully-off and fully-on at the limits - // (otherwise it might flicker a little bit). - - lightLevel = map(lightLevel, low+30, high-30, 0, 255); - lightLevel = constrain(lightLevel, 0, 255); - - // Now we'll return to the main loop(), and send lightLevel - // to the LED. -} - - diff --git a/Circuit_07/Circuit_07.ino b/Circuit_07/Circuit_07.ino deleted file mode 100644 index e44dd27..0000000 --- a/Circuit_07/Circuit_07.ino +++ /dev/null @@ -1,182 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 07 - -TEMPERATURE SENSOR - - Use the "serial monitor" window to read a temperature sensor. - - The TMP36 is an easy-to-use temperature sensor that outputs - a voltage that's proportional to the ambient temperature. - You can use it for all kinds of automation tasks where you'd - like to know or control the temperature of something. - - More information on the sensor is available in the datasheet: - http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Temp/TMP35_36_37.pdf - - Even more exciting, we'll start using the Arduino's serial port - to send data back to your main computer! Up until now, we've - been limited to using simple LEDs for output. We'll see that - the Arduino can also easily output all kinds of text and data. - -Hardware connections: - - Be careful when installing the temperature sensor, as it is - almost identical to the transistors! The one you want has - a triangle logo and "TMP" in very tiny letters. The - ones you DON'T want will have "222" on them. - - When looking at the flat side of the temperature sensor - with the pins down, from left to right the pins are: - 5V, SIGNAL, and GND. - - Connect the 5V pin to 5 Volts (5V). - Connect the SIGNAL pin to ANALOG pin 0. - Connect the GND pin to ground (GND). - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - -// We'll use analog input 0 to measure the temperature sensor's -// signal pin. - -const int temperaturePin = 0; - - -void setup() -{ - // In this sketch, we'll use the Arduino's serial port - // to send text back to the main computer. For both sides to - // communicate properly, they need to be set to the same speed. - // We use the Serial.begin() function to initialize the port - // and set the communications speed. - - // The speed is measured in bits per second, also known as - // "baud rate". 9600 is a very commonly used baud rate, - // and will transfer about 10 characters per second. - - Serial.begin(9600); -} - - -void loop() -{ - // Up to now we've only used integer ("int") values in our - // sketches. Integers are always whole numbers (0, 1, 23, etc.). - // In this sketch, we'll use floating-point values ("float"). - // Floats can be fractional numbers such as 1.42, 2523.43121, etc. - - // We'll declare three floating-point variables - // (We can declare multiple variables of the same type on one line:) - - float voltage, degreesC, degreesF; - - // First we'll measure the voltage at the analog pin. Normally - // we'd use analogRead(), which returns a number from 0 to 1023. - // Here we've written a function (further down) called - // getVoltage() that returns the true voltage (0 to 5 Volts) - // present on an analog input pin. - - voltage = getVoltage(temperaturePin); - - // Now we'll convert the voltage to degrees Celsius. - // This formula comes from the temperature sensor datasheet: - - degreesC = (voltage - 0.5) * 100.0; - - // While we're at it, let's convert degrees Celsius to Fahrenheit. - // This is the classic C to F conversion formula: - - degreesF = degreesC * (9.0/5.0) + 32.0; - - // Now we'll use the serial port to print these values - // to the serial monitor! - - // To open the serial monitor window, upload your code, - // then click the "magnifying glass" button at the right edge - // of the Arduino IDE toolbar. The serial monitor window - // will open. - - // (NOTE: remember we said that the communication speed - // must be the same on both sides. Ensure that the baud rate - // control at the bottom of the window is set to 9600. If it - // isn't, change it to 9600.) - - // Also note that every time you upload a new sketch to the - // Arduino, the serial monitor window will close. It does this - // because the serial port is also used to upload code! - // When the upload is complete, you can re-open the serial - // monitor window. - - // To send data from the Arduino to the serial monitor window, - // we use the Serial.print() function. You can print variables - // or text (within quotes). - - Serial.print("voltage: "); - Serial.print(voltage); - Serial.print(" deg C: "); - Serial.print(degreesC); - Serial.print(" deg F: "); - Serial.println(degreesF); - - // These statements will print lines of data like this: - // "voltage: 0.73 deg C: 22.75 deg F: 72.96" - - // Note that all of the above statements are "print", except - // for the last one, which is "println". "Print" will output - // text to the SAME LINE, similar to building a sentence - // out of words. "Println" will insert a "carriage return" - // character at the end of whatever it prints, moving down - // to the NEXT line. - - delay(1000); // repeat once per second (change as you wish!) -} - - -float getVoltage(int pin) -{ - // This function has one input parameter, the analog pin number - // to read. You might notice that this function does not have - // "void" in front of it; this is because it returns a floating- - // point value, which is the true voltage on that pin (0 to 5V). - - // You can write your own functions that take in parameters - // and return values. Here's how: - - // To take in parameters, put their type and name in the - // parenthesis after the function name (see above). You can - // have multiple parameters, separated with commas. - - // To return a value, put the type BEFORE the function name - // (see "float", above), and use a return() statement in your code - // to actually return the value (see below). - - // If you don't need to get any parameters, you can just put - // "()" after the function name. - - // If you don't need to return a value, just write "void" before - // the function name. - - // Here's the return statement for this function. We're doing - // all the math we need to do within this statement: - - return (analogRead(pin) * 0.004882814); - - // This equation converts the 0 to 1023 value that analogRead() - // returns, into a 0.0 to 5.0 value that is the true voltage - // being read at that pin. -} - -// Other things to try with this code: - -// Turn on an LED if the temperature is above or below a value. - -// Read that threshold value from a potentiometer - now you've -// created a thermostat! - diff --git a/Circuit_08/Circuit_08.ino b/Circuit_08/Circuit_08.ino deleted file mode 100644 index c45c1a3..0000000 --- a/Circuit_08/Circuit_08.ino +++ /dev/null @@ -1,139 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 08 - -SINGLE SERVO - - Sweep a servo back and forth through its full range of motion. - - A "servo", short for servomotor, is a motor that includes - feedback circuitry that allows it to be commanded to move to - specific positions. This one is very small, but larger servos - are used extensively in robotics to control mechanical arms, - hands, etc. You could use it to make a (tiny) robot arm, - aircraft control surface, or anywhere something needs to be - moved to specific positions. - -Hardware connections: - - The servo has a cable attached to it with three wires. - Because the cable ends in a socket, you can use jumper wires - to connect between the Arduino and the servo. Just plug the - jumper wires directly into the socket. - - Connect the RED wire (power) to 5 Volts (5V) - Connect the WHITE wire (signal) to digital pin 9 - Connect the BLACK wire (ground) to ground (GND) - - Note that servos can use a lot of power, which can cause your - Arduino to reset or behave erratically. If you're using large - servos or many of them, it's best to provide them with their - own separate 5V supply. See this Arduino Forum thread for info: - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239464763 - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// If we had to write a sketch to control a servo from scratch, -// it would be a lot of work. Fortunately, others have done the -// hard work for you. We're going to include a "library" -// that has the functions needed to drive servos. - -// A library is an set of additional functions you can add to -// your sketch. Numerous libraries are available for many uses, -// see http://arduino.cc/en/Reference/Libraries for information -// on the standard libraries, and Google for others. When you're -// using a new part, chances are someone has written a library -// for it. - -#include // servo library - -// Once you "include" a library, you'll have access to those -// functions. You can find a list of the functions in the servo -// library at: http://arduino.cc/en/Reference/Servo -// Most libraries also have example sketches you can load from -// the "file/examples" menu. - -// Now we'll create a servo "object", called myservo. You should -// create one of these for each servo you want to control. -// You can control a maximum of twelve servos on the Uno -// using this library. (Other servo libraries may let you -// control more). Note that this library disables PWM on -// pins 9 and 10! - -Servo servo1; // servo control object - - -void setup() -{ - // We'll now "attach" the servo1 object to digital pin 9. - // If you want to control more than one servo, attach more - // servo objects to the desired pins (must be digital). - - // Attach tells the Arduino to begin sending control signals - // to the servo. Servos require a continuous stream of control - // signals, even if you're not currently moving them. - // While the servo is being controlled, it will hold its - // current position with some force. If you ever want to - // release the servo (allowing it to be turned by hand), - // you can call servo1.detach(). - - servo1.attach(9); -} - - -void loop() -{ - int position; - - // To control a servo, you give it the angle you'd like it - // to turn to. Servos cannot turn a full 360 degrees, but you - // can tell it to move anywhere between 0 and 180 degrees. - - // Change position at full speed: - - servo1.write(90); // Tell servo to go to 90 degrees - - delay(1000); // Pause to get it time to move - - servo1.write(180); // Tell servo to go to 180 degrees - - delay(1000); // Pause to get it time to move - - servo1.write(0); // Tell servo to go to 0 degrees - - delay(1000); // Pause to get it time to move - - // Change position at a slower speed: - - // To slow down the servo's motion, we'll use a for() loop - // to give it a bunch of intermediate positions, with 20ms - // delays between them. You can change the step size to make - // the servo slow down or speed up. Note that the servo can't - // move faster than its full speed, and you won't be able - // to update it any faster than every 20ms. - - // Tell servo to go to 180 degrees, stepping by two degrees - - for(position = 0; position < 180; position += 2) - { - servo1.write(position); // Move to next position - delay(20); // Short pause to allow it to move - } - - // Tell servo to go to 0 degrees, stepping by one degree - - for(position = 180; position >= 0; position -= 1) - { - servo1.write(position); // Move to next position - delay(20); // Short pause to allow it to move - } -} - diff --git a/Circuit_09/Circuit_09.ino b/Circuit_09/Circuit_09.ino deleted file mode 100644 index cb589ef..0000000 --- a/Circuit_09/Circuit_09.ino +++ /dev/null @@ -1,135 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 09 - -FLEX SENSOR - - Use the "flex sensor" to change the position of a servo - - In the previous sketch, we learned how to command a servo to - mode to different positions. In this sketch, we'll introduce - a new sensor, and use it to control the servo. - - A flex sensor is a plastic strip with a conductive coating. - When the strip is straight, the coating will be a certain - resistance. When the strip is bent, the particles in the coating - get further apart, increasing the resistance. You can use this - sensor to sense finger movement in gloves, door hinges, stuffed - animals, etc. See http://www.sparkfun.com/tutorials/270 for - more information. - -Hardware connections: - - Flex sensor: - - The flex sensor is the plastic strip with black stripes. - It senses bending away from the striped side. - - The flex sensor has two pins, and since it's a resistor, - the pins are interchangable. - - Connect one of the pins to ANALOG IN pin 0 on the Arduino. - Connect the same pin, through a 10K Ohm resistor (brown - black orange) to GND. - Connect the other pin to 5V. - - Servo: - - The servo has a cable attached to it with three wires. - Because the cable ends in a socket, you can use jumper wires - to connect between the Arduino and the servo. Just plug the - jumper wires directly into the socket. - - Connect the RED wire (power) to 5 Volts (5V) - Connect the WHITE wire (signal) to digital pin 9 - Connect the BLACK wire (ground) to ground (GND) - - Note that servos can use a lot of power, which can cause your - Arduino to reset or behave erratically. If you're using large - servos or many of them, it's best to provide them with their - own separate 5V supply. See this Arduino Forum thread for info: - http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239464763 - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// Include the servo library to add servo-control functions: - -#include - -// Create a servo "object", called servo1. Each servo object -// controls one servo (you can have a maximum of 12): - -Servo servo1; - -// Define the analog input pin to measure flex sensor position: - -const int flexpin = 0; - - -void setup() -{ - // Use the serial monitor window to help debug our sketch: - - Serial.begin(9600); - - // Enable control of a servo on pin 9: - - servo1.attach(9); -} - - -void loop() -{ - int flexposition; // Input value from the analog pin. - int servoposition; // Output value to the servo. - - // Read the position of the flex sensor (0 to 1023): - - flexposition = analogRead(flexpin); - - // Because the voltage divider circuit only returns a portion - // of the 0-1023 range of analogRead(), we'll map() that range - // to the servo's range of 0 to 180 degrees. The flex sensors - // we use are usually in the 600-900 range: - - servoposition = map(flexposition, 600, 900, 0, 180); - servoposition = constrain(servoposition, 0, 180); - - // Now we'll command the servo to move to that position: - - servo1.write(servoposition); - - // Because every flex sensor has a slightly different resistance, - // the 600-900 range may not exactly cover the flex sensor's - // output. To help tune our program, we'll use the serial port to - // print out our values to the serial monitor window: - - Serial.print("sensor: "); - Serial.print(flexposition); - Serial.print(" servo: "); - Serial.println(servoposition); - - // Note that all of the above lines are "print" except for the - // last line which is "println". This puts everything on the - // same line, then sends a final carriage return to move to - // the next line. - - // After you upload the sketch, turn on the serial monitor - // (the magnifying-glass icon to the right of the icon bar). - // You'll be able to see the sensor values. Bend the flex sensor - // and note its minimum and maximum values. If you replace the - // 600 and 900 in the map() function above, you'll exactly match - // the flex sensor's range with the servo's range. - - delay(20); // wait 20ms between servo updates -} - - diff --git a/Circuit_10/Circuit_10.ino b/Circuit_10/Circuit_10.ino deleted file mode 100644 index 1ae50a5..0000000 --- a/Circuit_10/Circuit_10.ino +++ /dev/null @@ -1,161 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 10 - -SOFT POTENTIOMETER - - Use the soft potentiometer to change the color - of the RGB LED - - The soft potentiometer is a neat input device that detects - pressure along its length. When you press it down with a finger - (it works best on a flat surface), it will change resistance - depending on where you're pressing it. You might use it to make - a piano or light dimmer; here we're going to use it to control - the color of an RGB LED. - -Hardware connections: - - Soft potentiometer: - - The soft potentiometer is the large plastic strip with three - pins. We'll be connecting it as a voltage divider, just like - we did with the knob-type potentiometer back in circuit #2. - - Connect the middle pin to ANALOG IN pin 0 on the Arduino. - Connect one side to 5V. - Connect the other side to GND. - Also connect a 10K resistor from the middle pin to GND. - - TIP: the soft pot will only work while you're actively - pressing on it; at other times it will "float" to random - values. To prevent this, we've added a 10K pull-down resistor - to the middle pin (output voltage). This will keep the output - at zero volts when the pot is not being pressed. - - RGB LED: - - An RGB LED is actually three LEDs (red, green, and blue) - in one package. When we run them at different brightnesses, - they mix to form new colors. - - Starting at the flattened edge of the flange on the LED, - the pins are ordered RED, COMMON, GREEN, BLUE. - - Connect RED to a 330 Ohm resistor. - Connect the other end of the resistor to Arduino digital pin 9. - - Connect COMMON to GND. - - Connect GREEN through a 330 Ohm resistor. - Connect the other end of the resistor to Arduino digital pin 10. - - Connect BLUE through a 330 Ohm resistor. - Connect the other end of the resistor to Arduino digital pin 11. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// Constants for LED connections (note that these must be -// PWM pins, which are marked with "PWM" or have a "~" symbol -// next to them on the board). - -const int RED_LED_PIN = 9; // Red LED Pin -const int GREEN_LED_PIN = 10; // Green LED Pin -const int BLUE_LED_PIN = 11; // Blue LED Pin - -const int SENSOR_PIN = 0; // Analog input pin - -// Global PWM brightness values for the RGB LED. -// These are global so both loop() and setRGB() can see them. - -int redValue, greenValue, blueValue; - - -void setup() -{ - // No need for any code here - // analogWrite() sets up the pins as outputs -} - - -void loop() -{ - int sensorValue; - - // Read the voltage from the softpot (0-1023) - - sensorValue = analogRead(0); - - // We've written a new function called setRGB() (further down - // in the sketch) that decodes sensorValue into a position - // on the RGB "rainbow", and sets the RGB LED to that color. - - setRGB(sensorValue); -} - - -// setRGB() -// Set a RGB LED to a position on the "rainbow" of all colors. -// RGBposition should be in the range of 0 to 1023 (such as -// from an analog input). - -void setRGB(int RGBposition) -{ - int mapRGB1, mapRGB2, constrained1, constrained2; - - // Here we take RGBposition and turn it into three RGB values. - - // The three values are computed so that the colors mix and - // produce a rainbow of colors across the 0-1023 input range. - - // For each channel (red green blue), we're creating a "peak" - // a third of the way along the 0-1023 range. By overlapping - // these peaks with each other, the colors are mixed together. - // This is most easily shown with a diagram: - // http://sfecdn.s3.amazonaws.com/education/SIK/SchematicImages/Misc/RGB_function.jpg - - // Create the red peak, which is centered at 0. - // (Because it's centered at 0, half is after 0, and half - // is before 1023): - - mapRGB1 = map(RGBposition, 0, 341, 255, 0); - constrained1 = constrain(mapRGB1, 0, 255); - - mapRGB2 = map(RGBposition, 682, 1023, 0, 255); - constrained2 = constrain(mapRGB2, 0, 255); - - redValue = constrained1 + constrained2; - - // Create the green peak, which is centered at 341 - // (one-third of the way to 1023): - - // Note that we've nested the functions by putting the map() - // function inside the constrain() function. This can make your - // code more compact, and requires fewer variabls: - - greenValue = constrain(map(RGBposition, 0, 341, 0, 255), 0, 255) - - constrain(map(RGBposition, 341, 682, 0,255), 0, 255); - - // Create the blue peak, which is centered at 682 - // (two-thirds of the way to 1023): - - blueValue = constrain(map(RGBposition, 341, 682, 0, 255), 0, 255) - - constrain(map(RGBposition, 682, 1023, 0, 255), 0, 255); - - // Now we have all three brightnesses, - // we just need to display the computed color: - - analogWrite(RED_LED_PIN, redValue); - analogWrite(GREEN_LED_PIN, greenValue); - analogWrite(BLUE_LED_PIN, blueValue); - - // Feel free to use this function in your own code! -} diff --git a/Circuit_11/Circuit_11.ino b/Circuit_11/Circuit_11.ino deleted file mode 100644 index 0c095e4..0000000 --- a/Circuit_11/Circuit_11.ino +++ /dev/null @@ -1,154 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 11 - -BUZZER - - Use the buzzer to play a song! - - The buzzer in your Inventor's Kit is an electromechanical - component you can use to make noise. Inside the buzzer is a - coil of wire and a small magnet. When current flows through - the coil, it becomes magnetized and pulls towards the magnet, - creating a tiny "click". When you do this thousands of times - per second, you create tones. - - The Arduino has a built-in command called tone() which clicks - the buzzer at a certain frequency. This sketch knows the - frequencies of the common notes, allowing you to create songs. - We're never going to let you down! - -Hardware connections: - - The buzzer has two pins. One is positive and one is negative. - The postitive pin is marked by a "+" symbol on both the top - and bottom of the buzzer. - - Connect the positive pin to Arduino digital pin 9. - (Note that this must be a PWM pin.) - Connect the negative pin to GND. - - Tip: if the buzzer doesn't fit into the breadboard easily, - try rotating it slightly to fit into diagonal holes. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -(This sketch was originally developed by D. Cuartielles for K3) -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - -/* -This sketch uses the buzzer to play songs. -The Arduino's tone() command will play notes of a given frequency. -We'll provide a function that takes in note characters (a-g), -and returns the corresponding frequency from this table: - - note frequency - c 262 Hz - d 294 Hz - e 330 Hz - f 349 Hz - g 392 Hz - a 440 Hz - b 494 Hz - C 523 Hz - -For more information, see http://arduino.cc/en/Tutorial/Tone -*/ - -const int buzzerPin = 9; - -// We'll set up an array with the notes we want to play -// change these values to make different songs! - -// Length must equal the total number of notes and spaces - -const int songLength = 18; - -// Notes is an array of text characters corresponding to the notes -// in your song. A space represents a rest (no tone) - -char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest - -// Beats is an array of values for each note and rest. -// A "1" represents a quarter-note, 2 a half-note, etc. -// Don't forget that the rests (spaces) need a length as well. - -int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2}; - -// The tempo is how fast to play the song. -// To make the song play faster, decrease this value. - -int tempo = 150; - - -void setup() -{ - pinMode(buzzerPin, OUTPUT); -} - - -void loop() -{ - int i, duration; - - for (i = 0; i < songLength; i++) // step through the song arrays - { - duration = beats[i] * tempo; // length of note/rest in ms - - if (notes[i] == ' ') // is this a rest? - { - delay(duration); // then pause for a moment - } - else // otherwise, play the note - { - tone(buzzerPin, frequency(notes[i]), duration); - delay(duration); // wait for tone to finish - } - delay(tempo/10); // brief pause between notes - } - - // We only want to play the song once, so we'll pause forever: - while(true){} - // If you'd like your song to play over and over, - // remove the above statement -} - - -int frequency(char note) -{ - // This function takes a note character (a-g), and returns the - // corresponding frequency in Hz for the tone() function. - - int i; - const int numNotes = 8; // number of notes we're storing - - // The following arrays hold the note characters and their - // corresponding frequencies. The last "C" note is uppercase - // to separate it from the first lowercase "c". If you want to - // add more notes, you'll need to use unique characters. - - // For the "char" (character) type, we put single characters - // in single quotes. - - char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' }; - int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523}; - - // Now we'll search through the letters in the array, and if - // we find it, we'll return the frequency for that note. - - for (i = 0; i < numNotes; i++) // Step through the notes - { - if (names[i] == note) // Is this the one? - { - return(frequencies[i]); // Yes! Return the frequency - } - } - return(0); // We looked through everything and didn't find it, - // but we still need to return a value, so return 0. -} - diff --git a/Circuit_12/Circuit_12.ino b/Circuit_12/Circuit_12.ino deleted file mode 100644 index 136e691..0000000 --- a/Circuit_12/Circuit_12.ino +++ /dev/null @@ -1,217 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 12 - -SPINNING A MOTOR - - Use a transistor to spin a motor at different speeds. - We'll also show you how to input data from the serial port - (see the serialSpeed() function below). - - Motors are the basis for thousands of things in our daily lives, - and the Arduino can control them. Here we'll use pulse-width - modulation (PWM) to vary the speed of a motor. - - The Arduino pins are strong enough to light small LEDs (up to - 40 milliAmps), but they're not strong enough to run motors and - other power-hungry parts. (This motor needs 50-100mA). - Because the motor needs more current than an Arduino pin can - provide, we'll use a transistor to do the heavy lifting. - A transistor is a solid-state switch. When we give it a small - amount of current, it can switch a much larger current. - The transistors in your kit (2N2222) can switch up to 200mA. - - You can turn a transistor on and off using the digitalWrite() - function, but you can also use the analogWrite() function to - vary the speed of the motor. The analogWrite() function pulses - a pin, varying the width of the pulse from 0% to 100%. We call - this technique "PWM", for "Pulse-Width Modulation". - - One thing to keep in mind is that when you lower the speed of - a motor using PWM, you're also reducing the torque (strength) - of the motor. For PWM values below 50 or so, the motor won't have - enough torque to start spinning. It will start spinning when you - raise the speed a bit. - -Hardware connections: - - Transistor: - - The transistor has three pins. Looking at the flat side with the - pins down, the order is COLLECTOR, BASE, EMITTER. - - Connect the black wire on the motor to the - COLLECTOR pin on the transistor. - - Connect the BASE pin through a 330 Ohm resistor to - digital pin 9. - - Connect the EMITTER pin to GND. - - Motor: - - You've already connected the black wire on the motor to the - COLLECTOR pin on the transistor. - - Connect the other (red) wire on the motor to 5V. - - Flyback diode: - - When the motor is spinning and suddenly turned off, the - magnetic field inside it collapses, generating a voltage spike. - This can damage the transistor. To prevent this, we use a - "flyback diode", which diverts the voltage spike "around" the - transistor. - - Connect the side of the diode with the band (cathode) to 5V - Connect the other side of the diode (anode) to the black wire - on the motor. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - -// We'll be controlling the motor from pin 9. -// This must be one of the PWM-capable pins. - -const int motorPin = 9; - - -void setup() -{ - // Set up the motor pin to be an output: - - pinMode(motorPin, OUTPUT); - - // Set up the serial port: - - Serial.begin(9600); -} - - -void loop() -{ - // Here we've used comments to disable some of the examples. - // To try different things, uncomment one of the following lines - // and comment the other ones. See the functions below to learn - // what they do and how they work. - - // motorOnThenOff(); - // motorOnThenOffWithSpeed(); - // motorAcceleration(); - serialSpeed(); -} - - -// This function turns the motor on and off like the blinking LED. -// Try different values to affect the timing. - -void motorOnThenOff() -{ - int onTime = 3000; // milliseconds to turn the motor on - int offTime = 3000; // milliseconds to turn the motor off - - digitalWrite(motorPin, HIGH); // turn the motor on (full speed) - delay(onTime); // delay for onTime milliseconds - digitalWrite(motorPin, LOW); // turn the motor off - delay(offTime); // delay for offTime milliseconds -} - - -// This function alternates between two speeds. -// Try different values to affect the timing and speed. - -void motorOnThenOffWithSpeed() -{ - int Speed1 = 200; // between 0 (stopped) and 255 (full speed) - int Time1 = 3000; // milliseconds for speed 1 - - int Speed2 = 50; // between 0 (stopped) and 255 (full speed) - int Time2 = 3000; // milliseconds to turn the motor off - - analogWrite(motorPin, Speed1); // turns the motor On - delay(Time1); // delay for onTime milliseconds - analogWrite(motorPin, Speed2); // turns the motor Off - delay(Time2); // delay for offTime milliseconds -} - - -// This function slowly accelerates the motor to full speed, -// then back down to zero. - -void motorAcceleration() -{ - int speed; - int delayTime = 20; // milliseconds between each speed step - - // accelerate the motor - - for(speed = 0; speed <= 255; speed++) - { - analogWrite(motorPin,speed); // set the new speed - delay(delayTime); // delay between speed steps - } - - // decelerate the motor - - for(speed = 255; speed >= 0; speed--) - { - analogWrite(motorPin,speed); // set the new speed - delay(delayTime); // delay between speed steps - } -} - - -// This function will let you type a speed into the serial -// monitor window. Open the serial monitor using the magnifying- -// glass icon at the top right of the Arduino window. Then -// type your desired speed into the small text entry bar at the -// top of the window and click "Send" or press return. The motor -// will then operate at that speed. The valid range is 0 to 255. - -void serialSpeed() -{ - int speed; - - Serial.println("Type a speed (0-255) into the box above,"); - Serial.println("then click [send] or press [return]"); - Serial.println(); // Print a blank line - - // In order to type out the above message only once, - // we'll run the rest of this function in an infinite loop: - - while(true) // "true" is always true, so this will loop forever. - { - // First we check to see if incoming data is available: - - while (Serial.available() > 0) - { - // If it is, we'll use parseInt() to pull out any numbers: - - speed = Serial.parseInt(); - - // Because analogWrite() only works with numbers from - // 0 to 255, we'll be sure the input is in that range: - - speed = constrain(speed, 0, 255); - - // We'll print out a message to let you know that the - // number was received: - - Serial.print("Setting speed to "); - Serial.println(speed); - - // And finally, we'll set the speed of the motor! - - analogWrite(motorPin, speed); - } - } -} - - - diff --git a/Circuit_13/Circuit_13.ino b/Circuit_13/Circuit_13.ino deleted file mode 100644 index 9371062..0000000 --- a/Circuit_13/Circuit_13.ino +++ /dev/null @@ -1,119 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 13 - -RELAYS - - Use a transistor to drive a relay - - A relay is a electrically-controlled mechanical switch. - It can control much more voltage and current than an Arduino pin - (or the transistor included in your kit) can. If you want to use - the Arduino to control a 120V bulb, coffee maker, or other high- - power device, a relay is an excellent way to do that. Because - the relay needs more power to switch than an Arduino pin can - provide, we'll use a transistor to drive the relay in exactly - the same way we used a transistor to drive a motor in circuit 12. - - A relay consists of a coil of wire, and switch contacts. When - you apply power to the coil, it becomes magnetized, and pulls - the switch contacts closed. Since the switch contacts are - completely isolated from the Arduino, you can safely use a - relay to control normally dangerous voltages (but please only do - this if you already know how to safely work with high voltage!). - - The relay has three contact pins, COM (common), NC (Normally - Closed), and NO (Normally Open). When the relay is turned off, - the COM pin is connected to the NC (Normally Closed) pin. When - the relay is turned on, the COM pin is connected to the NO - (Normally Open) pin. - - This code is very simple - it turns the relay on for one second, - and off for one second, the same as the blink sketch! - -Hardware connections: - - Transistor: - - The transistor has three pins. Looking at the flat side with - the pins down, the order is COLLECTOR, BASE, EMITTER. - - Connect the BASE pin through a 1K resistor to digital pin 2. - - Connect the EMITTER pin to GND. - - Relay coil: - - The relay has pins for a coil (which you use to control the - relay), and contacts (which you connect to the device you'd - like to switch). The top or bottom of the relay should have - a symbol indicating the coil pins. - - Connect one side of the coil to the COLLECTOR pin - on the transistor. - - Connect other side of the coil to 5V. - - Diode: - - The relay has a coil that you energize to close the switch. - When you disconnect power from a coil, the coil will generate - a voltage spike that can damage the transistor. This diode - protects the transistor from the voltage spike. - - Connect the side of the diode with the band (cathode) to 5V - - Connect the other side of the diode (anode) to the COLLECTOR - pin of the transistor. - - Relay contacts and LEDs: - - We'll use the relay contacts to turn LEDs on and off, but you - can use them to switch almost anything on and off. - - Connect the COMMON side of the switch to a 330 Ohm resistor. - Connect the other side of the above resistor to 5V. - - Connect the NC (Normally Closed) side of the switch to the - positive (longer) leg of LED 1. - - Connect the NO (Normally Open) side of the switch to the - positive (longer) leg of LED 2. - - Connect the negative sides (shorter leg) of both LEDs to GND. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -const int relayPin = 2; // use this pin to drive the transistor -const int timeDelay = 1000; // delay in ms for on and off phases - -// You can make timeDelay shorter, but note that relays, being -// mechanical devices, will wear out quickly if you try to drive -// them too fast. - - -void setup() -{ - pinMode(relayPin, OUTPUT); // set pin as an output -} - - -void loop() -{ - digitalWrite(relayPin, HIGH); // turn the relay on - - delay(timeDelay); // wait for one second - - digitalWrite(relayPin, LOW); // turn the relay off - - delay(timeDelay); // wait for one second -} - diff --git a/Circuit_14/Circuit_14.ino b/Circuit_14/Circuit_14.ino deleted file mode 100644 index a0a5434..0000000 --- a/Circuit_14/Circuit_14.ino +++ /dev/null @@ -1,379 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 13 - -SHIFT REGISTER - - Use a shift register to turn three pins into eight (or more!) - outputs - - An integrated circuit ("IC"), or "chip", is a self-contained - circuit built into a small plastic package. (If you look closely - at your Arduino board you'll see a number of ICs.) There are - thousands of different types of ICs available that you can use - to perform many useful functions. - - The 74HC595 shift register in your kit is an IC that has eight - digital outputs. To use these outputs, we'll use a new interface - called SPI (Serial Peripheral Interface). It's like the TX and - RX you're used to, but has an additional "clock" line that - controls the speed of the data transfer. Many parts use SPI - for communications, so the Arduino offers simple commands called - shiftIn() and shiftOut() to access these parts. - - This IC lets you use three digital pins on your Arduino to - control eight digital outputs on the chip. And if you need - even more outputs, you can daisy-chain multiple shift registers - together, allowing an almost unlimited number of outputs from - the same three Arduino pins! See the shift register datasheet - for details: - - http://www.sparkfun.com/datasheets/IC/SN74HC595.pdf - -Hardware connections: - - Shift register: - - Plug in the chip so it bridges the center "canyon" - on the breadboard. - - The shift register has 16 pins. They are numbered - counterclockwise starting at the pin 1 mark (notch - in the end of the chip). See the datasheet above - for a diagram. - - 74HC595 pin LED pin Arduino pin - - 1 (QB) LED 2 + - 2 (QC) LED 3 + - 3 (QD) LED 4 + - 4 (QE) LED 5 + - 5 (QF) LED 6 + - 6 (QG) LED 7 + - 7 (QH) LED 8 + - 8 (GND) GND - - 9 (QH*) - 10 (SRCLR*) 5V - 11 (SRCLK) Digital 3 - 12 (RCLK) Digital 4 - 13 (OE*) GND - 14 (SER) Digital 2 - 15 (QA) LED 1 + - 16 (VCC) 5V - - LEDs: - - After making the above connections to the positive (longer) - legs of the LEDs, connect the negative side (short lead) of - each LED to a 330 Ohm resistor, and connect the other side - of each resistor to GND. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 2.0 6/2012 MDG -*/ - - -// Pin definitions: -// The 74HC595 uses a type of serial connection called SPI -// (Serial Peripheral Interface) that requires three pins: - -int datapin = 2; -int clockpin = 3; -int latchpin = 4; - -// We'll also declare a global variable for the data we're -// sending to the shift register: - -byte data = 0; - - -void setup() -{ - // Set the three SPI pins to be outputs: - - pinMode(datapin, OUTPUT); - pinMode(clockpin, OUTPUT); - pinMode(latchpin, OUTPUT); -} - - -void loop() -{ - // We're going to use the same functions we played with back - // in circuit 04, "Multiple LEDs", we've just replaced - // digitalWrite() with a new function called shiftWrite() - // (see below). We also have a new function that demonstrates - // binary counting. - - // To try the different functions below, uncomment the one - // you want to run, and comment out the remaining ones to - // disable them from running. - - oneAfterAnother(); // All on, all off - - //oneOnAtATime(); // Scroll down the line - - //pingPong(); // Like above, but back and forth - - //randomLED(); // Blink random LEDs - - //marquee(); - - //binaryCount(); // Bit patterns from 0 to 255 -} - - -void shiftWrite(int desiredPin, boolean desiredState) - -// This function lets you make the shift register outputs -// HIGH or LOW in exactly the same way that you use digitalWrite(). - -// Like digitalWrite(), this function takes two parameters: - -// "desiredPin" is the shift register output pin -// you want to affect (0-7) - -// "desiredState" is whether you want that output -// to be HIGH or LOW - -// Inside the Arduino, numbers are stored as arrays of "bits", -// each of which is a single 1 or 0 value. Because a "byte" type -// is also eight bits, we'll use a byte (which we named "data" -// at the top of this sketch) to send data to the shift register. -// If a bit in the byte is "1", the output will be HIGH. If the bit -// is "0", the output will be LOW. - -// To turn the individual bits in "data" on and off, we'll use -// a new Arduino commands called bitWrite(), which can make -// individual bits in a number 1 or 0. -{ - // First we'll alter the global variable "data", changing the - // desired bit to 1 or 0: - - bitWrite(data,desiredPin,desiredState); - - // Now we'll actually send that data to the shift register. - // The shiftOut() function does all the hard work of - // manipulating the data and clock pins to move the data - // into the shift register: - - shiftOut(datapin, clockpin, MSBFIRST, data); - - // Once the data is in the shift register, we still need to - // make it appear at the outputs. We'll toggle the state of - // the latchPin, which will signal the shift register to "latch" - // the data to the outputs. (Latch activates on the high-to - // -low transition). - - digitalWrite(latchpin, HIGH); - digitalWrite(latchpin, LOW); -} - - -/* -oneAfterAnother() - -This function will light one LED, delay for delayTime, then light -the next LED, and repeat until all the LEDs are on. It will then -turn them off in the reverse order. -*/ - -void oneAfterAnother() -{ - int index; - int delayTime = 100; // Time (milliseconds) to pause between LEDs - // Make this smaller for faster switching - - // Turn all the LEDs on: - - // This for() loop will step index from 0 to 7 - // (putting "++" after a variable means add one to it) - // and will then use digitalWrite() to turn that LED on. - - for(index = 0; index <= 7; index++) - { - shiftWrite(index, HIGH); - delay(delayTime); - } - - // Turn all the LEDs off: - - // This for() loop will step index from 7 to 0 - // (putting "--" after a variable means subtract one from it) - // and will then use digitalWrite() to turn that LED off. - - for(index = 7; index >= 0; index--) - { - shiftWrite(index, LOW); - delay(delayTime); - } -} - - -/* -oneOnAtATime() - -This function will step through the LEDs, lighting one at at time. -*/ - -void oneOnAtATime() -{ - int index; - int delayTime = 100; // Time (milliseconds) to pause between LEDs - // Make this smaller for faster switching - - // step through the LEDs, from 0 to 7 - - for(index = 0; index <= 7; index++) - { - shiftWrite(index, HIGH); // turn LED on - delay(delayTime); // pause to slow down the sequence - shiftWrite(index, LOW); // turn LED off - } -} - - -/* -pingPong() - -This function will step through the LEDs, lighting one at at time, -in both directions. -*/ - -void pingPong() -{ - int index; - int delayTime = 100; // time (milliseconds) to pause between LEDs - // make this smaller for faster switching - - // step through the LEDs, from 0 to 7 - - for(index = 0; index <= 7; index++) - { - shiftWrite(index, HIGH); // turn LED on - delay(delayTime); // pause to slow down the sequence - shiftWrite(index, LOW); // turn LED off - } - - // step through the LEDs, from 7 to 0 - - for(index = 7; index >= 0; index--) - { - shiftWrite(index, HIGH); // turn LED on - delay(delayTime); // pause to slow down the sequence - shiftWrite(index, LOW); // turn LED off - } -} - - -/* -randomLED() - -This function will turn on random LEDs. Can you modify it so it -also lights them for random times? -*/ - -void randomLED() -{ - int index; - int delayTime = 100; // time (milliseconds) to pause between LEDs - // make this smaller for faster switching - - // The random() function will return a semi-random number each - // time it is called. See http://arduino.cc/en/Reference/Random - // for tips on how to make random() more random. - - index = random(8); // pick a random number between 0 and 7 - - shiftWrite(index, HIGH); // turn LED on - delay(delayTime); // pause to slow down the sequence - shiftWrite(index, LOW); // turn LED off -} - - -/* -marquee() - -This function will mimic "chase lights" like those around signs. -*/ - -void marquee() -{ - int index; - int delayTime = 200; // Time (milliseconds) to pause between LEDs - // Make this smaller for faster switching - - // Step through the first four LEDs - // (We'll light up one in the lower 4 and one in the upper 4) - - for(index = 0; index <= 3; index++) - { - shiftWrite(index, HIGH); // Turn a LED on - shiftWrite(index+4, HIGH); // Skip four, and turn that LED on - delay(delayTime); // Pause to slow down the sequence - shiftWrite(index, LOW); // Turn both LEDs off - shiftWrite(index+4, LOW); - } -} - - -/* -binaryCount() - -Numbers are stored internally in the Arduino as arrays of "bits", -each of which is a 1 or 0. Just like the base-10 numbers we use -every day, The position of the bit affects the magnitude of its -contribution to the total number: - -Bit position Contribution -0 1 -1 2 -2 4 -3 8 -4 16 -5 32 -6 64 -7 128 - -To build any number from 0 to 255 from the above 8 bits, just -select the contributions you need to make. The bits will then be -1 if you use that contribution, and 0 if you don't. - -This function will increment the "data" variable from 0 to 255 -and repeat. When we send this value to the shift register and LEDs, -you can see the on-off pattern of the eight bits that make up the -byte. See http://www.arduino.cc/playground/Code/BitMath for more -information on binary numbers. -*/ - -void binaryCount() -{ - int delayTime = 1000; // time (milliseconds) to pause between LEDs - // make this smaller for faster switching - - // Send the data byte to the shift register: - - shiftOut(datapin, clockpin, MSBFIRST, data); - - // Toggle the latch pin to make the data appear at the outputs: - - digitalWrite(latchpin, HIGH); - digitalWrite(latchpin, LOW); - - // Add one to data, and repeat! - // (Because a byte type can only store numbers from 0 to 255, - // if we add more than that, it will "roll around" back to 0 - // and start over). - - data++; - - // Delay so you can see what's going on: - - delay(delayTime); -} diff --git a/Circuit_15/Circuit_15.ino b/Circuit_15/Circuit_15.ino deleted file mode 100644 index 8e0c28a..0000000 --- a/Circuit_15/Circuit_15.ino +++ /dev/null @@ -1,209 +0,0 @@ -/* -SparkFun Inventor's Kit -Example sketch 15 - -LIQUID CRYSTAL DISPLAY (LCD) - - A Liquid Crystal Display (LCD) is a sophisticated module - that can be used to display text or numeric data. The display - included in your SIK features two lines of 16 characters, and - a backlight so it can be used at night. - - If you've been using the Serial Monitor to output data, - you'll find that a LCD provides many of the same benefits - without needing to drag a large computer around. - - This sketch will show you how to connect an LCD to your Arduino - and display any data you wish. - -Hardware connections: - - The LCD has a 16-pin male header attached to it along the top - edge. Pin 1 is the pin closest to the corner of the LCD. - Pin 16 is the pin closest to the center of the LCD. - - Plug the LCD into your breadboard. - - As usual, you will want to connect the + and - power rails - on the side of the breadboard to 5V and GND on your Arduino. - - Plug your 10K potentiometer into three unused rows on your - breadboard. Connect one side of the potentiometer to 5V, - and the other side to GND (it doesn't matter which). When you - run this sketch, you'll use the potentiometer to adjust the - contrast of the LCD so you can see the display. - - Now connect the LCD pins. Remember that pin 1 on the LCD - is the one closest to the corner. Start there and work your - way up. - - 1 to GND - 2 to 5V - 3 to the center pin on the potentiometer - 4 to Arduino digital pin 12 - 5 to GND - 6 to Arduino digital pin 11 - 7 (no connection) - 8 (no connection) - 9 (no connection) - 10 (no connection) - 11 to Arduino digital pin 5 - 12 to Arduino digital pin 4 - 13 to Arduino digital pin 3 - 14 to Arduino digital pin 2 - 15 to 5V - 16 to GND - - Once everything is connected, load this sketch into the - Arduino, and adjust the potentiometer until the display - is clear. - -Library - - The LCD has a chip built into it that controls all the - individual dots that make up the display, and obeys commands - sent to it by the the Arduino. The chip knows the dot patterns - that make up all the text characters, saving you a lot of work. - - To communicate with this chip, we'll use the LiquidCrystal - library, which is one of the standard libraries that comes - with the Arduino. This library does most of the hard work - of interfacing to the LCD; all you need to pick a location - on the display and send your data! - -Tips - - The LCD comes with a protective film over the display that - you can peel off (but be careful of the display surface as - it scratches easily). - - The LCD has a backlight that will light up when you turn on - your Arduino. If the backlight doesn't turn on, check your - connections. - - As we said above, the potentiometer adjusts the contrast of - the display. If you can't see anything when you run the sketch, - turn the potentiometer's knob until the text is clear. - -This sketch was written by SparkFun Electronics, -with lots of help from the Arduino community. -This code is completely free for any use. -Visit http://learn.sparkfun.com/products/2 for SIK information. -Visit http://www.arduino.cc to learn about the Arduino. - -Version 1.0 2/2013 MDG -*/ - -// Load the LiquidCrystal library, which will give us -// commands to interface to the LCD: - -#include - -// Initialize the library with the pins we're using. -// (Note that you can use different pins if needed.) -// See http://arduino.cc/en/Reference/LiquidCrystal -// for more information: - -LiquidCrystal lcd(12,11,5,4,3,2); - -void setup() -{ - // The LiquidCrystal library can be used with many different - // LCD sizes. We're using one that's 2 lines of 16 characters, - // so we'll inform the library of that: - - lcd.begin(16, 2); - - // Data sent to the display will stay there until it's - // overwritten or power is removed. This can be a problem - // when you upload a new sketch to the Arduino but old data - // remains on the display. Let's clear the LCD using the - // clear() command from the LiquidCrystal library: - - lcd.clear(); - - // Now we'll display a message on the LCD! - - // Just as with the Arduino IDE, there's a cursor that - // determines where the data you type will appear. By default, - // this cursor is invisible, though you can make it visible - // with other library commands if you wish. - - // When the display powers up, the invisible cursor starts - // on the top row and first column. - - lcd.print("hello, world!"); - - // Adjusting the contrast (IMPORTANT!) - - // When you run the sketch for the first time, there's a - // very good chance you won't see anything on the LCD display. - // This is because the contrast likely won't be set correctly. - // Don't worry, it's easy to set, and once you set it you won't - // need to change it again. - - // Run the sketch, then turn the potentiometer until you can - // clearly see the "hello, world!" text. If you still can't - // see anything, check all of your connections, and ensure that - // the sketch was successfully uploaded to the Arduino. -} - -void loop() -{ - // You can move the invisible cursor to any location on the - // LCD before sending data. Counting starts from 0, so the top - // line is line 0 and the bottom line is line 1. Columns range - // from 0 on the left side, to 15 on the right. - - // In additon to the "hello, world!" printed above, let's - // display a running count of the seconds since the Arduino - // was last reset. Note that the data you send to the display - // will stay there unless you erase it by overwriting it or - // sending a lcd.clear() command. - - // Here we'll set the invisible cursor to the first column - // (column 0) of the second line (line 1): - - lcd.setCursor(0,1); - - // Now we'll print the number of seconds (millis() / 1000) - // since the Arduino last reset: - - lcd.print(millis()/1000); - - // TIP: Since the numeric data we're sending is always growing - // in length, new values will always overwrite the previous ones. - // However, if you want to display varying or decreasing numbers - // like a countdown, you'll find that the display will leave - // "orphan" characters when the new value is shorter than the - // old one. - - // To prevent this, you'll need to erase the old number before - // writing the new one. You can do this by overwriting the - // last number with spaces. If you erase the old number and - // immediately write the new one, the momentary erase won't - // be noticeable. Here's a typical sequence of code: - - // lcd.setCursor(0,1); // Set the cursor to the position - // lcd.print(" "); // Erase the largest possible number - // lcd.setCursor(0,1); // Reset the cursor to the original position - // lcd.print(millis()/1000); // Print our value - - // NEXT STEPS: - - // Now you know the basics of hooking up an LCD to the Arduino, - // and sending text and numeric data to the display! - - // The LCD library has many commands for turning the - // cursor on and off, scrolling the screen, etc. See: - // http://arduino.cc/en/Reference/LiquidCrystal - // for more information. - - // Arduino also comes with a number of built-in examples - // showing off the features of the LiquidCrystal library. - // These are locted in the file/examples/LiquidCrystal menu. - - // Have fun, and let us know what you create! - // Your friends at SparkFun. -} - diff --git a/Circuit_16/Circuit_16.ino b/Circuit_16/Circuit_16.ino deleted file mode 100644 index f0072ed..0000000 --- a/Circuit_16/Circuit_16.ino +++ /dev/null @@ -1,563 +0,0 @@ -/* - SparkFun Inventor's Kit - Example sketch 16 - Spark Fun Electronics - Oct. 7, 2014 - - Simon Says is a memory game. Start the game by pressing one of the four buttons. When a button lights up, - press the button, repeating the sequence. The sequence will get longer and longer. The game is won after - 13 rounds. - - Generates random sequence, plays music, and displays button lights. - - Simon tones from Wikipedia - - A (red, upper left) - 440Hz - 2.272ms - 1.136ms pulse - - a (green, upper right, an octave higher than A) - 880Hz - 1.136ms, - 0.568ms pulse - - D (blue, lower left, a perfect fourth higher than the upper left) - 587.33Hz - 1.702ms - 0.851ms pulse - - G (yellow, lower right, a perfect fourth higher than the lower left) - - 784Hz - 1.276ms - 0.638ms pulse - - Simon Says game originally written in C for the PIC16F88. - Ported for the ATmega168, then ATmega328, then Arduino 1.0. - Fixes and cleanup by Joshua Neal - - This sketch was written by SparkFun Electronics, - with lots of help from the Arduino community. - This code is completely free for any use. - Visit http://www.arduino.cc to learn about the Arduino. - */ - -/************************************************* -* Public Constants -*************************************************/ -#define NOTE_B0 31 -#define NOTE_C1 33 -#define NOTE_CS1 35 -#define NOTE_D1 37 -#define NOTE_DS1 39 -#define NOTE_E1 41 -#define NOTE_F1 44 -#define NOTE_FS1 46 -#define NOTE_G1 49 -#define NOTE_GS1 52 -#define NOTE_A1 55 -#define NOTE_AS1 58 -#define NOTE_B1 62 -#define NOTE_C2 65 -#define NOTE_CS2 69 -#define NOTE_D2 73 -#define NOTE_DS2 78 -#define NOTE_E2 82 -#define NOTE_F2 87 -#define NOTE_FS2 93 -#define NOTE_G2 98 -#define NOTE_GS2 104 -#define NOTE_A2 110 -#define NOTE_AS2 117 -#define NOTE_B2 123 -#define NOTE_C3 131 -#define NOTE_CS3 139 -#define NOTE_D3 147 -#define NOTE_DS3 156 -#define NOTE_E3 165 -#define NOTE_F3 175 -#define NOTE_FS3 185 -#define NOTE_G3 196 -#define NOTE_GS3 208 -#define NOTE_A3 220 -#define NOTE_AS3 233 -#define NOTE_B3 247 -#define NOTE_C4 262 -#define NOTE_CS4 277 -#define NOTE_D4 294 -#define NOTE_DS4 311 -#define NOTE_E4 330 -#define NOTE_F4 349 -#define NOTE_FS4 370 -#define NOTE_G4 392 -#define NOTE_GS4 415 -#define NOTE_A4 440 -#define NOTE_AS4 466 -#define NOTE_B4 494 -#define NOTE_C5 523 -#define NOTE_CS5 554 -#define NOTE_D5 587 -#define NOTE_DS5 622 -#define NOTE_E5 659 -#define NOTE_F5 698 -#define NOTE_FS5 740 -#define NOTE_G5 784 -#define NOTE_GS5 831 -#define NOTE_A5 880 -#define NOTE_AS5 932 -#define NOTE_B5 988 -#define NOTE_C6 1047 -#define NOTE_CS6 1109 -#define NOTE_D6 1175 -#define NOTE_DS6 1245 -#define NOTE_E6 1319 -#define NOTE_F6 1397 -#define NOTE_FS6 1480 -#define NOTE_G6 1568 -#define NOTE_GS6 1661 -#define NOTE_A6 1760 -#define NOTE_AS6 1865 -#define NOTE_B6 1976 -#define NOTE_C7 2093 -#define NOTE_CS7 2217 -#define NOTE_D7 2349 -#define NOTE_DS7 2489 -#define NOTE_E7 2637 -#define NOTE_F7 2794 -#define NOTE_FS7 2960 -#define NOTE_G7 3136 -#define NOTE_GS7 3322 -#define NOTE_A7 3520 -#define NOTE_AS7 3729 -#define NOTE_B7 3951 -#define NOTE_C8 4186 -#define NOTE_CS8 4435 -#define NOTE_D8 4699 -#define NOTE_DS8 4978 - -#define CHOICE_OFF 0 //Used to control LEDs -#define CHOICE_NONE 0 //Used to check buttons -#define CHOICE_RED (1 << 0) -#define CHOICE_GREEN (1 << 1) -#define CHOICE_BLUE (1 << 2) -#define CHOICE_YELLOW (1 << 3) - -#define LED_RED 10 -#define LED_GREEN 3 -#define LED_BLUE 13 -#define LED_YELLOW 5 - -// Button pin definitions -#define BUTTON_RED 9 -#define BUTTON_GREEN 2 -#define BUTTON_BLUE 12 -#define BUTTON_YELLOW 6 - -// Buzzer pin definitions -#define BUZZER1 4 -#define BUZZER2 7 - -// Define game parameters -#define ROUNDS_TO_WIN 13 //Number of rounds to succesfully remember before you win. 13 is do-able. -#define ENTRY_TIME_LIMIT 3000 //Amount of time to press a button before game times out. 3000ms = 3 sec - -#define MODE_MEMORY 0 -#define MODE_BATTLE 1 -#define MODE_BEEGEES 2 - -// Game state variables -byte gameMode = MODE_MEMORY; //By default, let's play the memory game -byte gameBoard[32]; //Contains the combination of buttons as we advance -byte gameRound = 0; //Counts the number of succesful rounds the player has made it through - -void setup() -{ - //Setup hardware inputs/outputs. These pins are defined in the hardware_versions header file - - //Enable pull ups on inputs - pinMode(BUTTON_RED, INPUT_PULLUP); - pinMode(BUTTON_GREEN, INPUT_PULLUP); - pinMode(BUTTON_BLUE, INPUT_PULLUP); - pinMode(BUTTON_YELLOW, INPUT_PULLUP); - - pinMode(LED_RED, OUTPUT); - pinMode(LED_GREEN, OUTPUT); - pinMode(LED_BLUE, OUTPUT); - pinMode(LED_YELLOW, OUTPUT); - - pinMode(BUZZER1, OUTPUT); - pinMode(BUZZER2, OUTPUT); - - //Mode checking - gameMode = MODE_MEMORY; // By default, we're going to play the memory game - - // Check to see if the lower right button is pressed - if (checkButton() == CHOICE_YELLOW) play_beegees(); - - // Check to see if upper right button is pressed - if (checkButton() == CHOICE_GREEN) - { - gameMode = MODE_BATTLE; //Put game into battle mode - - //Turn on the upper right (green) LED - setLEDs(CHOICE_GREEN); - toner(CHOICE_GREEN, 150); - - setLEDs(CHOICE_RED | CHOICE_BLUE | CHOICE_YELLOW); // Turn on the other LEDs until you release button - - while(checkButton() != CHOICE_NONE) ; // Wait for user to stop pressing button - - //Now do nothing. Battle mode will be serviced in the main routine - } - - play_winner(); // After setup is complete, say hello to the world -} - -void loop() -{ - attractMode(); // Blink lights while waiting for user to press a button - - // Indicate the start of game play - setLEDs(CHOICE_RED | CHOICE_GREEN | CHOICE_BLUE | CHOICE_YELLOW); // Turn all LEDs on - delay(1000); - setLEDs(CHOICE_OFF); // Turn off LEDs - delay(250); - - if (gameMode == MODE_MEMORY) - { - // Play memory game and handle result - if (play_memory() == true) - play_winner(); // Player won, play winner tones - else - play_loser(); // Player lost, play loser tones - } - - if (gameMode == MODE_BATTLE) - { - play_battle(); // Play game until someone loses - - play_loser(); // Player lost, play loser tones - } -} - -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -//The following functions are related to game play only - -// Play the regular memory game -// Returns 0 if player loses, or 1 if player wins -boolean play_memory(void) -{ - randomSeed(millis()); // Seed the random generator with random amount of millis() - - gameRound = 0; // Reset the game to the beginning - - while (gameRound < ROUNDS_TO_WIN) - { - add_to_moves(); // Add a button to the current moves, then play them back - - playMoves(); // Play back the current game board - - // Then require the player to repeat the sequence. - for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) - { - byte choice = wait_for_button(); // See what button the user presses - - if (choice == 0) return false; // If wait timed out, player loses - - if (choice != gameBoard[currentMove]) return false; // If the choice is incorect, player loses - } - - delay(1000); // Player was correct, delay before playing moves - } - - return true; // Player made it through all the rounds to win! -} - -// Play the special 2 player battle mode -// A player begins by pressing a button then handing it to the other player -// That player repeats the button and adds one, then passes back. -// This function returns when someone loses -boolean play_battle(void) -{ - gameRound = 0; // Reset the game frame back to one frame - - while (1) // Loop until someone fails - { - byte newButton = wait_for_button(); // Wait for user to input next move - gameBoard[gameRound++] = newButton; // Add this new button to the game array - - // Then require the player to repeat the sequence. - for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) - { - byte choice = wait_for_button(); - - if (choice == 0) return false; // If wait timed out, player loses. - - if (choice != gameBoard[currentMove]) return false; // If the choice is incorect, player loses. - } - - delay(100); // Give the user an extra 100ms to hand the game to the other player - } - - return true; // We should never get here -} - -// Plays the current contents of the game moves -void playMoves(void) -{ - for (byte currentMove = 0 ; currentMove < gameRound ; currentMove++) - { - toner(gameBoard[currentMove], 150); - - // Wait some amount of time between button playback - // Shorten this to make game harder - delay(150); // 150 works well. 75 gets fast. - } -} - -// Adds a new random button to the game sequence, by sampling the timer -void add_to_moves(void) -{ - byte newButton = random(0, 4); //min (included), max (exluded) - - // We have to convert this number, 0 to 3, to CHOICEs - if(newButton == 0) newButton = CHOICE_RED; - else if(newButton == 1) newButton = CHOICE_GREEN; - else if(newButton == 2) newButton = CHOICE_BLUE; - else if(newButton == 3) newButton = CHOICE_YELLOW; - - gameBoard[gameRound++] = newButton; // Add this new button to the game array -} - -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -//The following functions control the hardware - -// Lights a given LEDs -// Pass in a byte that is made up from CHOICE_RED, CHOICE_YELLOW, etc -void setLEDs(byte leds) -{ - if ((leds & CHOICE_RED) != 0) - digitalWrite(LED_RED, HIGH); - else - digitalWrite(LED_RED, LOW); - - if ((leds & CHOICE_GREEN) != 0) - digitalWrite(LED_GREEN, HIGH); - else - digitalWrite(LED_GREEN, LOW); - - if ((leds & CHOICE_BLUE) != 0) - digitalWrite(LED_BLUE, HIGH); - else - digitalWrite(LED_BLUE, LOW); - - if ((leds & CHOICE_YELLOW) != 0) - digitalWrite(LED_YELLOW, HIGH); - else - digitalWrite(LED_YELLOW, LOW); -} - -// Wait for a button to be pressed. -// Returns one of LED colors (LED_RED, etc.) if successful, 0 if timed out -byte wait_for_button(void) -{ - long startTime = millis(); // Remember the time we started the this loop - - while ( (millis() - startTime) < ENTRY_TIME_LIMIT) // Loop until too much time has passed - { - byte button = checkButton(); - - if (button != CHOICE_NONE) - { - toner(button, 150); // Play the button the user just pressed - - while(checkButton() != CHOICE_NONE) ; // Now let's wait for user to release button - - delay(10); // This helps with debouncing and accidental double taps - - return button; - } - - } - - return CHOICE_NONE; // If we get here, we've timed out! -} - -// Returns a '1' bit in the position corresponding to CHOICE_RED, CHOICE_GREEN, etc. -byte checkButton(void) -{ - if (digitalRead(BUTTON_RED) == 0) return(CHOICE_RED); - else if (digitalRead(BUTTON_GREEN) == 0) return(CHOICE_GREEN); - else if (digitalRead(BUTTON_BLUE) == 0) return(CHOICE_BLUE); - else if (digitalRead(BUTTON_YELLOW) == 0) return(CHOICE_YELLOW); - - return(CHOICE_NONE); // If no button is pressed, return none -} - -// Light an LED and play tone -// Red, upper left: 440Hz - 2.272ms - 1.136ms pulse -// Green, upper right: 880Hz - 1.136ms - 0.568ms pulse -// Blue, lower left: 587.33Hz - 1.702ms - 0.851ms pulse -// Yellow, lower right: 784Hz - 1.276ms - 0.638ms pulse -void toner(byte which, int buzz_length_ms) -{ - setLEDs(which); //Turn on a given LED - - //Play the sound associated with the given LED - switch(which) - { - case CHOICE_RED: - buzz_sound(buzz_length_ms, 1136); - break; - case CHOICE_GREEN: - buzz_sound(buzz_length_ms, 568); - break; - case CHOICE_BLUE: - buzz_sound(buzz_length_ms, 851); - break; - case CHOICE_YELLOW: - buzz_sound(buzz_length_ms, 638); - break; - } - - setLEDs(CHOICE_OFF); // Turn off all LEDs -} - -// Toggle buzzer every buzz_delay_us, for a duration of buzz_length_ms. -void buzz_sound(int buzz_length_ms, int buzz_delay_us) -{ - // Convert total play time from milliseconds to microseconds - long buzz_length_us = buzz_length_ms * (long)1000; - - // Loop until the remaining play time is less than a single buzz_delay_us - while (buzz_length_us > (buzz_delay_us * 2)) - { - buzz_length_us -= buzz_delay_us * 2; //Decrease the remaining play time - - // Toggle the buzzer at various speeds - digitalWrite(BUZZER1, LOW); - digitalWrite(BUZZER2, HIGH); - delayMicroseconds(buzz_delay_us); - - digitalWrite(BUZZER1, HIGH); - digitalWrite(BUZZER2, LOW); - delayMicroseconds(buzz_delay_us); - } -} - -// Play the winner sound and lights -void play_winner(void) -{ - setLEDs(CHOICE_GREEN | CHOICE_BLUE); - winner_sound(); - setLEDs(CHOICE_RED | CHOICE_YELLOW); - winner_sound(); - setLEDs(CHOICE_GREEN | CHOICE_BLUE); - winner_sound(); - setLEDs(CHOICE_RED | CHOICE_YELLOW); - winner_sound(); -} - -// Play the winner sound -// This is just a unique (annoying) sound we came up with, there is no magic to it -void winner_sound(void) -{ - // Toggle the buzzer at various speeds - for (byte x = 250 ; x > 70 ; x--) - { - for (byte y = 0 ; y < 3 ; y++) - { - digitalWrite(BUZZER2, HIGH); - digitalWrite(BUZZER1, LOW); - delayMicroseconds(x); - - digitalWrite(BUZZER2, LOW); - digitalWrite(BUZZER1, HIGH); - delayMicroseconds(x); - } - } -} - -// Play the loser sound/lights -void play_loser(void) -{ - setLEDs(CHOICE_RED | CHOICE_GREEN); - buzz_sound(255, 1500); - - setLEDs(CHOICE_BLUE | CHOICE_YELLOW); - buzz_sound(255, 1500); - - setLEDs(CHOICE_RED | CHOICE_GREEN); - buzz_sound(255, 1500); - - setLEDs(CHOICE_BLUE | CHOICE_YELLOW); - buzz_sound(255, 1500); -} - -// Show an "attract mode" display while waiting for user to press button. -void attractMode(void) -{ - while(1) - { - setLEDs(CHOICE_RED); - delay(100); - if (checkButton() != CHOICE_NONE) return; - - setLEDs(CHOICE_BLUE); - delay(100); - if (checkButton() != CHOICE_NONE) return; - - setLEDs(CHOICE_GREEN); - delay(100); - if (checkButton() != CHOICE_NONE) return; - - setLEDs(CHOICE_YELLOW); - delay(100); - if (checkButton() != CHOICE_NONE) return; - } -} - -//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -// The following functions are related to Beegees Easter Egg only - -// Notes in the melody. Each note is about an 1/8th note, "0"s are rests. -int melody[] = { - NOTE_G4, NOTE_A4, 0, NOTE_C5, 0, 0, NOTE_G4, 0, 0, 0, - NOTE_E4, 0, NOTE_D4, NOTE_E4, NOTE_G4, 0, - NOTE_D4, NOTE_E4, 0, NOTE_G4, 0, 0, - NOTE_D4, 0, NOTE_E4, 0, NOTE_G4, 0, NOTE_A4, 0, NOTE_C5, 0}; - -int noteDuration = 115; // This essentially sets the tempo, 115 is just about right for a disco groove :) -int LEDnumber = 0; // Keeps track of which LED we are on during the beegees loop - -// Do nothing but play bad beegees music -// This function is activated when user holds bottom right button during power up -void play_beegees() -{ - //Turn on the bottom right (yellow) LED - setLEDs(CHOICE_YELLOW); - toner(CHOICE_YELLOW, 150); - - setLEDs(CHOICE_RED | CHOICE_GREEN | CHOICE_BLUE); // Turn on the other LEDs until you release button - - while(checkButton() != CHOICE_NONE) ; // Wait for user to stop pressing button - - setLEDs(CHOICE_NONE); // Turn off LEDs - - delay(1000); // Wait a second before playing song - - digitalWrite(BUZZER1, LOW); // setup the "BUZZER1" side of the buzzer to stay low, while we play the tone on the other pin. - - while(checkButton() == CHOICE_NONE) //Play song until you press a button - { - // iterate over the notes of the melody: - for (int thisNote = 0; thisNote < 32; thisNote++) { - changeLED(); - tone(BUZZER2, melody[thisNote],noteDuration); - // to distinguish the notes, set a minimum time between them. - // the note's duration + 30% seems to work well: - int pauseBetweenNotes = noteDuration * 1.30; - delay(pauseBetweenNotes); - // stop the tone playing: - noTone(BUZZER2); - } - } -} - -// Each time this function is called the board moves to the next LED -void changeLED(void) -{ - setLEDs(1 << LEDnumber); // Change the LED - - LEDnumber++; // Goto the next LED - if(LEDnumber > 3) LEDnumber = 0; // Wrap the counter if needed -} - - diff --git a/Project01_LightHouse/01-Blink/01-Blink.ino b/Project01_LightHouse/01-Blink/01-Blink.ino new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index c4f07e3..feac4a2 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,2 @@ -SparkFun Inventor's Kit - Example Sketches -====================================================== - -[![SparkFun Inventor's Kit](https://cdn.sparkfun.com//assets/parts/8/6/5/3/12060-01.jpg) -*SparkFun Inventor's Kit (KIT-12060)*](https://www.sparkfun.com/products/12060) - -The example sketches in this repository are part of the SparkFun Inventor's Kit (a.k.a. *"The SIK"*). The SIK consists of an [Arduino microcontroller](http://www.arduino.com) and a variety of electronic components designed to help you learn basic programming and circuits. Once you've mastered these circuits, you'll be able to start building projects limited only by your imagination! - -These sketches are designed to work with the [SIK Experiment Guide](https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32) tutorial. - - -Getting Started ---------------- - -1. If you haven't yet, download and install the [Arduino IDE](http://arduino.cc/en/Main/Software) -2. Obtain the latest SIK Guide Code by one of the following methods: - * Clone this repository using Git ([New to Git? Click here.](https://help.github.com/articles/set-up-git)) - * Download this repository as a [zip file](https://github.com/sparkfun/SIK-Guide-Code/archive/master.zip) and unzip. -3. Place the `SIK-Guide-Code` folder in the Arduino IDE `examples` directory: - * PC: drag the `SIK-Guide-Code` folder into `C:\program files\Arduino-x\examples` - * MAC: Right-click on the Arduino IDE app and click "Show Package Contents...". Drag the `SIK-Guide-Code` folder into `Contents/Resources/Java` - * Linux: see [http://www.arduino.cc/playground/Learning/Linux](http://www.arduino.cc/playground/Learning/Linux) -4. Start the Arduino IDE; the examples should be visible in this menu: `File > Examples > SIK Guide Code` - -Sketch Topics -------------- - -1. Blinking an LED -2. Potentiometer (knob) -3. RGB (Red Green Blue) LED -4. Multiple LEDs -5. Push buttons -6. Photoresistor (light sensor) -7. Temperature sensor -8. Servomotor -9. Flex sensor -10. Soft potentiometer -11. Buzzer -12. Motor -13. Relay -14. Shift register -15. Using an LCD -16. Simon Says - -Version History ---------------- -* [v32](https://github.com/sparkfun/SIK-Guide-Code/tree/v32) -SIK code version 3.2 -* [v30](https://github.com/sparkfun/SIK-Guide-Code/tree/v30) -SIK code version 3.0 - - - -License Information -------------------- - -These sketches were written by [SparkFun Electronics](https://www.sparkfun.com) with lots of help from the Arduino community. - -All contents of this repository are released under [Creative Commons Share-alike 3.0](http://creativecommons.org/licenses/by-sa/3.0/). +# SIK_rework +Re-work repository for all code examples, fritzing diagrams, and photos From aaa68b684f100a3c05b17f9132baedf4d56051ac Mon Sep 17 00:00:00 2001 From: Brian Huang Date: Fri, 13 Feb 2015 15:30:00 -0700 Subject: [PATCH 2/9] Updating for new project based SIK guide --- .../01-Blink.ino => Exp01-Blink/Exp01-Blink.ino} | 0 Project01_LightHouse/LightHouse/LightHouse.ino | 0 .../Exp02-2LEDs/Exp02-2LEDs.ino | 0 .../RailRoadCrossing/RailRoadCrossing.ino | 0 .../Exp03-MultiBlink/Exp03-MultiBlink.ino | 0 Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino | 0 .../Exp04-ButtonPush/Exp04-ButtonPush.ino | 0 .../Exp05-FadingLED/Exp05-FadingLED.ino | 0 .../Exp06-RGBColorMixing.ino | 0 .../Exp07-DimmerKnob/Exp07-DimmerKnob.ino | 0 Project04_RGBLamp/RGBLamp/RGBLamp.ino | 0 .../Exp08-LightSensor/Exp08-LightSensor.ino | 0 Project05_NightLight/NightLight/NightLight.ino | 0 .../_Exp09-Servos/_Exp09-Servos.ino | 0 .../Exp10-LiftingHeavyLoads.ino | 0 .../Exp11-TempControlledMotor.ino | 0 .../Exp12-SerialLCD/Exp12-SerialLCD.ino | 0 .../Exp13-H-BridgeMotor/Exp13-H-BridgeMotor.ino | 0 .../Exp14-IRPairPhotogate.ino | Bin 0 -> 7334 bytes .../ReactionTimer/ReactionTimer.ino | 0 .../Exp15-MutipleInputAccel.ino | 0 .../GameControllerMazeGame.ino | 0 .../Exp16-SoundSensing/Exp16-SoundSensing.ino | 0 .../SoundBarGraph/SoundBarGraph.ino | 0 .../Exp17-ToneMusicMaking.ino | 0 Project13_Therimin/Therimin/Therimin.ino | 0 Project14_Simon/SimonGame/SimonGame.ino | 0 .../SIKVendingMachine/SIKVendingMachine.ino | 0 28 files changed, 0 insertions(+), 0 deletions(-) rename Project01_LightHouse/{01-Blink/01-Blink.ino => Exp01-Blink/Exp01-Blink.ino} (100%) create mode 100644 Project01_LightHouse/LightHouse/LightHouse.ino create mode 100644 Project02_StopLightRRcrossing/Exp02-2LEDs/Exp02-2LEDs.ino create mode 100644 Project02_StopLightRRcrossing/RailRoadCrossing/RailRoadCrossing.ino create mode 100644 Project03_9LEDMatrix/Exp03-MultiBlink/Exp03-MultiBlink.ino create mode 100644 Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino create mode 100644 Project04_RGBLamp/Exp04-ButtonPush/Exp04-ButtonPush.ino create mode 100644 Project04_RGBLamp/Exp05-FadingLED/Exp05-FadingLED.ino create mode 100644 Project04_RGBLamp/Exp06-RGBColorMixing/Exp06-RGBColorMixing.ino create mode 100644 Project04_RGBLamp/Exp07-DimmerKnob/Exp07-DimmerKnob.ino create mode 100644 Project04_RGBLamp/RGBLamp/RGBLamp.ino create mode 100644 Project05_NightLight/Exp08-LightSensor/Exp08-LightSensor.ino create mode 100644 Project05_NightLight/NightLight/NightLight.ino create mode 100644 Project06_BalanceBeamGrabber/_Exp09-Servos/_Exp09-Servos.ino create mode 100644 Project07_FanSpiroGraph/Exp10-LiftingHeavyLoads/Exp10-LiftingHeavyLoads.ino create mode 100644 Project08_GreenHouse/Exp11-TempControlledMotor/Exp11-TempControlledMotor.ino create mode 100644 Project08_GreenHouse/Exp12-SerialLCD/Exp12-SerialLCD.ino create mode 100644 Project09_DrawbotRedux/Exp13-H-BridgeMotor/Exp13-H-BridgeMotor.ino create mode 100644 Project10_ReactionTimer/Exp14-IRPairPhotogate/Exp14-IRPairPhotogate.ino create mode 100644 Project10_ReactionTimer/ReactionTimer/ReactionTimer.ino create mode 100644 Project11_GameControllerMazeGame/Exp15-MutipleInputAccel/Exp15-MutipleInputAccel.ino create mode 100644 Project11_GameControllerMazeGame/GameControllerMazeGame/GameControllerMazeGame.ino create mode 100644 Project12_FunOmeter/Exp16-SoundSensing/Exp16-SoundSensing.ino create mode 100644 Project12_FunOmeter/SoundBarGraph/SoundBarGraph.ino create mode 100644 Project13_Therimin/Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino create mode 100644 Project13_Therimin/Therimin/Therimin.ino create mode 100644 Project14_Simon/SimonGame/SimonGame.ino create mode 100644 Project15_VendingMachine/SIKVendingMachine/SIKVendingMachine.ino diff --git a/Project01_LightHouse/01-Blink/01-Blink.ino b/Project01_LightHouse/Exp01-Blink/Exp01-Blink.ino similarity index 100% rename from Project01_LightHouse/01-Blink/01-Blink.ino rename to Project01_LightHouse/Exp01-Blink/Exp01-Blink.ino diff --git a/Project01_LightHouse/LightHouse/LightHouse.ino b/Project01_LightHouse/LightHouse/LightHouse.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project02_StopLightRRcrossing/Exp02-2LEDs/Exp02-2LEDs.ino b/Project02_StopLightRRcrossing/Exp02-2LEDs/Exp02-2LEDs.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project02_StopLightRRcrossing/RailRoadCrossing/RailRoadCrossing.ino b/Project02_StopLightRRcrossing/RailRoadCrossing/RailRoadCrossing.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project03_9LEDMatrix/Exp03-MultiBlink/Exp03-MultiBlink.ino b/Project03_9LEDMatrix/Exp03-MultiBlink/Exp03-MultiBlink.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino b/Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project04_RGBLamp/Exp04-ButtonPush/Exp04-ButtonPush.ino b/Project04_RGBLamp/Exp04-ButtonPush/Exp04-ButtonPush.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project04_RGBLamp/Exp05-FadingLED/Exp05-FadingLED.ino b/Project04_RGBLamp/Exp05-FadingLED/Exp05-FadingLED.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project04_RGBLamp/Exp06-RGBColorMixing/Exp06-RGBColorMixing.ino b/Project04_RGBLamp/Exp06-RGBColorMixing/Exp06-RGBColorMixing.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project04_RGBLamp/Exp07-DimmerKnob/Exp07-DimmerKnob.ino b/Project04_RGBLamp/Exp07-DimmerKnob/Exp07-DimmerKnob.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project04_RGBLamp/RGBLamp/RGBLamp.ino b/Project04_RGBLamp/RGBLamp/RGBLamp.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project05_NightLight/Exp08-LightSensor/Exp08-LightSensor.ino b/Project05_NightLight/Exp08-LightSensor/Exp08-LightSensor.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project05_NightLight/NightLight/NightLight.ino b/Project05_NightLight/NightLight/NightLight.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project06_BalanceBeamGrabber/_Exp09-Servos/_Exp09-Servos.ino b/Project06_BalanceBeamGrabber/_Exp09-Servos/_Exp09-Servos.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project07_FanSpiroGraph/Exp10-LiftingHeavyLoads/Exp10-LiftingHeavyLoads.ino b/Project07_FanSpiroGraph/Exp10-LiftingHeavyLoads/Exp10-LiftingHeavyLoads.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project08_GreenHouse/Exp11-TempControlledMotor/Exp11-TempControlledMotor.ino b/Project08_GreenHouse/Exp11-TempControlledMotor/Exp11-TempControlledMotor.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project08_GreenHouse/Exp12-SerialLCD/Exp12-SerialLCD.ino b/Project08_GreenHouse/Exp12-SerialLCD/Exp12-SerialLCD.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project09_DrawbotRedux/Exp13-H-BridgeMotor/Exp13-H-BridgeMotor.ino b/Project09_DrawbotRedux/Exp13-H-BridgeMotor/Exp13-H-BridgeMotor.ino new file mode 100644 index 0000000..e69de29 diff --git a/Project10_ReactionTimer/Exp14-IRPairPhotogate/Exp14-IRPairPhotogate.ino b/Project10_ReactionTimer/Exp14-IRPairPhotogate/Exp14-IRPairPhotogate.ino new file mode 100644 index 0000000000000000000000000000000000000000..501b62d2a5b457e97e07b72d68f5648213399a62 GIT binary patch literal 7334 zcma)B2|U!>7q^CN5h0N`wk%`DnqAgxG4_2lW(K1%GscWHlC?z$p|X=DOA!gBBzm^U zlI>Z`P9(Cm{AZNM>tFBl&V1(gxpVJ1-+Ruzckb_g?|~Rm({NBw&{I%Q8^eQQlHm91?@T!ik?5{)Fm zVDTV05sxSL?&pc7rhpjHk)5WXB0os-dv~}=tv|!MqOmXna@U#N5!nIy@%U8`I4q8c zBMkuYM-acVJNAp-aCod69_hU={9jrA%1?4k>4aGuK=fDo$k&vK-`~r4mw;V~LZ{Hdio{ z5;w5>G@5)>x7#3*ez{R5YN?%Rlqq?$-DKIts1jx<)iV1oTe9HA6>v2)F}BEg?CxW` z;9EsCt|`_!A2>&(UP%rSU{MH1Y&xSV0f+-BZ8`Q_idqa60ucbwZRmBVHN`1%;;ARkp{ z3AVdu14=J@Dy3dA?O7yKO>oWAz-PSToosFD2dG7^>8=z+f70c4oIP29%BeW>yyq>e zu}z8H6)lg%=Zd*EX;_~f)-L{wdR66cK+ALwDte`^#3DXwgU|Ks7$1S{Y}eOfUMD!xzZ z3ajZH6&*CM^&5Fp>CT!lYbEU}g9mpvm0#^uq(%yFf3T;nc}t;DAt~tI!!R7BUwQYkhTZNl?tNLef9+rWb2^1I3iX=97rq(7F-i zth-ToZYnTr){i}!{;HqxKmgDAtqr;wR_N2MabZ*Tqt|uYasYzHe-wTayDoUh6%V`I znt2FaUzUrn$LYP((q&9PJQaRKef@b#xuD(v#H(S!NTS?AJ3@Zxq9l~L3Y`)(YdeN7 zxIaZ}9P}Zam2;$-L-?4kYHL|G5ac6` zK2$h zGWq!jMh82P%WPP`$ozVG^Widt+^~w_A$0*$*u$Ks21)^}e-&$Ym?}=MOdrYMW74C$ zE3aXHSdS*+*%d?QhU*rbnseB)%o=C)cY~m3Nj{42nzqlh#v5)5bxSsh@dQ0Hj!}Oy zOFJ3oNg;v&li6_V6GK_{v9>A%>-)Lj*!a85<=gQz`CV6iV`vrVH#cnKr%peDI1YsfWlE1H zaprI4vDA3Mh3O;ZoyF;^@f^c`l~|rwO;t|)5|*xz@{}3qoptP2L~6pT)BV$@a{Z-< z>8rI)56(S}b+yo^0)zRi;Hnd1QG6HKX^Vvzs`w4Im{rqW;gL<|ZEt9y4G{EA02C}N zz!$vzBwgL?eof{*9q`*4tC@E5d7aKIY42MS^@i0sL4|B3#fs0Jzwys^4_!@M2#|Zz z^G@IGOu$EV_c7Ii{6BQ9-yTmj779T>=r|c(Z+%HNaYFGxaWtqk#OqRk-nn(UDF^6% zeNJl_1HzUOHWKosfnk=Np^>8{9wm7H0CZHY7oSqD6f%(5BDm7R=+N=p_f=cBh!Z?KW4uzJgU+_o|N+*U?c z#mQB3lyFybDDts^mlTm-qZiEn7|j!P-P$QwSm^YXdzS}i60VolMlo$4@KnAKB7UXp zQrO6+vCw1}v3j)=S(*3JS-QRsVSH28qh-62Z$?(j%B$R&W15RALg|%LzM~ZQDx~pDK1sZ2b7y6W{xSi>N#S}~vhm31gi zPkmD?>jJ^j^fY0aF#5cFBgH@U&rZvtV<`%YV3Vl8uM)3_yce1TLW-y^xOvLc_SiT~ z)pd;M-2~n%<^pOt??n7-~VC8X76NdMzc#hu)XYy}$fDPr>Ys z%k^x*)YIX^vQ5cHgGAqM8`p1rl{`7;pS6%RLx1Ihq_Dem9>S>W%CK?)odEk1cQh${f_qmA*Bq!)b@=5SX~`B1?$?Urg$>(NM{nxCl@QlG+SG{&7aF_ z$cQphROzZBVW3s3=b$V>EtFj`B$XwS%0SRMe#XLH-{JYd^}46vTx`uy#cB8P^Bbv%{gn@Hj%*B~W=WmIKiW7q z3PdvJE~Vm1SC>j5#zj0s)9pYL#%$JlpH2otR;rIl6RrIT4}#IJxBjAI45({R6Ow%I z9p|Gm({oPeC~HmIYWntK&i!hmw2s^PIZ_01VdjI%4>_-u>!)<2u1<9XQl1>V6@?9w zW>rRoAFCg>E&gNBkM*_Mqho%_Zrzz-g~TAl3E^vNHkuEb{V;A5^t@VqyiQ9WKP+BW zveu)}ig=U>=5nOH%_t1E(%g6<`DL2*oc_f@`of>t!QP5VksK|%iRa33TAMt+g2YLFfR zK1jSbiT$Vnq@}FMW8TlY5*%sJ)j~$L;avC*3}gSM=I|UA|Q!5!30RA7;ok8 zO=IO${>)hudkG^tP~dS z29j1%QUdL?0)BLbfd8$BBjV9JS_n9ZM3~4d%^M^wB@NouC42Z^og(Y*cL|Hd{@oEd zhVLQnbSDD_%YnZC1_=BZm3_k}15n=`D>A6M>JBs_|sgod-fM7YGw1TCy zw6d&>GFV1RK~5F)3)S!DNCb*Nnhzl22fb8>Sc1X&VDK4Pd5a%r|EKa#OSnIrbaGRd z`APdn^>dR^CqK4lVn+66-?l z@8?<^iNNjFN&hg%!SFCQJPhZ)+pvr4i^U^;u7kUiwBaOTyw?CyS4F^;e=|`EQZl3% zciX=QNAxC{Bap5r3=;7@0`mG-0~laju>#Tn65dW&|EebQ-_&IPo0=S1?Z+ZjCU?H~ z>+hM^ss8=d1eu##x)VKJFfbI_8${SGO5reW^GwU$)06QNE@#h0 z`$LNFwMhM&s8^>7~I^^Qr8&c5Xq! z`@(Y0ll_z(gi2NCNqfvqM=b?Hs%Zl@A4LJO#YWHmgr)&S>E|Tc5idCwsk~N6DtL3gmqbeG}a*Hp5H{*P%2%z?>taXma|r0_Q9Fzu-*Uxuz+d zbXV^QNtWPv8mJ}~Z5K_Xs-jx7fUH;jL`T3@yt+4e<y&zxA7;dk@?vZNeb zTtL+C?YeGX>bP^`qmSdDq)dU&P_VU1*H#RFXvm+Z{<2;jqwn@rJI65AURb&oU~zT8x&%;gCYX1ael9f=@aQam&z z8iZ{mhh19JPKwri^46Hr(<$3A7S+~PT37k1k?P`BQm*TOTd?wb%j{4Eo548V&Mcb5 zJi(yItNmfwcWHZ{3t43X-6Z)&9LFNxg@hbe9N~RLg?T4BVjbQdmmB)^lci`-QfPTV zWw-$`lrw4gT89&QOuXJmeOB7A?8eNbK&UWf(N_&E8#>@2b(7nKAcsyb zBaxbS*SYH0@(OL$Js?$W_g5OLfQ`#`IPFhV8Xt#lq@x*n)MqNJR-DFCE)VrK#tAE^ z4{DwseeEB0OLm|Gfsk=VavxN`k@#3U40T-of@%AQ{BCwt<~4~D2Bc0U^M{1&J9mLe zrPW)P;1U*BVwy!NY4x^MUKr~-*d{pZ9}7w5DC(4-OQmPGwm+64p7e@v+NXLX^>!=n z?UCc16}BESv{hHy1K)llnA+bR)4Um0PWfty;ykX=cub&dp8`00Lt^FX+I4i~5AhET1IdSs*826vY^X4ZO zw-=d?-^%*K+BUco>SQl!Klf6Uj-5J_va#mK(HzNy9Hq)@&=~RKPdMfhFV%oHM}hb2 zEP%A!v4<3WmEAvkO7mP??%W7o(va&AHEvRI-2@~*d_Q&pF}U2^m2@q5!quk((WGNR z8ThGNaFt>Kw@fA2=8*NW<&U#@#~eN$)|h;t1t)?1*kMPjpGj)D+_yJ+IC2|3KWz0!ZYV?VH=C2 zAC_CS!Na>EPx+M2qEl=7=Ha4eVxy>&6$|if=+pb{0cGV~v;1+lS~FX=k3sW+Mz7_e z*-cFbjQw#Q=PCO9Z%8V7)RkiOx&zFHpFL54OhV|UEY3YZ3Q zh&L*xtBO`VD!P<;63WgIN_X7+&kK6u;jzJ&LMAZ*Oi#E|AD?U-8*HJ3JoYG;IcxSZ zY+=chCV{soO0>P#a=D6|KQWfsFuF2;EB(vrQ`z?$9*3N|*b~EF;rt_!@q46y#ufexq`kz(e?_VJ1 Date: Tue, 17 Feb 2015 14:14:01 -0700 Subject: [PATCH 3/9] Added files to link file structure --- .../_08-NightLight.ino/_08-NightLight.ino.ino | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Project05_NightLight/08-NightLight/_08-NightLight.ino/_08-NightLight.ino.ino diff --git a/Project05_NightLight/08-NightLight/_08-NightLight.ino/_08-NightLight.ino.ino b/Project05_NightLight/08-NightLight/_08-NightLight.ino/_08-NightLight.ino.ino new file mode 100644 index 0000000..95c2b6e --- /dev/null +++ b/Project05_NightLight/08-NightLight/_08-NightLight.ino/_08-NightLight.ino.ino @@ -0,0 +1,9 @@ +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + +} From c260bc09530efd2f87fa6c2be35822175ed94086 Mon Sep 17 00:00:00 2001 From: Toni Klopfenstein Date: Tue, 17 Feb 2015 13:56:19 -0800 Subject: [PATCH 4/9] Adding file for demo --- Demo_Project/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Demo_Project/README.md diff --git a/Demo_Project/README.md b/Demo_Project/README.md new file mode 100644 index 0000000..feac4a2 --- /dev/null +++ b/Demo_Project/README.md @@ -0,0 +1,2 @@ +# SIK_rework +Re-work repository for all code examples, fritzing diagrams, and photos From 942eb143d4e49cc3a1b6188e681e697afab1d501 Mon Sep 17 00:00:00 2001 From: Brian Huang Date: Tue, 17 Feb 2015 15:01:14 -0700 Subject: [PATCH 5/9] Updated readme.m --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index feac4a2..911a6fc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # SIK_rework Re-work repository for all code examples, fritzing diagrams, and photos + +The focus is on projects rather than individual code activities. Some projects might have just one code / circuit example, others will have multiple. The outline for all of the circuits is as follows: + + + +* Project01_LightHouse + * 01-Blink +* Project02_StopLightRRcrossing + * 02-2LEDs +Project03_9LEDMatrix + * 03-MultipleLEDs +Project04_RGBLamp + * 04-ButtonPush + * 05-FadingLED + * 06-RGBColorMixingh + * 07-DimmerKnob + + Project05_NightLight +Project06_BalanceBeamGrabber +Project07_FanSpiroGraph +Project08_GreenHouse +Project09_DrawbotRedux +Project10_ReactionTimer +Project11_GameControllerMazeGame +Project12_FunOmeter +Project13_Therimin +Project14_Simon +Project15_VendingMachine + +Demo Project \ No newline at end of file From fbcf29b3823c972a00aa57565a4097a8c0395c8b Mon Sep 17 00:00:00 2001 From: mando10 Date: Tue, 17 Feb 2015 15:22:52 -0700 Subject: [PATCH 6/9] Adding in real railroad sketch Swapping out actual sketch for actual one that Maya and I did. --- .../RailRoadCrossing/.DS_Store | Bin 0 -> 6148 bytes .../RailRoadCrossing/RailRoadCrossing.ino | 0 .../RailRoadCrossing/railroad_blink.ino | 30 ++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 Project02_StopLightRRcrossing/RailRoadCrossing/.DS_Store delete mode 100644 Project02_StopLightRRcrossing/RailRoadCrossing/RailRoadCrossing.ino create mode 100644 Project02_StopLightRRcrossing/RailRoadCrossing/railroad_blink.ino diff --git a/Project02_StopLightRRcrossing/RailRoadCrossing/.DS_Store b/Project02_StopLightRRcrossing/RailRoadCrossing/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Thu, 19 Feb 2015 16:46:51 -0700 Subject: [PATCH 7/9] Lighthouse Making an LED light up like a lighthouse light. --- .../LightHouse/LightHouse.ino | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Project01_LightHouse/LightHouse/LightHouse.ino b/Project01_LightHouse/LightHouse/LightHouse.ino index e69de29..5e43cd1 100644 --- a/Project01_LightHouse/LightHouse/LightHouse.ino +++ b/Project01_LightHouse/LightHouse/LightHouse.ino @@ -0,0 +1,24 @@ +/* + Blink + Turns on an LED on for one second, then off for one second, repeatedly. + + This example code is in the public domain. + */ + +// Pin 13 has an LED connected on most Arduino boards. +// give it a name: +int led = 13; + +// the setup routine runs once when you press reset: +void setup() { + // initialize the digital pin as an output. + pinMode(led, OUTPUT); +} + +// the loop routine runs over and over again forever: +void loop() { + digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) + delay(2000); // wait for a second + digitalWrite(led, LOW); // turn the LED off by making the voltage LOW + delay(2000); // wait for a second +} From 6ed8599d289b03bd794d389b035da42303200be9 Mon Sep 17 00:00:00 2001 From: Mike Grusin Date: Fri, 19 Feb 2016 16:30:47 -0700 Subject: [PATCH 8/9] not sure what changed --- Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino | 86 +++++++++++++++++++ .../SoundBarGraph/SoundBarGraph.ino | 71 +++++++++++++++ 2 files changed, 157 insertions(+) diff --git a/Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino b/Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino index e69de29..737c3c9 100644 --- a/Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino +++ b/Project03_9LEDMatrix/LEDMatrix/LEDMatrix.ino @@ -0,0 +1,86 @@ +// Declare a 2-dimensional array of variables +// called "matrix". We'll initialize it with the +// pin numbers of the LEDs we're using: + +int matrix[3][3] = {2,3,4, + 5,6,7, + 8,9,10}; + +// To read a number out of the matrix, use y (vertical) +// and x (horizontal) indexes from 0 to 2: + +// X +// 0 1 2 +// +// 0 2 3 4 +// Y 1 5 6 7 +// 2 8 9 10 + +// When reading or writing from an array, enclose the +// indexes in brackets, and put the Y index first: + +// matrix[0][0] returns 2 +// matrix[0][1] returns 3 +// matrix[1][0] returns 5 +// matrix[2][0] returns 8 +// matrix[2][2] returns 10 + +void setup() +{ + int x,y; + + // Step through the whole matrix using x and y + // Make each pin an output + // And turn the output off (LOW): + + // This for loop will step y from 0 to 2 + + for (y=0; y<=2; x++) + { + for (x=0; x<=2; x++) + { + pinMode(matrix[y][x],OUTPUT); + digitalWrite(matrix[y][x],LOW); + } + } +} + +void loop() +{ + int x,y; + + // These random number generators will return numbers + // from 0 to 2: + + x = random(3); + y = random(3); + + digitalWrite(matrix[y][x],HIGH); + delay(100); + digitalWrite(matrix[y][x],LOW); +} + +void single(int x, int y, boolean on) +{ + digitalWrite(matrix[y][x],on); +} + +void row(int y, boolean on) +{ + int x; + + for (x=0; x<3; x++) + { + single(x,y,on); + } +} + +void column(int y, boolean on) +{ + int x; + + for (x=0; x<3; x++) + { + single(x,y,on); + } +} diff --git a/Project12_FunOmeter/SoundBarGraph/SoundBarGraph.ino b/Project12_FunOmeter/SoundBarGraph/SoundBarGraph.ino index e69de29..1488a69 100644 --- a/Project12_FunOmeter/SoundBarGraph/SoundBarGraph.ino +++ b/Project12_FunOmeter/SoundBarGraph/SoundBarGraph.ino @@ -0,0 +1,71 @@ + +const int MICPIN = 0; + +void setup() +{} + +void loop() +{ + int volume,x; + static int highest = 0; + float percent; + + volume = measureVolume(200); + + if (volume > highest) highest = volume; + + percent = (volume / highest)*10; + + for (x=0; x highest) + { + highest = sample; + } + + if (sample < lowest) + { + lowest = sample; + } + } + + // The volume is the amplitude of the waveform, + // which is the difference between the highest and lowest + // values. + + return highest-lowest; +} From 994ec7f28b94d5a0c370906ea51cfda8d21f525a Mon Sep 17 00:00:00 2001 From: Mike Grusin Date: Thu, 25 May 2017 10:35:36 -0600 Subject: [PATCH 9/9] Therimin -> theremin --- .../Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino | 0 .../Therimin.ino => Project13_Theremin/Theremin/Theremin.ino | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {Project13_Therimin => Project13_Theremin}/Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino (100%) rename Project13_Therimin/Therimin/Therimin.ino => Project13_Theremin/Theremin/Theremin.ino (100%) diff --git a/Project13_Therimin/Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino b/Project13_Theremin/Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino similarity index 100% rename from Project13_Therimin/Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino rename to Project13_Theremin/Exp17-ToneMusicMaking/Exp17-ToneMusicMaking.ino diff --git a/Project13_Therimin/Therimin/Therimin.ino b/Project13_Theremin/Theremin/Theremin.ino similarity index 100% rename from Project13_Therimin/Therimin/Therimin.ino rename to Project13_Theremin/Theremin/Theremin.ino