1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Merge branch 'new-extension' of github.com:arduino/Arduino into diskloader_reboot

Conflicts:
	hardware/arduino/variants/mega/pins_arduino.h
	libraries/Ethernet/examples/PachubeClient/PachubeClient.ino
	libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
This commit is contained in:
Zach Eveland
2011-10-27 11:41:02 -04:00
14 changed files with 212 additions and 226 deletions

View File

@ -131,7 +131,8 @@ public class AvrdudeUploader extends Uploader {
Map<String, String> boardPreferences = Base.getBoardPreferences(); Map<String, String> boardPreferences = Base.getBoardPreferences();
List fuses = new ArrayList(); List fuses = new ArrayList();
fuses.add("-e"); // erase the chip fuses.add("-e"); // erase the chip
fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m"); if (boardPreferences.get("bootloader.unlock_bits") != null)
fuses.add("-Ulock:w:" + boardPreferences.get("bootloader.unlock_bits") + ":m");
if (boardPreferences.get("bootloader.extended_fuses") != null) if (boardPreferences.get("bootloader.extended_fuses") != null)
fuses.add("-Uefuse:w:" + boardPreferences.get("bootloader.extended_fuses") + ":m"); fuses.add("-Uefuse:w:" + boardPreferences.get("bootloader.extended_fuses") + ":m");
fuses.add("-Uhfuse:w:" + boardPreferences.get("bootloader.high_fuses") + ":m"); fuses.add("-Uhfuse:w:" + boardPreferences.get("bootloader.high_fuses") + ":m");
@ -145,26 +146,32 @@ public class AvrdudeUploader extends Uploader {
} catch (InterruptedException e) {} } catch (InterruptedException e) {}
Target t; Target t;
List bootloader = new ArrayList();
String bootloaderPath = boardPreferences.get("bootloader.path"); String bootloaderPath = boardPreferences.get("bootloader.path");
if (bootloaderPath.indexOf(':') == -1) { if (bootloaderPath != null) {
t = Base.getTarget(); // the current target (associated with the board) if (bootloaderPath.indexOf(':') == -1) {
} else { t = Base.getTarget(); // the current target (associated with the board)
String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':')); } else {
t = Base.targetsTable.get(targetName); String targetName = bootloaderPath.substring(0, bootloaderPath.indexOf(':'));
bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1); t = Base.targetsTable.get(targetName);
bootloaderPath = bootloaderPath.substring(bootloaderPath.indexOf(':') + 1);
}
File bootloadersFile = new File(t.getFolder(), "bootloaders");
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
bootloaderPath = bootloaderFile.getAbsolutePath();
bootloader.add("-Uflash:w:" + bootloaderPath + File.separator +
boardPreferences.get("bootloader.file") + ":i");
} }
if (boardPreferences.get("bootloader.lock_bits") != null)
File bootloadersFile = new File(t.getFolder(), "bootloaders"); bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m");
File bootloaderFile = new File(bootloadersFile, bootloaderPath);
bootloaderPath = bootloaderFile.getAbsolutePath();
List bootloader = new ArrayList();
bootloader.add("-Uflash:w:" + bootloaderPath + File.separator +
boardPreferences.get("bootloader.file") + ":i");
bootloader.add("-Ulock:w:" + boardPreferences.get("bootloader.lock_bits") + ":m");
return avrdude(params, bootloader); if (bootloader.size() > 0)
return avrdude(params, bootloader);
return true;
} }
public boolean avrdude(Collection p1, Collection p2) throws RunnerException { public boolean avrdude(Collection p1, Collection p2) throws RunnerException {

View File

@ -7,11 +7,11 @@
<!-- all these need to change for new releases --> <!-- all these need to change for new releases -->
<key>CFBundleGetInfoString</key> <key>CFBundleGetInfoString</key>
<string>1.0-rc1</string> <string>1.0-rc2</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>0100</string> <string>0100</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0-rc1</string> <string>1.0-rc2</string>
<!-- now stop changing things and get outta here --> <!-- now stop changing things and get outta here -->
<key>CFBundleAllowMixedLocalizations</key> <key>CFBundleAllowMixedLocalizations</key>

View File

@ -19,7 +19,7 @@
Created 26 Sept. 2005 Created 26 Sept. 2005
by Tom Igoe by Tom Igoe
modified 30 Aug 2011 modified 26 Oct 2011
by Tom Igoe and Scott Fitzgerald by Tom Igoe and Scott Fitzgerald
This example code is in the public domain. This example code is in the public domain.
@ -47,12 +47,10 @@ void loop()
if (Serial.available() > 0) { if (Serial.available() > 0) {
// get incoming byte: // get incoming byte:
inByte = Serial.read(); inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255: // read first analog input:
firstSensor = analogRead(A0)/4; firstSensor = analogRead(A0);
// delay 10ms to let the ADC recover: // read second analog input:
delay(10); secondSensor = analogRead(A1);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(A1)/4;
// read switch, map it to 0 or 255L // read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255); thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values: // send sensor values:

View File

@ -40,6 +40,11 @@ extern "C"{
#define FALLING 2 #define FALLING 2
#define RISING 3 #define RISING 3
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
#define DEFAULT 0
#define EXTERNAL 1
#define INTERNAL 2
#else
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define INTERNAL1V1 2 #define INTERNAL1V1 2
#define INTERNAL2V56 3 #define INTERNAL2V56 3
@ -48,6 +53,7 @@ extern "C"{
#endif #endif
#define DEFAULT 1 #define DEFAULT 1
#define EXTERNAL 0 #define EXTERNAL 0
#endif
// undefine stdlib's abs if encountered // undefine stdlib's abs if encountered
#ifdef abs #ifdef abs
@ -142,6 +148,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
#define NOT_A_PIN 0 #define NOT_A_PIN 0
#define NOT_A_PORT 0 #define NOT_A_PORT 0
#ifdef ARDUINO_MAIN
#define PA 1 #define PA 1
#define PB 2 #define PB 2
#define PC 3 #define PC 3
@ -153,6 +160,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
#define PJ 10 #define PJ 10
#define PK 11 #define PK 11
#define PL 12 #define PL 12
#endif
#define NOT_ON_TIMER 0 #define NOT_ON_TIMER 0
#define TIMER0A 1 #define TIMER0A 1

View File

@ -593,7 +593,7 @@ void String::replace(const String& find, const String& replace)
if (size == len) return; if (size == len) return;
if (size > capacity && !changeBuffer(size)) return; // XXX: tell user! if (size > capacity && !changeBuffer(size)) return; // XXX: tell user!
int index = len - 1; int index = len - 1;
while ((index = lastIndexOf(find, index)) >= 0) { while (index >= 0 && (index = lastIndexOf(find, index)) >= 0) {
readFrom = buffer + index + find.len; readFrom = buffer + index + find.len;
memmove(readFrom + diff, readFrom, len - (readFrom - buffer)); memmove(readFrom + diff, readFrom, len - (readFrom - buffer));
len += diff; len += diff;

View File

@ -1,4 +1,3 @@
#define ARDUINO_MAIN
#include <Arduino.h> #include <Arduino.h>
int main(void) int main(void)

View File

@ -221,10 +221,14 @@ void init()
// set timer 1 prescale factor to 64 // set timer 1 prescale factor to 64
sbi(TCCR1B, CS11); sbi(TCCR1B, CS11);
#if F_CPU >= 8000000L
sbi(TCCR1B, CS10); sbi(TCCR1B, CS10);
#endif
#elif defined(TCCR1) && defined(CS11) && defined(CS10) #elif defined(TCCR1) && defined(CS11) && defined(CS10)
sbi(TCCR1, CS11); sbi(TCCR1, CS11);
#if F_CPU >= 8000000L
sbi(TCCR1, CS10); sbi(TCCR1, CS10);
#endif
#endif #endif
// put timer 1 in 8-bit phase correct pwm mode // put timer 1 in 8-bit phase correct pwm mode
#if defined(TCCR1A) && defined(WGM10) #if defined(TCCR1A) && defined(WGM10)

View File

@ -24,6 +24,7 @@
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/ */
#define ARDUINO_MAIN
#include "wiring_private.h" #include "wiring_private.h"
#include "pins_arduino.h" #include "pins_arduino.h"

228
hardware/arduino/variants/mega/pins_arduino.h Executable file → Normal file
View File

@ -1,8 +1,8 @@
/* /*
pins_arduino.c - pin definitions for the Arduino board pins_arduino.h - Pin definition functions for Arduino
Part of Arduino / Wiring Lite Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005 David A. Mellis Copyright (c) 2007 David A. Mellis
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -19,66 +19,72 @@
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA Boston, MA 02111-1307 USA
$Id$ $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/ */
#include <avr/io.h> #ifndef Pins_Arduino_h
#include "wiring_private.h" #define Pins_Arduino_h
#include "pins_arduino.h"
// On the Arduino board, digital pins are also used #include <avr/pgmspace.h>
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA8 & 168 / ARDUINO #define NUM_DIGITAL_PINS 70
// #define NUM_ANALOG_INPUTS 16
// +-\/-+ #define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1)
// PC6 1| |28 PC5 (AI 5) #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))
// (D 0) PD0 2| |27 PC4 (AI 4)
// (D 1) PD1 3| |26 PC3 (AI 3)
// (D 2) PD2 4| |25 PC2 (AI 2)
// PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
// (D 4) PD4 6| |23 PC0 (AI 0)
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5 (D 13)
// PWM+ (D 5) PD5 11| |18 PB4 (D 12)
// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
// (D 7) PD7 13| |16 PB2 (D 10) PWM
// (D 8) PB0 14| |15 PB1 (D 9) PWM
// +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)
// ATMEL ATMEGA1280 / ARDUINO const static uint8_t SS = 53;
// const static uint8_t MOSI = 51;
// 0-7 PE0-PE7 works const static uint8_t MISO = 50;
// 8-13 PB0-PB5 works const static uint8_t SCK = 52;
// 14-21 PA0-PA7 works
// 22-29 PH0-PH7 works
// 30-35 PG5-PG0 works
// 36-43 PC7-PC0 works
// 44-51 PJ7-PJ0 works
// 52-59 PL7-PL0 works
// 60-67 PD7-PD0 works
// A0-A7 PF0-PF7
// A8-A15 PK0-PK7
#define PA 1 const static uint8_t SDA = 20;
#define PB 2 const static uint8_t SCL = 21;
#define PC 3 const static uint8_t LED_BUILTIN = 13;
#define PD 4
#define PE 5
#define PF 6
#define PG 7
#define PH 8
#define PJ 10
#define PK 11
#define PL 12
const static uint8_t A0 = 54;
const static uint8_t A1 = 55;
const static uint8_t A2 = 56;
const static uint8_t A3 = 57;
const static uint8_t A4 = 58;
const static uint8_t A5 = 59;
const static uint8_t A6 = 60;
const static uint8_t A7 = 61;
const static uint8_t A8 = 62;
const static uint8_t A9 = 63;
const static uint8_t A10 = 64;
const static uint8_t A11 = 65;
const static uint8_t A12 = 66;
const static uint8_t A13 = 67;
const static uint8_t A14 = 68;
const static uint8_t A15 = 69;
// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):
// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
// Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \
(((p) >= 50) && ((p) <= 53)) || \
(((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
( (((p) >= 62) && ((p) <= 69)) ? 2 : \
0 ) )
#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
((uint8_t *)0) ) )
#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
( ((p) == 50) ? 3 : \
( ((p) == 51) ? 2 : \
( ((p) == 52) ? 1 : \
( ((p) == 53) ? 0 : \
( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
0 ) ) ) ) ) )
#ifdef ARDUINO_MAIN
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const uint16_t PROGMEM port_to_mode_PGM[] = { const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT, NOT_A_PORT,
(uint16_t) &DDRA, (uint16_t) &DDRA,
@ -351,115 +357,7 @@ const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER , // PK 6 ** 68 ** A14 NOT_ON_TIMER , // PK 6 ** 68 ** A14
NOT_ON_TIMER , // PK 7 ** 69 ** A15 NOT_ON_TIMER , // PK 7 ** 69 ** A15
}; };
#else
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PC, /* 14 */
PC,
PC,
PC,
PC,
PC,
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /* 14, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
// on the ATmega168, digital pin 3 has hardware pwm
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
#else
TIMER2B,
#endif
NOT_ON_TIMER,
// on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
NOT_ON_TIMER,
#else
TIMER0B,
TIMER0A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER, /* 8 - port B */
TIMER1A,
TIMER1B,
#if defined(__AVR_ATmega8__)
TIMER2,
#else
TIMER2A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 14 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
#endif #endif
#endif

View File

@ -44,7 +44,7 @@ const static uint8_t SCK = 13;
const static uint8_t SDA = 18; const static uint8_t SDA = 18;
const static uint8_t SCL = 19; const static uint8_t SCL = 19;
const static uint8_t LED = 13; const static uint8_t LED_BUILTIN = 13;
const static uint8_t A0 = 14; const static uint8_t A0 = 14;
const static uint8_t A1 = 15; const static uint8_t A1 = 15;

View File

@ -11,7 +11,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 4 Sep 2010 updated 26 Oct 2011
by Tom Igoe by Tom Igoe
http://www.tigoe.net/pcomp/code/category/arduinowiring/873 http://www.tigoe.net/pcomp/code/category/arduinowiring/873
@ -23,34 +23,32 @@
#include <Ethernet.h> #include <Ethernet.h>
// assign a MAC address for the ethernet controller. // assign a MAC address for the ethernet controller.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
byte ip[] = {
192,168,1,20 };
byte gateway[] = {
192,168,1,1};
byte subnet[] = {
255, 255, 255, 0 };
// The address of the server you want to connect to (pachube.com):
byte server[] = {
173,203,98,29 };
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(10,0,1,20);
// initialize the library instance: // initialize the library instance:
Client client(server, 80); EthernetClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 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 int postingInterval = 10000; //delay between updates to Pachube.com
void setup() { void setup() {
// start the ethernet connection and serial port: // start serial port:
Ethernet.begin(mac, ip);
Serial.begin(9600); Serial.begin(9600);
// give the ethernet module time to boot up: // give the ethernet module time to boot up:
delay(1000); delay(1000);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Configure manually:
Ethernet.begin(mac, ip);
}
} }
void loop() { void loop() {
@ -86,7 +84,7 @@ 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()) { if (client.connect("www.pachube.com", 80)) {
Serial.println("connecting..."); Serial.println("connecting...");
// send the HTTP PUT request. // send the HTTP PUT request.
// fill in your feed address here: // fill in your feed address here:

View File

@ -14,7 +14,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 4 Sep 2010 updated 26 Oct 2011
by Tom Igoe by Tom Igoe
This code is in the public domain. This code is in the public domain.
@ -28,31 +28,28 @@
// fill in your address here: // fill in your address here:
byte mac[] = { byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller: // fill in an available IP address on your network here,
byte ip[] = { // for manual configuration:
192,168,1,20 }; IPAddress ip(10,0,1,20);
byte gateway[] = {
192,168,1,1};
byte subnet[] = {
255, 255, 255, 0 };
// The address of the server you want to connect to (pachube.com):
byte server[] = {
173,203,98,29 };
// initialize the library instance: // initialize the library instance:
Client client(server, 80); EthernetClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds 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 int postingInterval = 10000; //delay between updates to Pachube.com
void setup() { void setup() {
// start the ethernet connection and serial port: // start serial port:
Ethernet.begin(mac, ip);
Serial.begin(9600); Serial.begin(9600);
// give the ethernet module time to boot up: // give the ethernet module time to boot up:
delay(1000); delay(1000);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// Configure manually:
Ethernet.begin(mac, ip);
}
} }
void loop() { void loop() {
@ -96,7 +93,7 @@ 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()) { if (client.connect("www.pachube.com", 80)) {
Serial.println("connecting..."); Serial.println("connecting...");
// send the HTTP PUT request. // send the HTTP PUT request.
// fill in your feed address here: // fill in your feed address here:

View File

@ -0,0 +1,43 @@
/*
Keyboard Button test
Sends a text string when a button is pressed.
The circuit:
* pushbutton attached from pin 4 to +5V
* 10-kilohm resistor attached from pin 4 to ground
created 24 Oct 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardButton
*/
const int buttonPin = 4; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
int counter = 0; // button push counter
void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
// if the button state has changed,
if ((buttonState != previousButtonState)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;
// type out a message
Keyboard.print("You pressed the button: ");
Keyboard.print(counter);
Keyboard.println(" times.");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}

View File

@ -0,0 +1,33 @@
/*
Keyboard test
Reads a byte from the serial port, sends a keystroke back.
The sent keystroke is one higher than what's received, e.g.
if you send a, you get b, send A you get B, and so forth.
The circuit:
* none
created 21 Oct 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardSerial
*/
void setup() {
// open the serial port:
Serial.begin(9600);
}
void loop() {
// check for incoming serial data:
if (Serial.available() > 0) {
// read incoming serial data:
char inChar = Serial.read();
// Type the next ASCII value from what you received:
Keyboard.write(inChar+1);
}
}