Skip to content

Commit cc0a18d

Browse files
committed
Merge pull request #2 from Fede85/master
String examples corrections from Federico Vanzati merged.
2 parents ade4893 + 412f261 commit cc0a18d

File tree

1,112 files changed

+244484
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,112 files changed

+244484
-260
lines changed

Diff for: build/linux/work/arduino

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
APPDIR="$(dirname -- $(readlink -f -- "${0}") )"
4+
5+
cd $APPDIR
6+
7+
for LIB in \
8+
java/lib/rt.jar \
9+
java/lib/tools.jar \
10+
lib/*.jar \
11+
;
12+
do
13+
CLASSPATH="${CLASSPATH}:${LIB}"
14+
done
15+
export CLASSPATH
16+
17+
LD_LIBRARY_PATH=`pwd`/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
18+
export LD_LIBRARY_PATH
19+
20+
export PATH="${APPDIR}/java/bin:${PATH}"
21+
22+
java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
AnalogReadSerial
3+
Reads an analog input on pin 0, prints the result to the serial monitor
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
}
11+
12+
void loop() {
13+
int sensorValue = analogRead(A0);
14+
Serial.println(sensorValue);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
void setup() {
2+
// put your setup code here, to run once:
3+
4+
}
5+
6+
void loop() {
7+
// put your main code here, to run repeatedly:
8+
9+
}

Diff for: build/linux/work/examples/01.Basics/Blink/Blink.ino

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Blink
3+
Turns on an LED on for one second, then off for one second, repeatedly.
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
void setup() {
9+
// initialize the digital pin as an output.
10+
// Pin 13 has an LED connected on most Arduino boards:
11+
pinMode(13, OUTPUT);
12+
}
13+
14+
void loop() {
15+
digitalWrite(13, HIGH); // set the LED on
16+
delay(1000); // wait for a second
17+
digitalWrite(13, LOW); // set the LED off
18+
delay(1000); // wait for a second
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
DigitalReadSerial
3+
Reads a digital input on pin 2, prints the result to the serial monitor
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
void setup() {
9+
Serial.begin(9600);
10+
pinMode(2, INPUT);
11+
}
12+
13+
void loop() {
14+
int sensorValue = digitalRead(2);
15+
Serial.println(sensorValue);
16+
}
17+
18+
19+

Diff for: build/linux/work/examples/01.Basics/Fade/Fade.ino

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Fade
3+
4+
This example shows how to fade an LED on pin 9
5+
using the analogWrite() function.
6+
7+
This example code is in the public domain.
8+
9+
*/
10+
int brightness = 0; // how bright the LED is
11+
int fadeAmount = 5; // how many points to fade the LED by
12+
13+
void setup() {
14+
// declare pin 9 to be an output:
15+
pinMode(9, OUTPUT);
16+
}
17+
18+
void loop() {
19+
// set the brightness of pin 9:
20+
analogWrite(9, brightness);
21+
22+
// change the brightness for next time through the loop:
23+
brightness = brightness + fadeAmount;
24+
25+
// reverse the direction of the fading at the ends of the fade:
26+
if (brightness == 0 || brightness == 255) {
27+
fadeAmount = -fadeAmount ;
28+
}
29+
// wait for 30 milliseconds to see the dimming effect
30+
delay(30);
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* Blink without Delay
2+
3+
Turns on and off a light emitting diode(LED) connected to a digital
4+
pin, without using the delay() function. This means that other code
5+
can run at the same time without being interrupted by the LED code.
6+
7+
The circuit:
8+
* LED attached from pin 13 to ground.
9+
* Note: on most Arduinos, there is already an LED on the board
10+
that's attached to pin 13, so no hardware is needed for this example.
11+
12+
13+
created 2005
14+
by David A. Mellis
15+
modified 8 Feb 2010
16+
by Paul Stoffregen
17+
18+
This example code is in the public domain.
19+
20+
21+
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
22+
*/
23+
24+
// constants won't change. Used here to
25+
// set pin numbers:
26+
const int ledPin = 13; // the number of the LED pin
27+
28+
// Variables will change:
29+
int ledState = LOW; // ledState used to set the LED
30+
long previousMillis = 0; // will store last time LED was updated
31+
32+
// the follow variables is a long because the time, measured in miliseconds,
33+
// will quickly become a bigger number than can be stored in an int.
34+
long interval = 1000; // interval at which to blink (milliseconds)
35+
36+
void setup() {
37+
// set the digital pin as output:
38+
pinMode(ledPin, OUTPUT);
39+
}
40+
41+
void loop()
42+
{
43+
// here is where you'd put code that needs to be running all the time.
44+
45+
// check to see if it's time to blink the LED; that is, if the
46+
// difference between the current time and last time you blinked
47+
// the LED is bigger than the interval at which you want to
48+
// blink the LED.
49+
unsigned long currentMillis = millis();
50+
51+
if(currentMillis - previousMillis > interval) {
52+
// save the last time you blinked the LED
53+
previousMillis = currentMillis;
54+
55+
// if the LED is off turn it on and vice-versa:
56+
if (ledState == LOW)
57+
ledState = HIGH;
58+
else
59+
ledState = LOW;
60+
61+
// set the LED with the ledState of the variable:
62+
digitalWrite(ledPin, ledState);
63+
}
64+
}
65+
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Button
3+
4+
Turns on and off a light emitting diode(LED) connected to digital
5+
pin 13, when pressing a pushbutton attached to pin 2.
6+
7+
8+
The circuit:
9+
* LED attached from pin 13 to ground
10+
* pushbutton attached to pin 2 from +5V
11+
* 10K resistor attached to pin 2 from ground
12+
13+
* Note: on most Arduinos there is already an LED on the board
14+
attached to pin 13.
15+
16+
17+
created 2005
18+
by DojoDave <http://www.0j0.org>
19+
modified 30 Aug 2011
20+
by Tom Igoe
21+
22+
This example code is in the public domain.
23+
24+
http://www.arduino.cc/en/Tutorial/Button
25+
*/
26+
27+
// constants won't change. They're used here to
28+
// set pin numbers:
29+
const int buttonPin = 2; // the number of the pushbutton pin
30+
const int ledPin = 13; // the number of the LED pin
31+
32+
// variables will change:
33+
int buttonState = 0; // variable for reading the pushbutton status
34+
35+
void setup() {
36+
// initialize the LED pin as an output:
37+
pinMode(ledPin, OUTPUT);
38+
// initialize the pushbutton pin as an input:
39+
pinMode(buttonPin, INPUT);
40+
}
41+
42+
void loop(){
43+
// read the state of the pushbutton value:
44+
buttonState = digitalRead(buttonPin);
45+
46+
// check if the pushbutton is pressed.
47+
// if it is, the buttonState is HIGH:
48+
if (buttonState == HIGH) {
49+
// turn LED on:
50+
digitalWrite(ledPin, HIGH);
51+
}
52+
else {
53+
// turn LED off:
54+
digitalWrite(ledPin, LOW);
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Debounce
3+
4+
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
5+
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
6+
a minimum delay between toggles to debounce the circuit (i.e. to ignore
7+
noise).
8+
9+
The circuit:
10+
* LED attached from pin 13 to ground
11+
* pushbutton attached from pin 2 to +5V
12+
* 10K resistor attached from pin 2 to ground
13+
14+
* Note: On most Arduino boards, there is already an LED on the board
15+
connected to pin 13, so you don't need any extra components for this example.
16+
17+
18+
created 21 November 2006
19+
by David A. Mellis
20+
modified 30 Aug 2011
21+
by Limor Fried
22+
23+
This example code is in the public domain.
24+
25+
http://www.arduino.cc/en/Tutorial/Debounce
26+
*/
27+
28+
// constants won't change. They're used here to
29+
// set pin numbers:
30+
const int buttonPin = 2; // the number of the pushbutton pin
31+
const int ledPin = 13; // the number of the LED pin
32+
33+
// Variables will change:
34+
int ledState = HIGH; // the current state of the output pin
35+
int buttonState; // the current reading from the input pin
36+
int lastButtonState = LOW; // the previous reading from the input pin
37+
38+
// the following variables are long's because the time, measured in miliseconds,
39+
// will quickly become a bigger number than can be stored in an int.
40+
long lastDebounceTime = 0; // the last time the output pin was toggled
41+
long debounceDelay = 50; // the debounce time; increase if the output flickers
42+
43+
void setup() {
44+
pinMode(buttonPin, INPUT);
45+
pinMode(ledPin, OUTPUT);
46+
}
47+
48+
void loop() {
49+
// read the state of the switch into a local variable:
50+
int reading = digitalRead(buttonPin);
51+
52+
// check to see if you just pressed the button
53+
// (i.e. the input went from LOW to HIGH), and you've waited
54+
// long enough since the last press to ignore any noise:
55+
56+
// If the switch changed, due to noise or pressing:
57+
if (reading != lastButtonState) {
58+
// reset the debouncing timer
59+
lastDebounceTime = millis();
60+
}
61+
62+
if ((millis() - lastDebounceTime) > debounceDelay) {
63+
// whatever the reading is at, it's been there for longer
64+
// than the debounce delay, so take it as the actual current state:
65+
buttonState = reading;
66+
}
67+
68+
// set the LED using the state of the button:
69+
digitalWrite(ledPin, buttonState);
70+
71+
// save the reading. Next time through the loop,
72+
// it'll be the lastButtonState:
73+
lastButtonState = reading;
74+
}
75+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Input Pullup Serial
3+
4+
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
5+
digital input on pin 2 and prints the results to the serial monitor.
6+
7+
The circuit:
8+
* Momentary switch attached from pin 2 to ground
9+
* Built-in LED on pin 13
10+
11+
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
12+
20K-ohm resistor is pulled to 5V. This configuration causes the input to
13+
read HIGH when the switch is open, and LOW when it is closed.
14+
15+
created 14 March 2012
16+
by Scott Fitzgerald
17+
18+
http://www.arduino.cc/en/Tutorial/InputPullupSerial
19+
20+
This example code is in the public domain
21+
22+
*/
23+
24+
void setup(){
25+
//start serial connection
26+
Serial.begin(9600);
27+
//configure pin2 as an input and enable the internal pull-up resistor
28+
pinMode(2, INPUT_PULLUP);
29+
pinMode(13, OUTPUT);
30+
31+
}
32+
33+
void loop(){
34+
//read the pushbutton value into a variable
35+
int sensorVal = digitalRead(2);
36+
//print out the value of the pushbutton
37+
Serial.println(sensorVal);
38+
39+
// Keep in mind the pullup means the pushbutton's
40+
// logic is inverted. It goes HIGH when it's open,
41+
// and LOW when it's pressed. Turn on pin 13 when the
42+
// button's pressed, and off when it's not:
43+
if (sensorVal == HIGH) {
44+
digitalWrite(13, LOW);
45+
}
46+
else {
47+
digitalWrite(13, HIGH);
48+
}
49+
}
50+
51+
52+

0 commit comments

Comments
 (0)