0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

課題用プログラム

Posted at
#include "mouse.h"
#include "Keyboard.h"

void setup() {
  
  Serial.begin(115200); //シリアル通信用
  Keyboard.begin();

  analogReadResolution(12);
  pinMode(26, INPUT);
  pinMode(27, INPUT);
  Mouse.begin();
  
  for( int i=0; i >=15 ; i = i+1 ){ //0~4:切り替えスイッチ 5:空 6~15:ボタン
    pinMode(i,INPUT);
  }
}

void loop() {
  int Y = analogRead(26); //値の読み取り
  int X = analogRead(27);
  Serial.println(Y); //数値確認用
  Serial.println(X);
  delay(5);

  int Xmove = (-X-1200+4095)/100; //マウスの移動量調整
  int Ymove = (Y-3150)/100;

  Mouse.move(Xmove, Ymove, 0); //マウス入力

  if (digitalRead(0)==LOW && digitalRead(1)==LOW && digitalRead(2)==LOW) { //切り替えスイッチ000xxの時

    int X[9];

    if (digitalRead(3)==LOW && digitalRead(4)==LOW){        //切り替えスイッチxxx00の時
      X[0]={0x61}; X[1]={0x62}; X[2]={0x63}; X[3]={0x64}; X[4]={0x65}; X[5]={0x66}; X[6]={0x67}; X[7]={0x68}; X[8]={0x69};    
    }if (digitalRead(3)==LOW && digitalRead(4)==HIGH){        //切り替えスイッチxxx01の時
      X[0]={0x71}; X[1]={0x72}; X[2]={0x73}; X[3]={0x74}; X[4]={0x75}; X[4]={0x75}; X[5]={0x76}; X[6]={0x77}; X[7]={0x78}; X[8]={0x79};      
    }

    for( int i=0; i <=8 ; i++ ){
      if (digitalRead(i+6)==HIGH){
        Keyboard.press(X[i]);
      }else{
        Keyboard.release(X[i]);
      }
    }
  }
    
  if (digitalRead(0)==LOW && digitalRead(1)==LOW && digitalRead(2)==HIGH) { //切り替えスイッチ001xxの時

  if (digitalRead(6)==HIGH) {
    Keyboard.press(KEY_LEFT_SHIFT);
  }else{
    Keyboard.release(KEY_LEFT_SHIFT);
  }

  if (digitalRead(7)==HIGH) {
    Keyboard.press(KEY_LEFT_ALT);
  }else{
    Keyboard.release(KEY_LEFT_ALT);
  }

  if (digitalRead(8)==HIGH) {
    Keyboard.press(KEY_LEFT_CTRL);
  }else{
    Keyboard.release(KEY_LEFT_CTRL);
  }

  if (digitalRead(9)==HIGH) {
    Keyboard.press(KEY_ESC );
  }else{
    Keyboard.release(KEY_ESC );
  }

  if (digitalRead(10)==HIGH) {
    Keyboard.press(0x61);
  }else{
    Keyboard.release(0x61);
  }
  
  if (digitalRead(11)==HIGH) {
    Keyboard.press(0x61);
  }else{
    Keyboard.release(0x61);
  }

  if (digitalRead(12)==HIGH) {
    Keyboard.press(0x62);
  }else{
    Keyboard.release(0x62);
  }

  if (digitalRead(13)==HIGH) {
    Keyboard.press(0x63);
  }else{
    Keyboard.release(0x63);
  }

  if (digitalRead(14)==HIGH) {
    Keyboard.press(0x64);
  }else{
    Keyboard.release(0x64);
  }

  if (digitalRead(15)==HIGH) {
    Keyboard.press(0x65);
  }else{
    Keyboard.release(0x65);
  }
  }
  //長すぎる


  if (digitalRead(0)==LOW && digitalRead(1)==HIGH && digitalRead(2)==LOW) { //切り替えスイッチ010xxの時
    if (digitalRead(6)==HIGH) {
      Keyboard.println("thank you"); //入力して改行
    }
    if (digitalRead(7)==HIGH) {
      Keyboard.println("good job");
    }
    if (digitalRead(8)==HIGH) {
      Keyboard.println("OMG");
    }
  }  
}

ご自由にお使いください(多分使えん)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?