1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-07 00:04:36 +03:00

Run new astyle formatter against all the examples

This commit is contained in:
Federico Fissore
2013-10-21 09:58:40 +02:00
parent 3c6ee46828
commit b4c68b3dff
259 changed files with 5160 additions and 5217 deletions

View File

@@ -1,58 +1,58 @@
/*
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
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
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
// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, youre 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);
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);
// declare the switch pin as an input
pinMode(2, INPUT);
}
void loop(){
void loop() {
// read the value of the switch
// digitalRead() checks to see if there is voltage
// on the pin or not
// on the pin or not
switchstate = digitalRead(2);
// if the button is not pressed
// blink the red LEDs
// 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.
// this else is part of the above if() statement.
// if the switch is not LOW (the button is pressed)
// the code below will run
// 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

View File

@@ -1,21 +1,21 @@
/*
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
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
This example code is part of the public domain
*/
// named constant for the pin the sensor is connected to
@@ -23,28 +23,28 @@ const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;
void setup(){
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);
for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop(){
// read the value on AnalogIn pin 0
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);
Serial.print(sensorVal);
// convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
float voltage = (sensorVal / 1024.0) * 5.0;
// Send the voltage level out the Serial port
Serial.print(", Volts: ");
@@ -54,28 +54,28 @@ void loop(){
// the sensor changes 10 mV per degree
// the datasheet says there's a 500 mV offset
// ((volatge - 500mV) times 100)
Serial.print(", degrees C: ");
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){
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){
} // 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){
} // 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){
else if (temperature >= baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);

View File

@@ -1,56 +1,56 @@
/*
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
1 RGB LED
three 10 kilohm resistors
3 220 ohm resistors
3 photoresistors
red green and blue colored gels
Created 13 September 2012
Modified 14 November 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
http://arduino.cc/starterKit
This example code is part of the public domain
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
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
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);
Serial.begin(9600);
// set the digital pins as outputs
pinMode(greenLEDPin,OUTPUT);
pinMode(redLEDPin,OUTPUT);
pinMode(blueLEDPin,OUTPUT);
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
@@ -60,9 +60,9 @@ void loop() {
// give the ADC a moment to settle
delay(5);
// read the value from the blue-filtered photoresistor:
blueSensorValue = analogRead(blueSensorPin);
blueSensorValue = analogRead(blueSensorPin);
// print out the values to the serial monitor
// print out the values to the serial monitor
Serial.print("raw sensor Values \t red: ");
Serial.print(redSensorValue);
Serial.print("\t green: ");
@@ -71,22 +71,22 @@ void loop() {
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.
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;
redValue = redSensorValue / 4;
greenValue = greenSensorValue / 4;
blueValue = blueSensorValue / 4;
// print out the mapped values
// 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);
Serial.println(blueValue);
/*
Now that you have a usable value, it's time to PWM the LED.

View File

@@ -1,34 +1,34 @@
/*
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
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
This example code is part of the public domain
*/
// include the servo library
#include <Servo.h>
Servo myServo; // create a servo object
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
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
myServo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // open a serial connection to your computer
}
@@ -38,17 +38,17 @@ void loop() {
Serial.print("potVal: ");
Serial.print(potVal);
// scale the numbers from the pot
// scale the numbers from the pot
angle = map(potVal, 0, 1023, 0, 179);
// print out the angle for the servo motor
// print out the angle for the servo motor
Serial.print(", angle: ");
Serial.println(angle);
Serial.println(angle);
// set the servo position
// set the servo position
myServo.write(angle);
// wait for the servo to get there
// wait for the servo to get there
delay(15);
}

View File

