ウィルス、天候もあって、引きこもりな週末。
というか、,もともと 根がひきこまラーなのだが。
宅配便でお届け頂ける方のおかげで、苦にならず。感謝感謝です。
お届け頂いた物で、久々電子工作。HID(要はゲームパットみたいな物)
をつくった。
マイコンボードには Tennsy2.0を使い、
マウスカーソルを動かすのにはJOYスティックみたいな物で動かせるように
良く使うショートカットキーは 右側のスイッチで動かせるように
プログラムは以下、 回路は複雑で無いので記載を割愛ですみません。
Tennsy を使うとBIOS時テキスト入力を求められた時でも、テキスト入力出来ました。
あとで直します。どうも プログラムをそのままコピペすると 一部
表示がおかしくなる模様。
// When setting up the NeoPixel library, we tell it how many pixels,
// and which pin to use to send signals. Note that for older NeoPixel
// strips you might need to change the third parameter -- see the
// strandtest example for more information on possible values.
Adafruit_NeoPixel pixels(int_NUMPIXELS, int_PIN, NEO_GRB + NEO_KHZ800);
#include
#include "Adafruit_seesaw.h"
Adafruit_seesaw ss;
const int int_BUTTON_RIGHT = 6;
const int int_BUTTON_DOWN = 7;
const int int_BUTTON_LEFT = 9;
const int int_BUTTON_UP = 10;
const int int_BUTTON_SEL = 14;
uint32_t button_mask = (1 <
(1 <
#if defined(ESP8266)
#define IRQ_PIN 2
#elif defined(ESP32)
#define IRQ_PIN 14
#elif defined(ARDUINO_NRF52832_FEATHER)
#define IRQ_PIN 27
#elif defined(TEENSYDUINO)
#define IRQ_PIN 8
#elif defined(ARDUINO_ARCH_WICED)
#define IRQ_PIN PC5
#else
#define IRQ_PIN 5
#endif
// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10); // which is appropriate for
Bounce button3 = Bounce(3, 10); // most mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 10); // to rapid touch, you can
Bounce button7 = Bounce(7, 10); // increase this time.
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
// const int ledPin = 5; // Mouse control LED
// parameters for reading the joystick:
const int int_range = 48; // output range of X or Y movement
const int int_responseDelay = 10; // response delay of the mouse, in ms
const int threshold = int_range / 48; // resting threshold
const int center = int_range / 2; // resting position value
//bool boo_mouseIsActive = false; // whether or not to control the mouse
bool boo_mouseIsActive = true; // whether or not to control the mouse
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
Serial.println("Joy FeatherWing");
if (!ss.begin(0x49)) {
Serial.println("ERROR! seesaw not found");
while (1);
} else {
Serial.println("seesaw started");
Serial.print("version: ");
Serial.println(ss.getVersion(), HEX);
}
ss.pinModeBulk(button_mask, INPUT_PULLUP);
ss.setGPIOInterrupts(button_mask, 1);
pinMode(IRQ_PIN, INPUT);
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(0, INPUT_PULLUP); // Function Text
pinMode(1, INPUT_PULLUP); // Function Print Screen Win+Alt+PrtScrn
pinMode(2, INPUT_PULLUP); // Function Start/Stop Recording Win+Alt+R
pinMode(3, INPUT_PULLUP); // Function Screen shoot Win+Shift+S
pinMode(4, INPUT_PULLUP); // Function Undo Cont+z
// pinMode(5, INPUT_PULLUP);
// pinMode(6, INPUT_PULLUP); // Teensy++ LED, may need 1k resistor pullup
// pinMode(7, INPUT_PULLUP);
// pinMode(8, INPUT_PULLUP);
// pinMode(9, INPUT_PULLUP);
// If your screen is a different size, edit this to set the size.
// Even if the size does not match, mouse.moveTo(x, y) will still
// work, but the results will be scaled as if the x,y coordinate
// was on this screen. Setting the correct screen size allows you
// to use the actual pixel coordinates of your screen.
// //Mouse.screenSize(1920, 1080);
// screenSize() is not supported on Teensy 2.0 & Teensy++ 2.0.
// Delete this line to run on 8 bit Teensy boards.
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixel colors to 'off
for(int i=0; i
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
pixels.setPixelColor(i, pixels.Color(3, 3, 3));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(1000); // Pause before next pass through loop
}
}
void loop() {
/* if(!digitalRead(IRQ_PIN)) { // Uncomment to use IRQ */
uint32_t buttons = ss.digitalReadBulk(button_mask);
//Serial.println(buttons, BIN);
if (! (buttons & (1 <
Serial.println("Button A pressed");
NeoPixels(0,10,0,50);
Mouse.move(0, 1);
NeoPixels(0,0,0,0);
}
if (! (buttons & (1 <
Serial.println("Button B pressed");
NeoPixels(0,10,0,50);
Mouse.move(-1, 0);
NeoPixels(0,0,0,0);
}
if (! (buttons & (1 <
Serial.println("Button Y pressed");
NeoPixels(0,10,0,50);
Mouse.move(0, -1);
NeoPixels(0,0,0,0);
}
if (! (buttons & (1 <
Serial.println("Button X pressed");
NeoPixels(0,10,0,50);
Mouse.move(1, 0);
NeoPixels(0,0,0,0);
}
if (! (buttons & (1 <
Serial.println("Button SEL pressed");
boo_mouseIsActive = !boo_mouseIsActive;
NeoPixels(1,0,0,400);
NeoPixels(0,0,0,100);
}
/* } // Uncomment to use IRQ */
// read and scale the two axes:
int xReading = readAxis(2);
int yReading = readAxis(3);
if ((xReading != 0 ) || (yReading != 0)) {
NeoPixels(0,0,10,0);
Serial.print("xReading = "); Serial.print(xReading);
Serial.print(", ");
Serial.print("yReading = "); Serial.println(yReading);
}
// if the mouse control state is active, move the mouse:
if (boo_mouseIsActive) {
Mouse.move(xReading, yReading);
NeoPixels(0,0,0,0);
}
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
// button5.update();
// button6.update();
// button7.update();
// button8.update();
// button9.update();
// Check each button for "falling" edge.
// Type a message on the Keyboard when each button presses
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button0.fallingEdge()) {
//Keyboard.println("B0 press");
NeoPixels(10,0,0,100);
Keyboard.press(KEY_A);
Keyboard.release(KEY_A);
//delay (50);
Keyboard.press(KEY_ENTER);
Keyboard.release(KEY_ENTER);
}
if (button1.fallingEdge()) {
//Keyboard.println("B1 press");
NeoPixels(10,10,10,100);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_LEFT_ALT);
delay(100);
Keyboard.press(KEY_PRINTSCREEN);
delay(500);
Keyboard.releaseAll();
delay (50);
}
if (button2.fallingEdge()) {
//Keyboard.println("B2 press");
NeoPixels(0,0,10,100);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_LEFT_ALT);
delay(100);
Keyboard.press('r');
delay(500);
Keyboard.releaseAll();
delay (500);
}
if (button3.fallingEdge()) {
//Keyboard.println("B3 press");
NeoPixels(1,10,1,100);
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_LEFT_SHIFT);
delay(100);
Keyboard.press('s');
delay(500);
Keyboard.releaseAll();
delay(100);
Keyboard.press(KEY_TAB);
Keyboard.release(KEY_TAB);
delay(100);
Keyboard.press(KEY_TAB);
Keyboard.release(KEY_TAB);
delay(100);
Keyboard.press(KEY_TAB);
Keyboard.release(KEY_TAB);
delay(100);
Keyboard.press(KEY_TAB);
Keyboard.release(KEY_TAB);
delay(100);
Keyboard.press(KEY_RETURN);
delay(100);
Keyboard.releaseAll();
delay(1000);
}
if (button4.fallingEdge()) {
//Keyboard.println("B4 press");
NeoPixels(10,5,0,100);
Keyboard.press(KEY_LEFT_CTRL);
delay(100);
Keyboard.press('z');
delay(500);
Keyboard.releaseAll();
delay (500);
}
// if (button5.fallingEdge()) {
// Keyboard.println("B5 press");
// }
// if (button6.fallingEdge()) {
// Keyboard.println("B6 press");
// }
// if (button7.fallingEdge()) {
// Keyboard.println("B7 press");
// }
// if (button8.fallingEdge()) {
// Keyboard.println("B8 press");
//}
// if (button9.fallingEdge()) {
// Keyboard.println("B9 press");
// }
// Check each button for "rising" edge
// Type a message on the Keyboard when each button releases.
// For many types of projects, you only care when the button
// is pressed and the release isn't needed.
// rising = low (pressed - button connects pin to ground)
// to high (not pressed - voltage from pullup resistor)
if (button0.risingEdge()) {
//Keyboard.println("B0 release");
//Keyboard.release(KEY_ENTER);
NeoPixels(0,0,0,0);
}
if (button1.risingEdge()) {
//Keyboard.println("B1 release");
NeoPixels(0,0,0,0);
}
if (button2.risingEdge()) {
//Keyboard.println("B2 release");
NeoPixels(0,0,0,0);
}
if (button3.risingEdge()) {
//Keyboard.println("B3 release");
NeoPixels(0,0,0,0);
}
if (button4.risingEdge()) {
//Keyboard.println("B4 release");
NeoPixels(0,0,0,0);
}
// if (button5.risingEdge()) {
// Keyboard.println("B5 release");
// }
// if (button6.risingEdge()) {
// Keyboard.println("B6 release");
// }
// if (button7.risingEdge()) {
// Keyboard.println("B7 release");
// }
// if (button8.risingEdge()) {
// Keyboard.println("B8 release");
// }
// if (button9.risingEdge()) {
// Keyboard.println("B9 release");
// }
delay(int_responseDelay);
}
int readAxis(int thisAxis) {
// read the analog input:
int reading = ss.analogRead(thisAxis);
// map the reading from the analog input range to the output range:
reading = map(reading, 0, 1023, 0, int_range);
// if the output reading is outside from the rest position threshold, use it:
int distance = reading - center;
if (abs(distance)
distance = 0;
}
// return the distance for this axis:
return distance;
}
void NeoPixels(int r, int g, int b, int d){
// Serial.println("NeoPixels start,");
pixels.clear(); // Set all pixel colors to 'off
for(int i=0; i
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
pixels.setPixelColor(i, pixels.Color(r, g, b));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(d); // Pause before next pass through loop
}
}