mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@ -1,30 +1,30 @@
|
||||
/*
|
||||
Keyboard logout
|
||||
|
||||
|
||||
This sketch demonstrates the Keyboard library.
|
||||
|
||||
When you connect pin 2 to ground, it performs a logout.
|
||||
|
||||
When you connect pin 2 to ground, it performs a logout.
|
||||
It uses keyboard combinations to do this, as follows:
|
||||
|
||||
|
||||
On Windows, CTRL-ALT-DEL followed by ALT-l
|
||||
On Ubuntu, CTRL-ALT-DEL, and ENTER
|
||||
On OSX, CMD-SHIFT-q
|
||||
|
||||
To wake: Spacebar.
|
||||
|
||||
|
||||
To wake: Spacebar.
|
||||
|
||||
Circuit:
|
||||
* Arduino Leonardo or Micro
|
||||
* wire to connect D2 to ground.
|
||||
|
||||
|
||||
created 6 Mar 2012
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardLogout
|
||||
*/
|
||||
|
||||
|
||||
#define OSX 0
|
||||
#define WINDOWS 1
|
||||
#define UBUNTU 2
|
||||
@ -33,13 +33,13 @@
|
||||
int platform = OSX;
|
||||
|
||||
void setup() {
|
||||
// make pin 2 an input and turn on the
|
||||
// make pin 2 an input and turn on the
|
||||
// pullup resistor so it goes high unless
|
||||
// connected to ground:
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
Keyboard.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
while (digitalRead(2) == HIGH) {
|
||||
// do nothing until pin 2 goes low
|
||||
@ -48,43 +48,43 @@ void loop() {
|
||||
delay(1000);
|
||||
|
||||
switch (platform) {
|
||||
case OSX:
|
||||
Keyboard.press(KEY_LEFT_GUI);
|
||||
// Shift-Q logs out:
|
||||
Keyboard.press(KEY_LEFT_SHIFT);
|
||||
Keyboard.press('Q');
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
// enter:
|
||||
Keyboard.write(KEY_RETURN);
|
||||
break;
|
||||
case WINDOWS:
|
||||
// CTRL-ALT-DEL:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
//ALT-s:
|
||||
delay(2000);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press('l');
|
||||
Keyboard.releaseAll();
|
||||
break;
|
||||
case UBUNTU:
|
||||
// CTRL-ALT-DEL:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(1000);
|
||||
Keyboard.releaseAll();
|
||||
// Enter to confirm logout:
|
||||
Keyboard.write(KEY_RETURN);
|
||||
break;
|
||||
case OSX:
|
||||
Keyboard.press(KEY_LEFT_GUI);
|
||||
// Shift-Q logs out:
|
||||
Keyboard.press(KEY_LEFT_SHIFT);
|
||||
Keyboard.press('Q');
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
// enter:
|
||||
Keyboard.write(KEY_RETURN);
|
||||
break;
|
||||
case WINDOWS:
|
||||
// CTRL-ALT-DEL:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(100);
|
||||
Keyboard.releaseAll();
|
||||
//ALT-s:
|
||||
delay(2000);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press('l');
|
||||
Keyboard.releaseAll();
|
||||
break;
|
||||
case UBUNTU:
|
||||
// CTRL-ALT-DEL:
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
delay(1000);
|
||||
Keyboard.releaseAll();
|
||||
// Enter to confirm logout:
|
||||
Keyboard.write(KEY_RETURN);
|
||||
break;
|
||||
}
|
||||
|
||||
// do nothing:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
/*
|
||||
Keyboard Button test
|
||||
|
||||
For the Arduino Leonardo, Micro and Due boards.
|
||||
|
||||
|
||||
Sends a text string when a button is pressed.
|
||||
|
||||
|
||||
The circuit:
|
||||
* pushbutton attached from pin 2 to +5V on AVR boards
|
||||
* pushbutton attached from pin 2 to +5V on AVR boards
|
||||
and to +3.3V to the Arduino Due
|
||||
* 10-kilohm resistor attached from pin 2 to ground
|
||||
|
||||
|
||||
created 24 Oct 2011
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardButton
|
||||
*/
|
||||
|
||||
@ -33,18 +33,18 @@ void setup() {
|
||||
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)) {
|
||||
// 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.print(counter);
|
||||
Keyboard.println(" times.");
|
||||
}
|
||||
// save the current button state for comparison next time:
|
||||
previousButtonState = buttonState;
|
||||
previousButtonState = buttonState;
|
||||
}
|
||||
|
||||
|
@ -1,40 +1,40 @@
|
||||
/*
|
||||
Arduino Programs Blink
|
||||
|
||||
|
||||
This sketch demonstrates the Keyboard library.
|
||||
|
||||
|
||||
For Leonardo and Due boards only.
|
||||
|
||||
|
||||
When you connect pin 2 to ground, it creates a new
|
||||
window with a key combination (CTRL-N),
|
||||
then types in the Blink sketch, then auto-formats the text
|
||||
using another key combination (CTRL-T), then
|
||||
uploads the sketch to the currently selected Arduino using
|
||||
using another key combination (CTRL-T), then
|
||||
uploads the sketch to the currently selected Arduino using
|
||||
a final key combination (CTRL-U).
|
||||
|
||||
|
||||
Circuit:
|
||||
* Arduino Leonardo, Micro or Due
|
||||
* wire to connect D2 to ground.
|
||||
|
||||
|
||||
created 5 Mar 2012
|
||||
modified 29 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example is in the public domain
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
|
||||
*/
|
||||
|
||||
// use this option for OSX.
|
||||
// use this option for OSX.
|
||||
// Comment it out if using Windows or Linux:
|
||||
char ctrlKey = KEY_LEFT_GUI;
|
||||
// use this option for Windows and Linux.
|
||||
// leave commented out if using OSX:
|
||||
// char ctrlKey = KEY_LEFT_CTRL;
|
||||
// char ctrlKey = KEY_LEFT_CTRL;
|
||||
|
||||
|
||||
void setup() {
|
||||
// make pin 2 an input and turn on the
|
||||
// make pin 2 an input and turn on the
|
||||
// pullup resistor so it goes high unless
|
||||
// connected to ground:
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
@ -65,9 +65,9 @@ void loop() {
|
||||
Keyboard.println("digitalWrite(13, HIGH);");
|
||||
Keyboard.print("delay(3000);");
|
||||
// 3000 ms is too long. Delete it:
|
||||
for (int keystrokes=0; keystrokes < 6; keystrokes++) {
|
||||
for (int keystrokes = 0; keystrokes < 6; keystrokes++) {
|
||||
delay(500);
|
||||
Keyboard.write(KEY_BACKSPACE);
|
||||
Keyboard.write(KEY_BACKSPACE);
|
||||
}
|
||||
// make it 1000 instead:
|
||||
Keyboard.println("1000);");
|
||||
@ -87,7 +87,7 @@ void loop() {
|
||||
Keyboard.releaseAll();
|
||||
|
||||
// wait for the sweet oblivion of reprogramming:
|
||||
while(true);
|
||||
while (true);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,21 +1,21 @@
|
||||
/*
|
||||
/*
|
||||
Keyboard test
|
||||
|
||||
|
||||
For the Arduino Leonardo, Micro or Due
|
||||
|
||||
|
||||
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
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
This example code is in the public domain.
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/KeyboardSerial
|
||||
*/
|
||||
|
||||
@ -32,7 +32,7 @@ void loop() {
|
||||
// read incoming serial data:
|
||||
char inChar = Serial.read();
|
||||
// Type the next ASCII value from what you received:
|
||||
Keyboard.write(inChar+1);
|
||||
}
|
||||
Keyboard.write(inChar + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,38 +3,38 @@
|
||||
KeyboardAndMouseControl
|
||||
|
||||
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
|
||||
|
||||
|
||||
Hardware:
|
||||
* 5 pushbuttons attached to D2, D3, D4, D5, D6
|
||||
|
||||
The mouse movement is always relative. This sketch reads
|
||||
|
||||
The mouse movement is always relative. This sketch reads
|
||||
four pushbuttons, and uses them to set the movement of the mouse.
|
||||
|
||||
|
||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||
over your mouse! Make sure you have control before you use the mouse commands.
|
||||
|
||||
|
||||
created 15 Mar 2012
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
this code is in the public domain
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// set pin numbers for the five buttons:
|
||||
const int upButton = 2;
|
||||
const int downButton = 3;
|
||||
const int upButton = 2;
|
||||
const int downButton = 3;
|
||||
const int leftButton = 4;
|
||||
const int rightButton = 5;
|
||||
const int mouseButton = 6;
|
||||
|
||||
void setup() { // initialize the buttons' inputs:
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
|
||||
|
||||
Serial.begin(9600);
|
||||
// initialize mouse control:
|
||||
Mouse.begin();
|
||||
@ -46,45 +46,45 @@ void loop() {
|
||||
if (Serial.available() > 0) {
|
||||
char inChar = Serial.read();
|
||||
|
||||
switch (inChar) {
|
||||
case 'u':
|
||||
// move mouse up
|
||||
Mouse.move(0, -40);
|
||||
break;
|
||||
case 'd':
|
||||
// move mouse down
|
||||
Mouse.move(0, 40);
|
||||
break;
|
||||
case 'l':
|
||||
// move mouse left
|
||||
Mouse.move(-40, 0);
|
||||
break;
|
||||
case 'r':
|
||||
// move mouse right
|
||||
Mouse.move(40, 0);
|
||||
break;
|
||||
case 'm':
|
||||
// perform mouse left click
|
||||
Mouse.click(MOUSE_LEFT);
|
||||
break;
|
||||
switch (inChar) {
|
||||
case 'u':
|
||||
// move mouse up
|
||||
Mouse.move(0, -40);
|
||||
break;
|
||||
case 'd':
|
||||
// move mouse down
|
||||
Mouse.move(0, 40);
|
||||
break;
|
||||
case 'l':
|
||||
// move mouse left
|
||||
Mouse.move(-40, 0);
|
||||
break;
|
||||
case 'r':
|
||||
// move mouse right
|
||||
Mouse.move(40, 0);
|
||||
break;
|
||||
case 'm':
|
||||
// perform mouse left click
|
||||
Mouse.click(MOUSE_LEFT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// use the pushbuttons to control the keyboard:
|
||||
if (digitalRead(upButton) == HIGH) {
|
||||
Keyboard.write('u');
|
||||
Keyboard.write('u');
|
||||
}
|
||||
if (digitalRead(downButton) == HIGH) {
|
||||
Keyboard.write('d');
|
||||
Keyboard.write('d');
|
||||
}
|
||||
if (digitalRead(leftButton) == HIGH) {
|
||||
Keyboard.write('l');
|
||||
Keyboard.write('l');
|
||||
}
|
||||
if (digitalRead(rightButton) == HIGH) {
|
||||
Keyboard.write('r');
|
||||
Keyboard.write('r');
|
||||
}
|
||||
if (digitalRead(mouseButton) == HIGH) {
|
||||
Keyboard.write('m');
|
||||
Keyboard.write('m');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,31 +2,31 @@
|
||||
/*
|
||||
ButtonMouseControl
|
||||
|
||||
For Leonardo and Due boards only.
|
||||
|
||||
For Leonardo and Due boards only.
|
||||
|
||||
Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due.
|
||||
|
||||
|
||||
Hardware:
|
||||
* 5 pushbuttons attached to D2, D3, D4, D5, D6
|
||||
|
||||
|
||||
The mouse movement is always relative. This sketch reads
|
||||
|
||||
|
||||
The mouse movement is always relative. This sketch reads
|
||||
four pushbuttons, and uses them to set the movement of the mouse.
|
||||
|
||||
|
||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||
over your mouse! Make sure you have control before you use the mouse commands.
|
||||
|
||||
|
||||
created 15 Mar 2012
|
||||
modified 27 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
this code is in the public domain
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// set pin numbers for the five buttons:
|
||||
const int upButton = 2;
|
||||
const int downButton = 3;
|
||||
const int upButton = 2;
|
||||
const int downButton = 3;
|
||||
const int leftButton = 4;
|
||||
const int rightButton = 5;
|
||||
const int mouseButton = 6;
|
||||
@ -37,10 +37,10 @@ int responseDelay = 10; // response delay of the mouse, in ms
|
||||
|
||||
void setup() {
|
||||
// initialize the buttons' inputs:
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
// initialize mouse control:
|
||||
Mouse.begin();
|
||||
@ -55,8 +55,8 @@ void loop() {
|
||||
int clickState = digitalRead(mouseButton);
|
||||
|
||||
// calculate the movement distance based on the button states:
|
||||
int xDistance = (leftState - rightState)*range;
|
||||
int yDistance = (upState - downState)*range;
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
// if X or Y is non-zero, move:
|
||||
if ((xDistance != 0) || (yDistance != 0)) {
|
||||
@ -67,14 +67,14 @@ void loop() {
|
||||
if (clickState == HIGH) {
|
||||
// if the mouse is not pressed, press it:
|
||||
if (!Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// else the mouse button is not pressed:
|
||||
else {
|
||||
// if the mouse is pressed, release it:
|
||||
if (Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,53 +1,53 @@
|
||||
/*
|
||||
JoystickMouseControl
|
||||
|
||||
|
||||
Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due.
|
||||
Uses a pushbutton to turn on and off mouse control, and
|
||||
a second pushbutton to click the left mouse button
|
||||
|
||||
|
||||
Hardware:
|
||||
* 2-axis joystick connected to pins A0 and A1
|
||||
* pushbuttons connected to pin D2 and D3
|
||||
|
||||
The mouse movement is always relative. This sketch reads
|
||||
|
||||
The mouse movement is always relative. This sketch reads
|
||||
two analog inputs that range from 0 to 1023 (or less on either end)
|
||||
and translates them into ranges of -6 to 6.
|
||||
The sketch assumes that the joystick resting values are around the
|
||||
and translates them into ranges of -6 to 6.
|
||||
The sketch assumes that the joystick resting values are around the
|
||||
middle of the range, but that they vary within a threshold.
|
||||
|
||||
|
||||
WARNING: When you use the Mouse.move() command, the Arduino takes
|
||||
over your mouse! Make sure you have control before you use the command.
|
||||
This sketch includes a pushbutton to toggle the mouse control state, so
|
||||
you can turn on and off mouse control.
|
||||
|
||||
|
||||
created 15 Sept 2011
|
||||
updated 28 Mar 2012
|
||||
by Tom Igoe
|
||||
|
||||
|
||||
this code is in the public domain
|
||||
|
||||
|
||||
*/
|
||||
|
||||
// set pin numbers for switch, joystick axes, and LED:
|
||||
const int switchPin = 2; // switch to turn on and off mouse control
|
||||
const int mouseButton = 3; // input pin for the mouse pushButton
|
||||
const int xAxis = A0; // joystick X axis
|
||||
const int xAxis = A0; // joystick X axis
|
||||
const int yAxis = A1; // joystick Y axis
|
||||
const int ledPin = 5; // Mouse control LED
|
||||
const int ledPin = 5; // Mouse control LED
|
||||
|
||||
// parameters for reading the joystick:
|
||||
int range = 12; // output range of X or Y movement
|
||||
int responseDelay = 5; // response delay of the mouse, in ms
|
||||
int threshold = range/4; // resting threshold
|
||||
int center = range/2; // resting position value
|
||||
int threshold = range / 4; // resting threshold
|
||||
int center = range / 2; // resting position value
|
||||
|
||||
boolean mouseIsActive = false; // whether or not to control the mouse
|
||||
int lastSwitchState = LOW; // previous switch state
|
||||
|
||||
void setup() {
|
||||
pinMode(switchPin, INPUT); // the switch pin
|
||||
pinMode(ledPin, OUTPUT); // the LED pin
|
||||
// take control of the mouse:
|
||||
pinMode(ledPin, OUTPUT); // the LED pin
|
||||
// take control of the mouse:
|
||||
Mouse.begin();
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ void loop() {
|
||||
mouseIsActive = !mouseIsActive;
|
||||
// turn on LED to indicate mouse state:
|
||||
digitalWrite(ledPin, mouseIsActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
// save switch state for next comparison:
|
||||
lastSwitchState = switchState;
|
||||
@ -72,21 +72,21 @@ void loop() {
|
||||
// if the mouse control state is active, move the mouse:
|
||||
if (mouseIsActive) {
|
||||
Mouse.move(xReading, yReading, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// read the mouse button and click or not click:
|
||||
// if the mouse button is pressed:
|
||||
if (digitalRead(mouseButton) == HIGH) {
|
||||
// if the mouse is not pressed, press it:
|
||||
if (!Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// else the mouse button is not pressed:
|
||||
else {
|
||||
// if the mouse is pressed, release it:
|
||||
if (Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,11 +94,11 @@ void loop() {
|
||||
}
|
||||
|
||||
/*
|
||||
reads an axis (0 or 1 for x or y) and scales the
|
||||
reads an axis (0 or 1 for x or y) and scales the
|
||||
analog input range to a range from 0 to <range>
|
||||
*/
|
||||
|
||||
int readAxis(int thisAxis) {
|
||||
int readAxis(int thisAxis) {
|
||||
// read the analog input:
|
||||
int reading = analogRead(thisAxis);
|
||||
|
||||
@ -111,7 +111,7 @@ int readAxis(int thisAxis) {
|
||||
|
||||
if (abs(distance) < threshold) {
|
||||
distance = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// return the distance for this axis:
|
||||
return distance;
|
||||
|
Reference in New Issue
Block a user