forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,171 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
build/shared/examples/10.StarterKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
Arduino Starter Kit example | ||
Project 2 - Spaceship Interface | ||
This sketch is written to accompany Project 2 in the | ||
Arduino Starter Kit | ||
Parts required: | ||
1 green LED | ||
2 red LEDs | ||
pushbutton | ||
10 kilohm resistor | ||
3 220 ohm resistors | ||
Created 13 September 2012 | ||
by Scott Fitzgerald | ||
http://arduino.cc/starterKit | ||
This example code is part of the public domain | ||
*/ | ||
|
||
// Create a global variable to hold the | ||
// state of the switch. This variable is persistent | ||
// throughout the program. Whenever you refer to | ||
// switchState, you’re talking about the number it holds | ||
int switchstate = 0; | ||
|
||
void setup(){ | ||
// declare the LED pins as outputs | ||
pinMode(3,OUTPUT); | ||
pinMode(4,OUTPUT); | ||
pinMode(5,OUTPUT); | ||
|
||
// declare the switch pin as an input | ||
pinMode(2,INPUT); | ||
} | ||
|
||
void loop(){ | ||
|
||
// read the value of the switch | ||
// digitalRead() checks to see if there is voltage | ||
// on the pin or not | ||
switchstate = digitalRead(2); | ||
|
||
// if the button is not pressed | ||
// blink the red LEDs | ||
if (switchstate == LOW) { | ||
digitalWrite(3, HIGH); // turn the green LED on pin 3 on | ||
digitalWrite(4, LOW); // turn the red LED on pin 4 off | ||
digitalWrite(5, LOW); // turn the red LED on pin 5 off | ||
} | ||
// this else is part of the above if() statement. | ||
// if the switch is not LOW (the button is pressed) | ||
// the code below will run | ||
else { | ||
digitalWrite(3, LOW); // turn the green LED on pin 3 off | ||
digitalWrite(4, LOW); // turn the red LED on pin 4 off | ||
digitalWrite(5, HIGH); // turn the red LED on pin 5 on | ||
// wait for a quarter second before changing the light | ||
delay(250); | ||
digitalWrite(4, HIGH); // turn the red LED on pin 4 on | ||
digitalWrite(5, LOW); // turn the red LED on pin 5 off | ||
// wait for a quarter second before changing the light | ||
delay(250); | ||
} | ||
} | ||
|
84 changes: 84 additions & 0 deletions
84
build/shared/examples/10.StarterKit/p03_LoveOMeter/p03_LoveOMeter.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Arduino Starter Kit example | ||
Project 3 - Love-O-Meter | ||
This sketch is written to accompany Project 3 in the | ||
Arduino Starter Kit | ||
Parts required: | ||
1 TMP36 temperature sensor | ||
3 red LEDs | ||
3 220 ohm resistors | ||
Created 13 September 2012 | ||
by Scott Fitzgerald | ||
http://arduino.cc/starterKit | ||
This example code is part of the public domain | ||
*/ | ||
|
||
// named constant for the pin the sensor is connected to | ||
const int sensorPin = A0; | ||
// room temperature in Celcius | ||
const float baselineTemp = 20.0; | ||
|
||
void setup(){ | ||
// open a serial connection to display values | ||
Serial.begin(9600); | ||
// set the LED pins as outputs | ||
// the for() loop saves some extra coding | ||
for(int pinNumber = 2; pinNumber<5; pinNumber++){ | ||
pinMode(pinNumber,OUTPUT); | ||
digitalWrite(pinNumber, LOW); | ||
} | ||
} | ||
|
||
void loop(){ | ||
// read the value on AnalogIn pin 0 | ||
// and store it in a variable | ||
int sensorVal = analogRead(sensorPin); | ||
|
||
// send the 10-bit sensor value out the serial port | ||
Serial.print("sensor Value: "); | ||
Serial.print(sensorVal); | ||
|
||
// convert the ADC reading to voltage | ||
float voltage = (sensorVal/1024.0) * 5.0; | ||
|
||
// Send the voltage level out the Serial port | ||
Serial.print(", Volts: "); | ||
Serial.print(voltage); | ||
|
||
// convert the voltage to temperature in degrees C | ||
// the sensor changes 10 mV per degree | ||
// the datasheet says there's a 500 mV offset | ||
// ((volatge - 500mV) times 100) | ||
Serial.print(", degrees C: "); | ||
float temperature = (voltage - .5) * 100; | ||
Serial.println(temperature); | ||
|
||
// if the current temperature is lower than the baseline | ||
// turn off all LEDs | ||
if(temperature < baselineTemp){ | ||
digitalWrite(2, LOW); | ||
digitalWrite(3, LOW); | ||
digitalWrite(4, LOW); | ||
} // if the temperature rises 2-4 degrees, turn an LED on | ||
else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){ | ||
digitalWrite(2, HIGH); | ||
digitalWrite(3, LOW); | ||
digitalWrite(4, LOW); | ||
} // if the temperature rises 4-6 degrees, turn a second LED on | ||
else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){ | ||
digitalWrite(2, HIGH); | ||
digitalWrite(3, HIGH); | ||
digitalWrite(4, LOW); | ||
} // if the temperature rises more than 6 degrees, turn all LEDs on | ||
else if(temperature >= baselineTemp+6){ | ||
digitalWrite(2, HIGH); | ||
digitalWrite(3, HIGH); | ||
digitalWrite(4, HIGH); | ||
} | ||
delay(1); | ||
} |
97 changes: 97 additions & 0 deletions
97
build/shared/examples/10.StarterKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
Arduino Starter Kit example | ||
Project 4 - Color Mixing Lamp | ||
This sketch is written to accompany Project 3 in the | ||
Arduino Starter Kit | ||
Parts required: | ||
1 RGB LED | ||
three 10 kilohm resistors | ||
3 220 ohm resistors | ||
3 photoresistors | ||
red green aand blue colored gels | ||
Created 13 September 2012 | ||
by Scott Fitzgerald | ||
Thanks to Federico Vanzati for improvements | ||
http://arduino.cc/starterKit | ||
This example code is part of the public domain | ||
*/ | ||
|
||
const int greenLEDPin = 9; // LED connected to digital pin 9 | ||
const int redLEDPin = 10; // LED connected to digital pin 10 | ||
const int blueLEDPin = 11; // LED connected to digital pin 11 | ||
|
||
const int redSensorPin = A0; // pin with the photoresistor with the red gel | ||
const int greenSensorPin = A1; // pin with the photoresistor with the green gel | ||
const int blueSensorPin = A2; // pin with the photoresistor with the blue gel | ||
|
||
int redValue = 0; // value to write to the red LED | ||
int greenValue = 0; // value to write to the green LED | ||
int blueValue = 0; // value to write to the blue LED | ||
|
||
int redSensorValue = 0; // variable to hold the value from the red sensor | ||
int greenSensorValue = 0; // variable to hold the value from the green sensor | ||
int blueSensorValue = 0; // variable to hold the value from the blue sensor | ||
|
||
void setup() { | ||
// initialize serial communications at 9600 bps: | ||
Serial.begin(9600); | ||
|
||
// set the digital pins as outputs | ||
pinMode(greenLedPin,OUTPUT); | ||
pinMode(redLedPin,OUTPUT); | ||
pinMode(blueLedPin,OUTPUT); | ||
} | ||
|
||
void loop() { | ||
// Read the sensors first: | ||
|
||
// read the value from the red-filtered photoresistor: | ||
redsensorValue = analogRead(redsensorPin); | ||
// give the ADC a moment to settle | ||
delay(5); | ||
// read the value from the green-filtered photoresistor: | ||
greensensorValue = analogRead(greensensorPin); | ||
// give the ADC a moment to settle | ||
delay(5); | ||
// read the value from the blue-filtered photoresistor: | ||
bluesensorValue = analogRead(bluesensorPin); | ||
|
||
// print out the values to the serial monitor | ||
Serial.print("raw sensor Values \t red: "); | ||
Serial.print(redsensorValue); | ||
Serial.print("\t green: "); | ||
Serial.print(greensensorValue); | ||
Serial.print("\t Blue: "); | ||
Serial.println(bluesensorValue); | ||
|
||
/* | ||
In order to use the values from the sensor for the LED, | ||
you need to do some math. The ADC provides a 10-bit number, | ||
but analogWrite() uses 8 bits. You'll want to divide your | ||
sensor readings by 4 to keep them in range of the output. | ||
*/ | ||
redValue = redsensorValue/4; | ||
greenValue = greensensorValue/4; | ||
blueValue = bluesensorValue/4; | ||
|
||
// print out the mapped values | ||
Serial.print("Mapped sensor Values \t red: "); | ||
Serial.print(redValue); | ||
Serial.print("\t green: "); | ||
Serial.print(greenValue); | ||
Serial.print("\t Blue: "); | ||
Serial.println(blueValue); | ||
|
||
/* | ||
Now that you have a usable value, it's time to PWM the LED. | ||
*/ | ||
analogWrite(redLedPin, redValue); | ||
analogWrite(greenLedPin, greenValue); | ||
analogWrite(blueLedPin, blueValue); | ||
} | ||
|
55 changes: 55 additions & 0 deletions
55
build/shared/examples/10.StarterKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Arduino Starter Kit example | ||
Project 5 - Servo Mood Indicator | ||
This sketch is written to accompany Project 5 in the | ||
Arduino Starter Kit | ||
Parts required: | ||
servo motor | ||
10 kilohm potentiometer | ||
2 100 uF electrolytic capacitors | ||
Created 13 September 2012 | ||
by Scott Fitzgerald | ||
http://arduino.cc/starterKit | ||
This example code is part of the public domain | ||
*/ | ||
|
||
// include the servo library | ||
#include <Servo.h> | ||
|
||
Servo myServo; // create a servo object | ||
|
||
int const potPin = A0; // analog pin used to connect the potentiometer | ||
int potVal; // variable to read the value from the analog pin | ||
int angle; // variable to hold the angle for the servo motor | ||
|
||
void setup() { | ||
myServo.attach(9); // attaches the servo on pin 9 to the servo object | ||
Serial.begin(9600); // open a serial connection to your computer | ||
} | ||
|
||
void loop() { | ||
potVal = analogRead(potPin); // read the value of the potentiometer | ||
// print out the value to the serial monitor | ||
Serial.print("potVal: "); | ||
Serial.print(potVal); | ||
|
||
// scale the numbers from the pot | ||
angle = map(potVal, 0, 1023, 0, 179); | ||
|
||
// print out the angle for the servo motor | ||
Serial.print(", angle: "); | ||
Serial.println(angle); | ||
|
||
// set the servo position | ||
myServo.write(angle); | ||
|
||
// wait for the servo to get there | ||
delay(15); | ||
} | ||
|
||
|
64 changes: 64 additions & 0 deletions
64
build/shared/examples/10.StarterKit/p06_LightTheremin/p06_LightTheremin.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Arduino Starter Kit example | ||
Project 6 - Light Theremin | ||
This sketch is written to accompany Project 6 in the | ||
Arduino Starter Kit | ||
Parts required: | ||
photoresistor | ||
10 kilohm resistor | ||
piezo | ||
Created 13 September 2012 | ||
by Scott Fitzgerald | ||
http://arduino.cc/starterKit | ||
This example code is part of the public domain | ||
*/ | ||
|
||
// variable to hold sensor value | ||
int sensorValue; | ||
// variable to calibrate low value | ||
int sensorLow = 1023; | ||
// variable to calibrate high value | ||
int sensorHigh = 0; | ||
// LED pin | ||
const int ledPin = 13; | ||
|
||
void setup() { | ||
// Make the LED pin an output and turn it on | ||
pinMode(ledPin, OUTPUT); | ||
digitalWrite(ledPin, HIGH); | ||
|
||
// calibrate for the first five seconds after program runs | ||
while (millis() < 5000) { | ||
// record the maximum sensor value | ||
sensorValue = analogRead(A0); | ||
if (sensorValue > sensorHigh) { | ||
sensorHigh = sensorValue; | ||
} | ||
// record the minimum sensor value | ||
if (sensorValue < sensorLow) { | ||
sensorLow = sensorValue; | ||
} | ||
} | ||
// turn the LED off, signaling the end of the calibration period | ||
digitalWrite(ledPin, LOW); | ||
} | ||
|
||
void loop() { | ||
//read the input from A0 and store it in a variable | ||
sensorValue = analogRead(A0); | ||
|
||
// map the sensor values to a wide range of pitches | ||
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000); | ||
|
||
// play the tone for 20 ms on pin 8 | ||
tone(8, pitch, 20); | ||
|
||
// wait for a moment | ||
delay(10); | ||
} | ||
|
Oops, something went wrong.