Skip to content

Commit 9c072e6

Browse files
committed
Update Old Pro Micro Examples
- adjust the output for the hardware UART in **Blinkies.ino** file to distinguish betweeh the serial monitor - add `Keyboard.begin()` in `setup()` for **SimpleKeyboard_HID.ino** (this appears to work without initializing it but it was added to be consistent with Arduino's reference example) - add `Mouse.begin()` in `setup()` to **SimpleJoystickMouse_HID.ino** (this appears to work without initializing it but it was added to be consistent with Arduino's reference example) - include the ability to invert the mouse using the joystick depending on the orientation of the joystick -autoformat
1 parent 99359c2 commit 9c072e6

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

Firmware/Blinkies/Blinkies.ino

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,33 @@
1313
*/
1414

1515
int RXLED = 17; // The RX LED has a defined Arduino pin
16-
// The TX LED was not so lucky, we'll need to use pre-defined
16+
// Note: The TX LED was not so lucky, we'll need to use pre-defined
1717
// macros (TXLED1, TXLED0) to control that.
1818
// (We could use the same macros for the RX LED too -- RXLED1,
1919
// and RXLED0.)
2020

2121
void setup()
2222
{
23-
pinMode(RXLED, OUTPUT); // Set RX LED as an output
24-
// TX LED is set as an output behind the scenes
23+
pinMode(RXLED, OUTPUT); // Set RX LED as an output
24+
// TX LED is set as an output behind the scenes
2525

26-
Serial.begin(9600); //This pipes to the serial monitor
27-
Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
26+
Serial.begin(9600); //This pipes to the serial monitor
27+
Serial.println("Initialize Serial Monitor");
28+
29+
Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
30+
Serial1.println("Initialize Serial Hardware UART Pins");
2831
}
2932

3033
void loop()
3134
{
32-
Serial.println("Hello world"); // Print "Hello World" to the Serial Monitor
33-
Serial1.println("Hello!"); // Print "Hello!" over hardware UART
35+
Serial.println("Hello world!"); // Print "Hello World" to the Serial Monitor
36+
Serial1.println("Hello! Can anybody hear me?"); // Print "Hello!" over hardware UART
3437

35-
digitalWrite(RXLED, LOW); // set the RX LED ON
36-
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
37-
delay(1000); // wait for a second
38+
digitalWrite(RXLED, LOW); // set the RX LED ON
39+
TXLED0; //TX LED is not tied to a normally controlled pin so a macro is needed, turn LED OFF
40+
delay(1000); // wait for a second
3841

39-
digitalWrite(RXLED, HIGH); // set the RX LED OFF
40-
TXLED1; //TX LED macro to turn LED ON
41-
delay(1000); // wait for a second
42+
digitalWrite(RXLED, HIGH); // set the RX LED OFF
43+
TXLED1; //TX LED macro to turn LED ON
44+
delay(1000); // wait for a second
4245
}

Firmware/SimpleJoystickMouse_HID/SimpleJoystickMouse_HID.ino

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
No restrictions. Just keep this license if you go on to use this
66
code in your future endeavors! Reuse and share.
77
8-
This is very simplistic code that allows you to turn the
8+
This is very simplistic code that allows you to turn the
99
SparkFun Thumb Joystick (http://www.sparkfun.com/products/9032)
1010
into an HID Mouse. The select button on the joystick is set up
11-
as the mouse left click.
12-
*/
11+
as the mouse left click.
12+
*/
1313
#include <Mouse.h>
1414
int horzPin = A0; // Analog output of horizontal joystick pin
1515
int vertPin = A1; // Analog output of vertical joystick pin
@@ -20,6 +20,9 @@ int vertValue, horzValue; // Stores current analog output of each axis
2020
const int sensitivity = 200; // Higher sensitivity value = slower mouse, should be <= about 500
2121
int mouseClickFlag = 0;
2222

23+
//int invertMouse = 1; //Invert joystick based on orientation
24+
int invertMouse = -1; //Noninverted joystick based on orientation
25+
2326
void setup()
2427
{
2528
pinMode(horzPin, INPUT); // Set both analog pins as inputs
@@ -30,6 +33,7 @@ void setup()
3033
vertZero = analogRead(vertPin); // get the initial values
3134
horzZero = analogRead(horzPin); // Joystick should be in neutral position when reading these
3235

36+
Mouse.begin(); //Init mouse emulation
3337
}
3438

3539
void loop()
@@ -38,16 +42,16 @@ void loop()
3842
horzValue = analogRead(horzPin) - horzZero; // read horizontal offset
3943

4044
if (vertValue != 0)
41-
Mouse.move(0, vertValue/sensitivity, 0); // move mouse on y axis
45+
Mouse.move(0, (invertMouse * (vertValue / sensitivity)), 0); // move mouse on y axis
4246
if (horzValue != 0)
43-
Mouse.move(horzValue/sensitivity, 0, 0); // move mouse on x axis
47+
Mouse.move((invertMouse * (horzValue / sensitivity)), 0, 0); // move mouse on x axis
4448

4549
if ((digitalRead(selPin) == 0) && (!mouseClickFlag)) // if the joystick button is pressed
4650
{
4751
mouseClickFlag = 1;
4852
Mouse.press(MOUSE_LEFT); // click the left button down
4953
}
50-
else if ((digitalRead(selPin))&&(mouseClickFlag)) // if the joystick button is not pressed
54+
else if ((digitalRead(selPin)) && (mouseClickFlag)) // if the joystick button is not pressed
5155
{
5256
mouseClickFlag = 0;
5357
Mouse.release(MOUSE_LEFT); // release the left button

Firmware/SimpleKeyboard_HID/SimpleKeyboard_HID.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
code in your future endeavors! Reuse and share.
77
88
This is very simplistic code that allows you to send a 'z' with
9-
a momentary pushbutton.
10-
*/
9+
a momentary pushbutton.
10+
*/
1111

1212
#include <Keyboard.h>
1313
int buttonPin = 9; // Set a button to any pin
@@ -16,6 +16,8 @@ void setup()
1616
{
1717
pinMode(buttonPin, INPUT); // Set the button as an input
1818
digitalWrite(buttonPin, HIGH); // Pull the button high
19+
20+
Keyboard.begin(); //Init keyboard emulation
1921
}
2022

2123
void loop()

0 commit comments

Comments
 (0)