Arduino Leonardo + Grove Base Sheild レッスン
Arduino Leonardoを選択する
https://gyazo.com/f56179b740f6b1ad24c9da5f711e70ba
Lチカする
https://gyazo.com/5a023866c955db85801ccd3b5d5c0ef8
シールドを刺す
https://gyazo.com/6e03b129f9d0fb640c3b67f98211c4a1
垂直に差しこむ
斜めにいれるとピンが曲がる
スライドスイッチは5Vにする
キーボード化する
注意
Arduinoから文字が送られるため、意図せぬトラブルを招くことがある。プログラムと配線には十分注意し、あらかじめ関係のないアプリケーションは終了させておくこと。不足の事態が起こったら、PC側のUSBケーブルを抜くこと。
code:keyboard01.js
#include "Keyboard.h"
void setup() {
Keyboard.begin();
pinMode(2, INPUT);
}
void loop() {
if(digitalRead(2) == HIGH){
Keyboard.print("a");
delay(200);
}
else{}
delay(1);
}
code: keyboard02.js
//加速度センサをi2cにつなぐ
//誤入力を防ぐためD2のボタンを外さない
#include "LIS3DHTR.h"
#include "Keyboard.h"
#ifdef SOFTWAREWIRE
#include <SoftwareWire.h>
SoftwareWire myWire(3, 2);
LIS3DHTR<SoftwareWire> LIS; //Software I2C
#define WIRE myWire
#else
#include <Wire.h>
LIS3DHTR<TwoWire> LIS; //Hardware I2C
#define WIRE Wire
#endif
void setup() {
Keyboard.begin();
LIS.begin(WIRE, 0x19); //IIC init
delay(100);
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
}
void loop() {
if (!LIS) {
Serial.println("LIS3DHTR didn't connect.");
while (1);
return;
}
if(LIS.getAccelerationX()*LIS.getAccelerationY()>2){
Keyboard.print("Ouch!");
Serial.println("Ouch");
delay(500);
}else{
}
delay(10);
}
キーボード関数について
https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
マウス関数について
https://www.arduino.cc/reference/en/language/functions/usb/mouse/
#arduino