@@ -1,21 +1,21 @@
/*
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
10 kilohm resistor
piezo
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// variable to hold sensor value

View File

@@ -1,32 +1,32 @@
/*
Arduino Starter Kit example
Project 7 - Keyboard
This sketch is written to accompany Project 7 in the
Arduino Starter Kit
Parts required:
two 10 kilohm resistors
1 Megohm resistor
1 Megohm resistor
220 ohm resistor
4 pushbuttons
piezo
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// create an array of notes
// the numbers below correspond to
// the numbers below correspond to
// the frequencies of middle C, D, E, and F
int notes[] = {262, 294, 330, 349};
void setup() {
//start serial communication
//start serial communication
Serial.begin(9600);
}
@@ -35,27 +35,27 @@ void loop() {
int keyVal = analogRead(A0);
// send the value from A0 to the Serial Monitor
Serial.println(keyVal);
// play the note corresponding to each value on A0
if(keyVal == 1023){
if (keyVal == 1023) {
// play the first frequency in the array on pin 8
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010){
else if (keyVal >= 990 && keyVal <= 1010) {
// play the second frequency in the array on pin 8
tone(8, notes[1]);
}
else if(keyVal >= 505 && keyVal <= 515){
else if (keyVal >= 505 && keyVal <= 515) {
// play the third frequency in the array on pin 8
tone(8, notes[2]);
}
else if(keyVal >= 5 && keyVal <= 10){
else if (keyVal >= 5 && keyVal <= 10) {
// play the fourth frequency in the array on pin 8
tone(8, notes[3]);
}
else{
else {
// if the value is out of range, play no tone
noTone(8);
}
}

View File

@@ -1,22 +1,22 @@
/*
Arduino Starter Kit example
Project 8 - Digital Hourglass
This sketch is written to accompany Project 8 in the
Arduino Starter Kit
Parts required:
10 kilohm resistor
six 220 ohm resistors
six LEDs
tilt switch
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// named constant for the switch pin
@@ -28,50 +28,50 @@ int prevSwitchState = 0; // the previous switch state
int led = 2; // a variable to refer to the LEDs
// 600000 = 10 minutes in milliseconds
long interval = 600000; // interval at which to light the next LED
long interval = 600000; // interval at which to light the next LED
void setup() {
// set the LED pins as outputs
for(int x = 2;x<8;x++){
for (int x = 2; x < 8; x++) {
pinMode(x, OUTPUT);
}
// set the tilt switch pin as input
// set the tilt switch pin as input
pinMode(switchPin, INPUT);
}
void loop(){
// store the time since the Arduino started running in a variable
unsigned long currentTime = millis();
void loop() {
// store the time since the Arduino started running in a variable
unsigned long currentTime = millis();
// compare the current time to the previous time an LED turned on
// if it is greater than your interval, run the if statement
if(currentTime - previousTime > interval) {
// save the current time as the last time you changed an LED
previousTime = currentTime;
if (currentTime - previousTime > interval) {
// save the current time as the last time you changed an LED
previousTime = currentTime;
// Turn the LED on
digitalWrite(led, HIGH);
// increment the led variable
// in 10 minutes the next LED will light up
led++;
if(led == 7){
// in 10 minutes the next LED will light up
led++;
if (led == 7) {
// the hour is up
}
}
// read the switch value
switchState = digitalRead(switchPin);
switchState = digitalRead(switchPin);
// if the switch has changed
if(switchState != prevSwitchState){
if (switchState != prevSwitchState) {
// turn all the LEDs low
for(int x = 2;x<8;x++){
for (int x = 2; x < 8; x++) {
digitalWrite(x, LOW);
}
}
// reset the LED variable to the first one
led = 2;
//reset the timer
previousTime = currentTime;
}

View File

@@ -1,10 +1,10 @@
/*
Arduino Starter Kit example
Project 9 - Motorized Pinwheel
This sketch is written to accompany Project 9 in the
Arduino Starter Kit
Parts required:
10 kilohm resistor
pushbutton
@@ -12,13 +12,13 @@
9V battery
IRF520 MOSFET
1N4007 diode
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// named constants for the switch and motor pins
@@ -29,22 +29,22 @@ int switchState = 0; // variable for reading the switch's status
void setup() {
// initialize the motor pin as an output:
pinMode(motorPin, OUTPUT);
pinMode(motorPin, OUTPUT);
// initialize the switch pin as an input:
pinMode(switchPin, INPUT);
pinMode(switchPin, INPUT);
}
void loop(){
void loop() {
// read the state of the switch value:
switchState = digitalRead(switchPin);
// check if the switch is pressed.
if (switchState == HIGH) {
// turn motor on:
digitalWrite(motorPin, HIGH);
}
if (switchState == HIGH) {
// turn motor on:
digitalWrite(motorPin, HIGH);
}
else {
// turn motor off:
digitalWrite(motorPin, LOW);
digitalWrite(motorPin, LOW);
}
}

View File

@@ -1,10 +1,10 @@
/*
Arduino Starter Kit example
Project 10 - Zoetrope
This sketch is written to accompany Project 10 in the
Arduino Starter Kit
Parts required:
two 10 kilohm resistors
2 momentary pushbuttons
@@ -12,14 +12,14 @@
motor
9V battery
H-Bridge
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
This example code is part of the public domain
*/
const int controlPin1 = 2; // connected to pin 7 on the H-bridge
@@ -39,7 +39,7 @@ int motorEnabled = 0; // Turns the motor on/off
int motorSpeed = 0; // speed of the motor
int motorDirection = 1; // current direction of the motor
void setup(){
void setup() {
// intialize the inputs and outputs
pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT);
@@ -51,44 +51,44 @@ void setup(){
digitalWrite(enablePin, LOW);
}
void loop(){
void loop() {
// read the value of the on/off switch
onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
delay(1);
// read the value of the direction switch
directionSwitchState = digitalRead(directionSwitchPin);
// read the value of the pot and divide by 4 to get
// read the value of the pot and divide by 4 to get
// a value that can be used for PWM
motorSpeed = analogRead(potPin)/4;
motorSpeed = analogRead(potPin) / 4;
// if the on/off button changed state since the last loop()
if(onOffSwitchState != previousOnOffSwitchState){
if (onOffSwitchState != previousOnOffSwitchState) {
// change the value of motorEnabled if pressed
if(onOffSwitchState == HIGH){
if (onOffSwitchState == HIGH) {
motorEnabled = !motorEnabled;
}
}
// if the direction button changed state since the last loop()
if (directionSwitchState != previousDirectionSwitchState) {
// change the value of motorDirection if pressed
// change the value of motorDirection if pressed
if (directionSwitchState == HIGH) {
motorDirection = !motorDirection;
}
}
}
// change the direction the motor spins by talking
// to the control pins on the H-Bridge
if (motorDirection == 1) {
digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);
}
}
else {
digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);
}
}
// if the motor is supposed to be on
if (motorEnabled == 1) {
@@ -99,7 +99,7 @@ void loop(){
//turn the motor off
analogWrite(enablePin, 0);
}
// save the current On/Offswitch state as the previous
// save the current On/Offswitch state as the previous
previousDirectionSwitchState = directionSwitchState;
// save the current switch state as the previous
previousOnOffSwitchState = onOffSwitchState;

View File

@@ -1,24 +1,24 @@
/*
Arduino Starter Kit example
Project 11 - Crystal Ball
This sketch is written to accompany Project 11 in the
Arduino Starter Kit
Parts required:
220 ohm resistor
10 kilohm resistor
10 kilohm potentiometer
16x2 LCD screen
tilt switch
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// include the library code:
@@ -40,12 +40,12 @@ int prevSwitchState = 0;
int reply;
void setup() {
// set up the number of columns and rows on the LCD
// set up the number of columns and rows on the LCD
lcd.begin(16, 2);
// set up the switch pin as an input
pinMode(switchPin,INPUT);
pinMode(switchPin, INPUT);
// Print a message to the LCD.
lcd.print("Ask the");
// set the cursor to column 0, line 1
@@ -62,57 +62,57 @@ void loop() {
// compare the switchState to its previous state
if (switchState != prevSwitchState) {
// if the state has changed from HIGH to LOW
// you know that the ball has been tilted from
// one direction to the other
// you know that the ball has been tilted from
// one direction to the other
if (switchState == LOW) {
// randomly chose a reply
reply = random(8);
// clean up the screen before printing a new reply
lcd.clear();
// set the cursor to column 0, line 0
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// print some text
lcd.print("the ball says:");
// move the cursor to the second line
lcd.setCursor(0, 1);
// choose a saying to print baed on the value in reply
switch(reply){
case 0:
lcd.print("Yes");
break;
// choose a saying to print baed on the value in reply
switch (reply) {
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likely");
break;
case 1:
lcd.print("Most likely");
break;
case 2:
lcd.print("Certainly");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook good");
break;
case 3:
lcd.print("Outlook good");
break;
case 4:
lcd.print("Unsure");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask again");
break;
case 5:
lcd.print("Ask again");
break;
case 6:
lcd.print("Doubtful");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
case 7:
lcd.print("No");
break;
}
}
}
// save the current switch state as the last state
// save the current switch state as the last state
prevSwitchState = switchState;
}

View File

@@ -1,10 +1,10 @@
/*
Arduino Starter Kit example
Project 12 - Knock Lock
This sketch is written to accompany Project 12 in the
Arduino Starter Kit
Parts required:
1 Megohm resistor
10 kilohm resistor
@@ -16,17 +16,17 @@
one yellow LED
one green LED
100 uF capacitor
Created 18 September 2012
by Scott Fitzgerald
Thanks to Federico Vanzati for improvements
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// import the library
// import the library
#include <Servo.h>
// create an instance of the servo library
Servo myServo;
@@ -51,7 +51,7 @@ boolean locked = false;
// how many valid knocks you've received
int numberOfKnocks = 0;
void setup(){
void setup() {
// attach the servo to pin 9
myServo.attach(9);
@@ -76,22 +76,22 @@ void setup(){
Serial.println("the box is unlocked!");
}
void loop(){
void loop() {
// if the box is unlocked
if(locked == false){
if (locked == false) {
// read the value of the switch pin
switchVal = digitalRead(switchPin);
// if the button is pressed, lock the box
if(switchVal == HIGH){
if (switchVal == HIGH) {
// set the locked variable to "true"
locked = true;
// change the status LEDs
digitalWrite(greenLed,LOW);
digitalWrite(redLed,HIGH);
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
// move the servo to the locked position
myServo.write(90);
@@ -105,16 +105,16 @@ void loop(){
}
// if the box is locked
if(locked == true){
if (locked == true) {
// check the value of the piezo
knockVal = analogRead(piezo);
// if there are not enough valid knocks
if(numberOfKnocks < 3 && knockVal > 0){
if (numberOfKnocks < 3 && knockVal > 0) {
// check to see if the knock is in range
if(checkForKnock(knockVal) == true){
if (checkForKnock(knockVal) == true) {
// increment the number of valid knocks
numberOfKnocks++;
@@ -126,7 +126,7 @@ void loop(){
}
// if there are three knocks
if(numberOfKnocks >= 3){
if (numberOfKnocks >= 3) {
// unlock the box
locked = false;
@@ -137,19 +137,19 @@ void loop(){
delay(20);
// change status LEDs
digitalWrite(greenLed,HIGH);
digitalWrite(redLed,LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
Serial.println("the box is unlocked!");
}
}
}
// this function checks to see if a
// this function checks to see if a
// detected knock is within max and min range
boolean checkForKnock(int value){
boolean checkForKnock(int value) {
// if the value of the knock is greater than
// the minimum, and larger than the maximum
if(value > quietKnock && value < loudKnock){
if (value > quietKnock && value < loudKnock) {
// turn the status LED on
digitalWrite(yellowLed, HIGH);
delay(50);
@@ -164,7 +164,7 @@ boolean checkForKnock(int value){
else {
// print status
Serial.print("Bad knock value ");
Serial.println(value);
Serial.println(value);
// return false
return false;
}

View File

@@ -1,26 +1,26 @@
/*
Arduino Starter Kit example
Project 13 - Touch Sensor Lamp
This sketch is written to accompany Project 13 in the
Arduino Starter Kit
Parts required:
1 Megohm resistor
metal foil or copper mesh
220 ohm resistor
LED
Software required :
Software required :
CapacitiveSensor library by Paul Badger
http://arduino.cc/playground/Main/CapacitiveSensor
Created 18 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
// import the library (must be located in the
@@ -30,7 +30,7 @@
// create an instance of the library
// pin 4 sends electrical energy
// pin 2 senses senses a change
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
CapacitiveSensor capSensor = CapacitiveSensor(4, 2);
// threshold for turning the lamp on
int threshold = 1000;
@@ -51,10 +51,10 @@ void loop() {
long sensorValue = capSensor.capacitiveSensor(30);
// print out the sensor value
Serial.println(sensorValue);
Serial.println(sensorValue);
// if the value is greater than the threshold
if(sensorValue > threshold) {
if (sensorValue > threshold) {
// turn the LED on
digitalWrite(ledPin, HIGH);
}

View File

@@ -1,23 +1,23 @@
/*
Arduino Starter Kit example
Project 14 - Tweak the Arduino Logo
This sketch is written to accompany Project 14 in the
Arduino Starter Kit
Parts required:
10 kilohm potentiometer
Software required :
Software required :
Processing http://processing.org
Active internet connection
Created 18 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
@@ -27,9 +27,9 @@ void setup() {
}
void loop() {
// read the value of A0, divide by 4 and
// read the value of A0, divide by 4 and
// send it as a byte over the serial connection
Serial.write(analogRead(A0)/4);
Serial.write(analogRead(A0) / 4);
delay(1);
}
@@ -37,68 +37,68 @@ void loop() {
// Tweak the Arduno Logo
// by Scott Fitzgerald
// This example code is in the public domain
// import the serial library
import processing.serial.*;
// create an instance of the serial library
Serial myPort;
// create an instance of PImage
PImage logo;
// a variable to hold the background color
int bgcolor = 0;
void setup() {
// set the color mode to Hue/Saturation/Brightness
colorMode(HSB, 255);
// load the Arduino logo into the PImage instance
logo = loadImage("http://arduino.cc/en/pub/skins/arduinoWide/img/logo.png");
// make the window the same size as the image
size(logo.width, logo.height);
// print a list of available serial ports to the
// print a list of available serial ports to the
// Processing staus window
println("Available serial ports:");
println(Serial.list());
// Tell the serial object the information it needs to communicate
// with the Arduno. Change Serial.list()[0] to the correct
// with the Arduno. Change Serial.list()[0] to the correct
// port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
// Arduino sketch.
myPort = new Serial(this, Serial.list()[0], 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
// port = new Serial(this, "COM1", 9600);
// port = new Serial(this, "COM1", 9600);
}
void draw() {
// if there is information in the serial port
if ( myPort.available() > 0) {
// read the value and store it in a variable
bgcolor = myPort.read();
// print the value to the status window
println(bgcolor);
println(bgcolor);
}
// Draw the background. the variable bgcolor
// contains the Hue, determined by the value
// from the serial port
background(bgcolor, 255, 255);
// draw the Arduino logo
image(logo, 0, 0);
}
*/

View File

@@ -1,37 +1,37 @@
/*
Arduino Starter Kit example
Project 15 - Hacking Buttons
This sketch is written to accompany Project 15 in the
Arduino Starter Kit
Parts required:
batery powered component
220 ohm resistor
4N35 optocoupler
Created 18 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit
This example code is part of the public domain
This example code is part of the public domain
*/
const int optoPin = 2; // the pin the optocoupler is connected to
void setup(){
// make the pin with the optocoupler an output
void setup() {
// make the pin with the optocoupler an output
pinMode(optoPin, OUTPUT);
}
void loop(){
digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler
delay(15); // give the optocoupler a moment to activate
digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again
delay(21000); // wait for 21 seconds
void loop() {
digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler
delay(15); // give the optocoupler a moment to activate
digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again
delay(21000); // wait for 21 seconds
}