mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Merge branch 'master' of github.com:arduino/Arduino into LUFA_bootloader
This commit is contained in:
commit
a0f1f1a930
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
Input Pullup Serial
|
||||||
|
|
||||||
|
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
|
||||||
|
digital input on pin 2 and prints the results to the serial monitor.
|
||||||
|
|
||||||
|
The circuit:
|
||||||
|
* Momentary switch attached from pin 2 to ground
|
||||||
|
* Built-in LED on pin 13
|
||||||
|
|
||||||
|
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
|
||||||
|
20K-ohm resistor is pulled to 5V. This configuration causes the input to
|
||||||
|
read HIGH when the switch is open, and LOW when it is closed.
|
||||||
|
|
||||||
|
created 14 March 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://www.arduino.cc/en/Tutorial/InputPullupSerial
|
||||||
|
|
||||||
|
This example code is in the public domain
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
//start serial connection
|
||||||
|
Serial.begin(9600);
|
||||||
|
//configure pin2 as an input and enable the internal pull-up resistor
|
||||||
|
pinMode(2, INPUT_PULLUP);
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
//read the pushbutton value into a variable
|
||||||
|
int sensorVal = digitalRead(2);
|
||||||
|
//print out the value of the pushbutton
|
||||||
|
Serial.println(sensorVal);
|
||||||
|
|
||||||
|
// Keep in mind the pullup means the pushbutton's
|
||||||
|
// logic is inverted. It goes HIGH when it's open,
|
||||||
|
// and LOW when it's pressed. Turn on pin 13 when the
|
||||||
|
// button's pressed, and off when it's not:
|
||||||
|
if (sensorVal == HIGH) {
|
||||||
|
digitalWrite(13, LOW);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
digitalWrite(13, HIGH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,7 +66,7 @@
|
|||||||
void pulse(int pin, int times);
|
void pulse(int pin, int times);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(19200);
|
||||||
pinMode(LED_PMODE, OUTPUT);
|
pinMode(LED_PMODE, OUTPUT);
|
||||||
pulse(LED_PMODE, 2);
|
pulse(LED_PMODE, 2);
|
||||||
pinMode(LED_ERR, OUTPUT);
|
pinMode(LED_ERR, OUTPUT);
|
||||||
@ -109,7 +109,7 @@ void heartbeat() {
|
|||||||
if (hbval < 32) hbdelta = -hbdelta;
|
if (hbval < 32) hbdelta = -hbdelta;
|
||||||
hbval += hbdelta;
|
hbval += hbdelta;
|
||||||
analogWrite(LED_HB, hbval);
|
analogWrite(LED_HB, hbval);
|
||||||
delay(40);
|
delay(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,4 +23,4 @@ parallel.force=true
|
|||||||
arduinoisp.name=Arduino as ISP
|
arduinoisp.name=Arduino as ISP
|
||||||
arduinoisp.communication=serial
|
arduinoisp.communication=serial
|
||||||
arduinoisp.protocol=stk500v1
|
arduinoisp.protocol=stk500v1
|
||||||
arduinoisp.speed=9600
|
arduinoisp.speed=19200
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||||
|
|
||||||
created 15 March 2010
|
created 15 March 2010
|
||||||
updated 27 Feb 2012
|
updated 16 Mar 2012
|
||||||
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
||||||
|
|
||||||
http://arduino.cc/en/Tutorial/PachubeClient
|
http://arduino.cc/en/Tutorial/PachubeClient
|
||||||
@ -27,8 +27,6 @@ http://arduino.cc/en/Tutorial/PachubeClient
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
|
#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
|
||||||
#define FEEDID 00000 // replace your feed ID
|
#define FEEDID 00000 // replace your feed ID
|
||||||
#define USERAGENT "My Project" // user agent is the project name
|
#define USERAGENT "My Project" // user agent is the project name
|
||||||
@ -45,9 +43,14 @@ IPAddress ip(10,0,1,20);
|
|||||||
// initialize the library instance:
|
// initialize the library instance:
|
||||||
EthernetClient client;
|
EthernetClient client;
|
||||||
|
|
||||||
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
// if you don't want to use DNS (and reduce your sketch size)
|
||||||
|
// use the numeric IP instead of the name for the server:
|
||||||
|
IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
|
||||||
|
//char server[] = "api.pachube.com"; // name address for pachube API
|
||||||
|
|
||||||
|
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||||
const int postingInterval = 10000; //delay between updates to Pachube.com
|
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// start serial port:
|
// start serial port:
|
||||||
@ -93,13 +96,13 @@ void loop() {
|
|||||||
// this method makes a HTTP connection to the server:
|
// this method makes a HTTP connection to the server:
|
||||||
void sendData(int thisData) {
|
void sendData(int thisData) {
|
||||||
// if there's a successful connection:
|
// if there's a successful connection:
|
||||||
if (client.connect("www.pachube.com", 80)) {
|
if (client.connect(server, 80)) {
|
||||||
Serial.println("connecting...");
|
Serial.println("connecting...");
|
||||||
// send the HTTP PUT request:
|
// send the HTTP PUT request:
|
||||||
client.print("PUT /v2/feeds/");
|
client.print("PUT /v2/feeds/");
|
||||||
client.print(FEEDID);
|
client.print(FEEDID);
|
||||||
client.println(".csv HTTP/1.1");
|
client.println(".csv HTTP/1.1");
|
||||||
client.print("Host: api.pachube.com\n");
|
client.println("Host: api.pachube.com");
|
||||||
client.print("X-PachubeApiKey: ");
|
client.print("X-PachubeApiKey: ");
|
||||||
client.println(APIKEY);
|
client.println(APIKEY);
|
||||||
client.print("User-Agent: ");
|
client.print("User-Agent: ");
|
||||||
@ -112,15 +115,14 @@ void sendData(int thisData) {
|
|||||||
client.println(thisLength);
|
client.println(thisLength);
|
||||||
|
|
||||||
// last pieces of the HTTP PUT request:
|
// last pieces of the HTTP PUT request:
|
||||||
client.print("Content-Type: text/csv\n");
|
client.println("Content-Type: text/csv");
|
||||||
client.println("Connection: close\n");
|
client.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
|
||||||
// here's the actual content of the PUT request:
|
// here's the actual content of the PUT request:
|
||||||
client.print("sensor1,");
|
client.print("sensor1,");
|
||||||
client.println(thisData);
|
client.println(thisData);
|
||||||
|
|
||||||
// note the time that the connection was made:
|
|
||||||
lastConnectionTime = millis();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// if you couldn't make a connection:
|
// if you couldn't make a connection:
|
||||||
@ -128,8 +130,9 @@ void sendData(int thisData) {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("disconnecting.");
|
Serial.println("disconnecting.");
|
||||||
client.stop();
|
client.stop();
|
||||||
lastConnected = client.connected();
|
|
||||||
}
|
}
|
||||||
|
// note the time that the connection was made or attempted:
|
||||||
|
lastConnectionTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
* Ethernet shield attached to pins 10, 11, 12, 13
|
* Ethernet shield attached to pins 10, 11, 12, 13
|
||||||
|
|
||||||
created 15 March 2010
|
created 15 March 2010
|
||||||
updated 27 Feb 2012
|
updated 16 Mar 2012
|
||||||
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
by Tom Igoe with input from Usman Haque and Joe Saavedra
|
||||||
|
|
||||||
http://arduino.cc/en/Tutorial/PachubeClientString
|
http://arduino.cc/en/Tutorial/PachubeClientString
|
||||||
@ -40,14 +40,19 @@
|
|||||||
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||||
// fill in an available IP address on your network here,
|
// fill in an available IP address on your network here,
|
||||||
// for manual configuration:
|
// for manual configuration:
|
||||||
IPAddress ip(10,0,0,20);
|
IPAddress ip(10,0,1,20);
|
||||||
|
|
||||||
// initialize the library instance:
|
// initialize the library instance:
|
||||||
EthernetClient client;
|
EthernetClient client;
|
||||||
|
|
||||||
|
// if you don't want to use DNS (and reduce your sketch size)
|
||||||
|
// use the numeric IP instead of the name for the server:
|
||||||
|
//IPAddress server(216,52,233,122); // numeric IP for api.pachube.com
|
||||||
|
char server[] = "api.pachube.com"; // name address for pachube API
|
||||||
|
|
||||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||||
const unsigned long postingInterval = 10000; //delay between updates to Pachube.com
|
const unsigned long postingInterval = 10*1000; //delay between updates to Pachube.com
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// start serial port:
|
// start serial port:
|
||||||
@ -105,29 +110,27 @@ void loop() {
|
|||||||
// this method makes a HTTP connection to the server:
|
// this method makes a HTTP connection to the server:
|
||||||
void sendData(String thisData) {
|
void sendData(String thisData) {
|
||||||
// if there's a successful connection:
|
// if there's a successful connection:
|
||||||
if (client.connect("api.pachube.com", 80)) {
|
if (client.connect(server, 80)) {
|
||||||
Serial.println("connecting...");
|
Serial.println("connecting...");
|
||||||
// send the HTTP PUT request:
|
// send the HTTP PUT request:
|
||||||
client.print("PUT /v2/feeds/");
|
client.print("PUT /v2/feeds/");
|
||||||
client.print(FEEDID);
|
client.print(FEEDID);
|
||||||
client.println(".csv HTTP/1.1");
|
client.println(".csv HTTP/1.1");
|
||||||
client.print("Host: api.pachube.com\n");
|
client.println("Host: api.pachube.com");
|
||||||
client.print("X-PachubeApiKey: ");
|
client.print("X-PachubeApiKey: ");
|
||||||
client.println(APIKEY);
|
client.println(APIKEY);
|
||||||
client.print("User-Agent: ");
|
client.print("User-Agent: ");
|
||||||
client.println(USERAGENT);
|
client.println(USERAGENT);
|
||||||
client.print("Content-Length: ");
|
client.print("Content-Length: ");
|
||||||
client.println(thisData.length(), DEC);
|
client.println(thisData.length());
|
||||||
|
|
||||||
// last pieces of the HTTP PUT request:
|
// last pieces of the HTTP PUT request:
|
||||||
client.print("Content-Type: text/csv\n");
|
client.println("Content-Type: text/csv");
|
||||||
client.println("Connection: close\n");
|
client.println("Connection: close");
|
||||||
|
client.println();
|
||||||
|
|
||||||
// here's the actual content of the PUT request:
|
// here's the actual content of the PUT request:
|
||||||
client.println(thisData);
|
client.println(thisData);
|
||||||
|
|
||||||
// note the time that the connection was made:
|
|
||||||
lastConnectionTime = millis();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// if you couldn't make a connection:
|
// if you couldn't make a connection:
|
||||||
@ -135,8 +138,8 @@ void sendData(String thisData) {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("disconnecting.");
|
Serial.println("disconnecting.");
|
||||||
client.stop();
|
client.stop();
|
||||||
lastConnected = client.connected();
|
|
||||||
}
|
}
|
||||||
|
// note the time that the connection was made or attempted:
|
||||||
|
lastConnectionTime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
created 18 Dec 2009
|
created 18 Dec 2009
|
||||||
by David A. Mellis
|
by David A. Mellis
|
||||||
modified 4 Sep 2010
|
modified 20 Mar 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@ -20,7 +20,8 @@
|
|||||||
|
|
||||||
// Enter a MAC address and IP address for your controller below.
|
// Enter a MAC address and IP address for your controller below.
|
||||||
// The IP address will be dependent on your local network:
|
// The IP address will be dependent on your local network:
|
||||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
byte mac[] = {
|
||||||
|
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||||
IPAddress ip(192,168,1, 177);
|
IPAddress ip(192,168,1, 177);
|
||||||
|
|
||||||
// Initialize the Ethernet server library
|
// Initialize the Ethernet server library
|
||||||
@ -28,23 +29,27 @@ IPAddress ip(192,168,1, 177);
|
|||||||
// (port 80 is default for HTTP):
|
// (port 80 is default for HTTP):
|
||||||
EthernetServer server(80);
|
EthernetServer server(80);
|
||||||
|
|
||||||
void setup()
|
void setup() {
|
||||||
{
|
Serial.begin(9600);
|
||||||
// start the Ethernet connection and the server:
|
// start the Ethernet connection and the server:
|
||||||
Ethernet.begin(mac, ip);
|
Ethernet.begin(mac, ip);
|
||||||
server.begin();
|
server.begin();
|
||||||
|
Serial.print("server is at ");
|
||||||
|
Serial.println(Ethernet.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
void loop() {
|
||||||
// listen for incoming clients
|
// listen for incoming clients
|
||||||
EthernetClient client = server.available();
|
EthernetClient client = server.available();
|
||||||
if (client) {
|
if (client) {
|
||||||
|
Serial.println("new client");
|
||||||
// an http request ends with a blank line
|
// an http request ends with a blank line
|
||||||
boolean currentLineIsBlank = true;
|
boolean currentLineIsBlank = true;
|
||||||
while (client.connected()) {
|
while (client.connected()) {
|
||||||
if (client.available()) {
|
if (client.available()) {
|
||||||
char c = client.read();
|
char c = client.read();
|
||||||
|
Serial.write(c);
|
||||||
// if you've gotten to the end of the line (received a newline
|
// if you've gotten to the end of the line (received a newline
|
||||||
// character) and the line is blank, the http request has ended,
|
// character) and the line is blank, the http request has ended,
|
||||||
// so you can send a reply
|
// so you can send a reply
|
||||||
@ -52,16 +57,22 @@ void loop()
|
|||||||
// send a standard http response header
|
// send a standard http response header
|
||||||
client.println("HTTP/1.1 200 OK");
|
client.println("HTTP/1.1 200 OK");
|
||||||
client.println("Content-Type: text/html");
|
client.println("Content-Type: text/html");
|
||||||
|
client.println("Connnection: close");
|
||||||
client.println();
|
client.println();
|
||||||
|
client.println("<!DOCTYPE HTML>");
|
||||||
|
client.println("<html>");
|
||||||
|
// add a meta refresh tag, so the browser pulls again every 5 seconds:
|
||||||
|
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
|
||||||
// output the value of each analog input pin
|
// output the value of each analog input pin
|
||||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
||||||
|
int sensorReading = analogRead(analogChannel);
|
||||||
client.print("analog input ");
|
client.print("analog input ");
|
||||||
client.print(analogChannel);
|
client.print(analogChannel);
|
||||||
client.print(" is ");
|
client.print(" is ");
|
||||||
client.print(analogRead(analogChannel));
|
client.print(sensorReading);
|
||||||
client.println("<br />");
|
client.println("<br />");
|
||||||
}
|
}
|
||||||
|
client.println("</html>");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
@ -78,5 +89,7 @@ void loop()
|
|||||||
delay(1);
|
delay(1);
|
||||||
// close the connection:
|
// close the connection:
|
||||||
client.stop();
|
client.stop();
|
||||||
|
Serial.println("client disonnected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,23 @@
|
|||||||
|
/*
|
||||||
|
Software serial multple serial test
|
||||||
|
|
||||||
|
Receives from the hardware serial, sends to software serial.
|
||||||
|
Receives from software serial, sends to hardware serial.
|
||||||
|
|
||||||
|
The circuit:
|
||||||
|
* RX is digital pin 2 (connect to TX of other device)
|
||||||
|
* TX is digital pin 3 (connect to RX of other device)
|
||||||
|
|
||||||
|
created back in the mists of time
|
||||||
|
by Tom Igoe
|
||||||
|
based on Mikal Hart's example
|
||||||
|
|
||||||
|
This example code is in the public domain.
|
||||||
|
|
||||||
|
*/
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
|
||||||
SoftwareSerial mySerial(2, 3);
|
SoftwareSerial mySerial(2, 3); // RX, TX
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user