uploaded week 7
BIN
content/docs/2023/code-design/7/2023-code-and-design-7.pdf
Normal file
152
content/docs/2023/code-design/7/_index.en.md
Normal file
@ -0,0 +1,152 @@
|
||||
---
|
||||
title: Week 7
|
||||
date: 2023-05-26
|
||||
weight: 7
|
||||
---
|
||||
|
||||
# 2023 Tokyo University of the Arts Art media Center「Code and Design」
|
||||
|
||||
## Slides (in Japanese)
|
||||
|
||||
{{< button href="2023-code-and-design-7.pdf">}}Slides(PDF){{< /button >}}
|
||||
|
||||
{{< button href="./slides">}}Slides(HTML){{< /button >}}
|
||||
|
||||
|
||||
## Python Scripts for Mouse Automation
|
||||
|
||||
https://github.com/tomoyanonymous/py-serial-automouse
|
||||
|
||||
{{< button href="https://github.com/tomoyanonymous/py-serial-automouse/archive/refs/heads/main.zip">}} DL Zip {{< /button >}}
|
||||
|
||||
## Arduino Example Codes
|
||||
|
||||
### ADCTouch_monitor.ino
|
||||
|
||||
{{< button href="./ADCTouch_monitor/ADCTouch_monitor.ino">}}DL{{< /button >}}
|
||||
|
||||
```cpp
|
||||
#include <ADCTouch.h>
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop() {
|
||||
int val = ADCTouch.read(A0, 100);
|
||||
Serial.println(val);
|
||||
delay(40);
|
||||
}
|
||||
```
|
||||
|
||||
### ADCTouch_minimal.ino
|
||||
|
||||
{{< button href="./ADCTouch_minimal/ADCTouch_minimal.ino">}}DL{{< /button >}}
|
||||
|
||||
```cpp
|
||||
#include <ADCTouch.h>
|
||||
//setup()とloop()で共通して使う値はグローバル変数(関数の外側)で定義しておく
|
||||
int ref = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
//繋げた導体の状態で初期値が変わるので、それを保存しておく必要がある
|
||||
ref = ADCTouch.read(A0, 100); //(使用するピン番号,平均を取るサンプル数)
|
||||
}
|
||||
void loop() {
|
||||
int val = ADCTouch.read(A0, 100) - ref;
|
||||
if (val > 40) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
Serial.println(val);
|
||||
delay(40);
|
||||
}
|
||||
```
|
||||
|
||||
### ADCTouch_Mouse
|
||||
|
||||
{{< button href="./ADCTouch_Mouse/ADCTouch_Mouse.ino">}}DL{{< /button >}}
|
||||
|
||||
```cpp
|
||||
#include <ADCTouch.h>
|
||||
|
||||
const int upButton = A0;
|
||||
const int downButton = A1;
|
||||
const int leftButton = A2;
|
||||
const int rightButton = A3;
|
||||
const int mouseButton = A4;
|
||||
int ref_up = 0;
|
||||
int ref_down = 0;
|
||||
int ref_left = 0;
|
||||
int ref_right = 0;
|
||||
int ref_mouse = 0;
|
||||
|
||||
int range = 10; // マウスカーソルの移動幅
|
||||
|
||||
void setup() {
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
|
||||
ref_up = ADCTouch.read(upButton, 100);
|
||||
ref_down = ADCTouch.read(downButton, 100);
|
||||
ref_left = ADCTouch.read(leftButton, 100);
|
||||
ref_right = ADCTouch.read(rightButton, 100);
|
||||
ref_mouse = ADCTouch.read(mouseButton, 100);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//マウス移動に関する処理をひとまとめに
|
||||
void moveMouse(int x, int y, int mouse_state) {
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(y);
|
||||
Serial.print(" ");
|
||||
Serial.println(mouse_state);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ボタンの検出
|
||||
int v1 = ADCTouch.read(upButton, 100) - ref_up;
|
||||
int v2 = ADCTouch.read(downButton, 100) - ref_down;
|
||||
int v3 = ADCTouch.read(leftButton, 100) - ref_left;
|
||||
int v4 = ADCTouch.read(rightButton, 100) - ref_right;
|
||||
int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
|
||||
//40以上ならクリックしたとみなし、1を、40以下なら0を
|
||||
// A ? B : C;はif (A) { return B;} else {return C;} の略記(三項演算子)
|
||||
int upState = v1 > 40 ? 1 : 0;
|
||||
int downState = v2 > 40 ? 1 : 0;
|
||||
int rightState = v3 > 40 ? 1 : 0;
|
||||
int leftState = v4 > 40 ? 1 : 0;
|
||||
int clickState = v5 > 40 ? 1 : 0;
|
||||
// 移動距離を算出(左右同時押しも考慮)
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
//移動もクリックもしてないならシリアル送信は冗長なので、しない
|
||||
// && は AND、!はNOT
|
||||
if (!(xDistance == 0 && yDistance == 0 && clickState == 0)) {
|
||||
moveMouse(xDistance, yDistance, clickState);
|
||||
}
|
||||
delay(5);
|
||||
}
|
||||
```
|
||||
|
||||
### DrunkMouse(Add Randomness)
|
||||
|
||||
{{< button href="./DrunkMouse/DrunkMouse.ino">}}DL{{< /button >}}
|
||||
|
||||
### ADCTouch_Mouse_HID.ino (Only works for Leonardo and Pro Micro)
|
||||
|
||||
{{< button href="./ADCTouch_Mouse_HID/ADCTouch_Mouse_HID.ino">}}DL{{< /button >}}
|
||||
|
||||
### ADCTouch_Mouse_scroll.ino(works only with `move_relative_scroll.command`)
|
||||
|
||||
{{< button href="./ADCTouch_Mouse_scroll/ADCTouch_Mouse_scroll.ino">}}DL{{< /button >}}
|
151
content/docs/2023/code-design/7/_index.md
Normal file
@ -0,0 +1,151 @@
|
||||
---
|
||||
title: 第7週
|
||||
date: 2023-05-26
|
||||
weight: 7
|
||||
---
|
||||
|
||||
# 2023年 東京藝術大学 芸術情報センター開設科目 「コードとデザイン」 第7回
|
||||
|
||||
## スライド
|
||||
|
||||
{{< button href="2023-code-and-design-7.pdf">}}スライド(PDF){{< /button >}}
|
||||
|
||||
{{< button href="slides">}}スライド(HTML){{< /button >}}
|
||||
|
||||
## マウスを動かすためのPythonスクリプト
|
||||
|
||||
https://github.com/tomoyanonymous/py-serial-automouse
|
||||
|
||||
{{< button href="https://github.com/tomoyanonymous/py-serial-automouse/archive/refs/heads/main.zip">}} DL Zip {{< /button >}}
|
||||
|
||||
## Arduinoサンプルコード
|
||||
|
||||
### ADCTouch_monitor.ino
|
||||
|
||||
{{< button href="examples/ADCTouch_monitor/ADCTouch_monitor.ino">}}DL{{< /button >}}
|
||||
|
||||
```cpp
|
||||
#include <ADCTouch.h>
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void loop() {
|
||||
int val = ADCTouch.read(A0, 100);
|
||||
Serial.println(val);
|
||||
delay(40);
|
||||
}
|
||||
```
|
||||
|
||||
### ADCTouch_minimal.ino
|
||||
|
||||
{{< button href="examples/ADCTouch_minimal/ADCTouch_minimal.ino">}}DL{{< /button >}}
|
||||
|
||||
```cpp
|
||||
#include <ADCTouch.h>
|
||||
//setup()とloop()で共通して使う値はグローバル変数(関数の外側)で定義しておく
|
||||
int ref = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
//繋げた導体の状態で初期値が変わるので、それを保存しておく必要がある
|
||||
ref = ADCTouch.read(A0, 100); //(使用するピン番号,平均を取るサンプル数)
|
||||
}
|
||||
void loop() {
|
||||
int val = ADCTouch.read(A0, 100) - ref;
|
||||
if (val > 40) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
Serial.println(val);
|
||||
delay(40);
|
||||
}
|
||||
```
|
||||
|
||||
### ADCTouch_Mouse
|
||||
|
||||
{{< button href="examples/ADCTouch_Mouse/ADCTouch_Mouse.ino">}}DL{{< /button >}}
|
||||
|
||||
```cpp
|
||||
#include <ADCTouch.h>
|
||||
|
||||
const int upButton = A0;
|
||||
const int downButton = A1;
|
||||
const int leftButton = A2;
|
||||
const int rightButton = A3;
|
||||
const int mouseButton = A4;
|
||||
int ref_up = 0;
|
||||
int ref_down = 0;
|
||||
int ref_left = 0;
|
||||
int ref_right = 0;
|
||||
int ref_mouse = 0;
|
||||
|
||||
int range = 10; // マウスカーソルの移動幅
|
||||
|
||||
void setup() {
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
|
||||
ref_up = ADCTouch.read(upButton, 100);
|
||||
ref_down = ADCTouch.read(downButton, 100);
|
||||
ref_left = ADCTouch.read(leftButton, 100);
|
||||
ref_right = ADCTouch.read(rightButton, 100);
|
||||
ref_mouse = ADCTouch.read(mouseButton, 100);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//マウス移動に関する処理をひとまとめに
|
||||
void moveMouse(int x, int y, int mouse_state) {
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(y);
|
||||
Serial.print(" ");
|
||||
Serial.println(mouse_state);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ボタンの検出
|
||||
int v1 = ADCTouch.read(upButton, 100) - ref_up;
|
||||
int v2 = ADCTouch.read(downButton, 100) - ref_down;
|
||||
int v3 = ADCTouch.read(leftButton, 100) - ref_left;
|
||||
int v4 = ADCTouch.read(rightButton, 100) - ref_right;
|
||||
int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
|
||||
//40以上ならクリックしたとみなし、1を、40以下なら0を
|
||||
// A ? B : C;はif (A) { return B;} else {return C;} の略記(三項演算子)
|
||||
int upState = v1 > 40 ? 1 : 0;
|
||||
int downState = v2 > 40 ? 1 : 0;
|
||||
int rightState = v3 > 40 ? 1 : 0;
|
||||
int leftState = v4 > 40 ? 1 : 0;
|
||||
int clickState = v5 > 40 ? 1 : 0;
|
||||
// 移動距離を算出(左右同時押しも考慮)
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
//移動もクリックもしてないならシリアル送信は冗長なので、しない
|
||||
// && は AND、!はNOT
|
||||
if (!(xDistance == 0 && yDistance == 0 && clickState == 0)) {
|
||||
moveMouse(xDistance, yDistance, clickState);
|
||||
}
|
||||
delay(5);
|
||||
}
|
||||
```
|
||||
|
||||
### DrunkMouse(ランダム性の追加)
|
||||
|
||||
{{< button href="examples/DrunkMouse/DrunkMouse.ino">}}DL{{< /button >}}
|
||||
|
||||
### ADCTouch_Mouse_HID.ino (Leonardo、Pro Microのみ)
|
||||
|
||||
{{< button href="examples/ADCTouch_Mouse_HID/ADCTouch_Mouse_HID.ino">}}DL{{< /button >}}
|
||||
|
||||
### ADCTouch_Mouse_scroll.ino(move_relative_scroll.commandと合わせて使う事)
|
||||
|
||||
{{< button href="examples/ADCTouch_Mouse_scroll/ADCTouch_Mouse_scroll.ino">}}DL{{< /button >}}
|
@ -0,0 +1,66 @@
|
||||
#include <ADCTouch.h>
|
||||
|
||||
const int upButton = A0;
|
||||
const int downButton = A1;
|
||||
const int leftButton = A2;
|
||||
const int rightButton = A3;
|
||||
const int mouseButton = A4;
|
||||
int ref_up = 0;
|
||||
int ref_down = 0;
|
||||
int ref_left = 0;
|
||||
int ref_right = 0;
|
||||
int ref_mouse = 0;
|
||||
|
||||
int range = 10; // マウスカーソルの移動幅
|
||||
|
||||
void setup() {
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
|
||||
ref_up = ADCTouch.read(upButton, 100);
|
||||
ref_down = ADCTouch.read(downButton, 100);
|
||||
ref_left = ADCTouch.read(leftButton, 100);
|
||||
ref_right = ADCTouch.read(rightButton, 100);
|
||||
ref_mouse = ADCTouch.read(mouseButton, 100);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//マウス移動に関する処理をひとまとめに
|
||||
void moveMouse(int x, int y, int mouse_state) {
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(y);
|
||||
Serial.print(" ");
|
||||
Serial.println(mouse_state);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ボタンの検出
|
||||
int v1 = ADCTouch.read(upButton, 100) - ref_up;
|
||||
int v2 = ADCTouch.read(downButton, 100) - ref_down;
|
||||
int v3 = ADCTouch.read(leftButton, 100) - ref_left;
|
||||
int v4 = ADCTouch.read(rightButton, 100) - ref_right;
|
||||
int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
|
||||
//40以上ならクリックしたとみなし、1を、40以下なら0を
|
||||
// A ? B : C;はif (A) { return B;} else {return C;} の略記(三項演算子)
|
||||
int upState = v1 > 40 ? 1 : 0;
|
||||
int downState = v2 > 40 ? 1 : 0;
|
||||
int rightState = v3 > 40 ? 1 : 0;
|
||||
int leftState = v4 > 40 ? 1 : 0;
|
||||
int clickState = v5 > 40 ? 1 : 0;
|
||||
// 移動距離を算出(左右同時押しも考慮)
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
//移動もクリックもしてないならシリアル送信は冗長なので、しない
|
||||
// && は AND、!はNOT
|
||||
if (!(xDistance == 0 && yDistance == 0 && clickState == 0)) {
|
||||
moveMouse(xDistance, yDistance, clickState);
|
||||
}
|
||||
|
||||
delay(5);
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
// Arduino Leonardo,Arduino Micro,Sparkfun Pro Microなど、ATMega32u4チップのものを使うこと
|
||||
|
||||
#include <Mouse.h>
|
||||
#include <ADCTouch.h>
|
||||
|
||||
const int upButton = A0;
|
||||
const int downButton = A1;
|
||||
const int leftButton = A2;
|
||||
const int rightButton = A3;
|
||||
const int mouseButton = A4;
|
||||
int ref_up = 0;
|
||||
int ref_down = 0;
|
||||
int ref_left = 0;
|
||||
int ref_right = 0;
|
||||
int ref_mouse = 0;
|
||||
|
||||
int range = 10;
|
||||
|
||||
void setup() {
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
|
||||
ref_up = ADCTouch.read(upButton, 100);
|
||||
ref_down = ADCTouch.read(downButton, 100);
|
||||
ref_left = ADCTouch.read(leftButton, 100);
|
||||
ref_right = ADCTouch.read(rightButton, 100);
|
||||
ref_mouse = ADCTouch.read(mouseButton, 100);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
void moveMouse(int x, int y, int mouse_state) {
|
||||
Mouse.move(x, y, 0);
|
||||
if (mouse_state == 1) {
|
||||
if (!Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.press(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (Mouse.isPressed(MOUSE_LEFT)) {
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
int v1 = ADCTouch.read(upButton, 100) - ref_up;
|
||||
int v2 = ADCTouch.read(downButton, 100) - ref_down;
|
||||
int v3 = ADCTouch.read(leftButton, 100) - ref_left;
|
||||
int v4 = ADCTouch.read(rightButton, 100) - ref_right;
|
||||
int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
|
||||
int upState = v1 > 40 ? 1 : 0;
|
||||
int downState = v2 > 40 ? 1 : 0;
|
||||
int rightState = v3 > 40 ? 1 : 0;
|
||||
int leftState = v4 > 40 ? 1 : 0;
|
||||
int clickState = v5 > 40 ? 1 : 0;
|
||||
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
|
||||
if (!(xDistance == 0 && yDistance == 0 && clickState == 0)) {
|
||||
moveMouse(xDistance, yDistance, clickState);
|
||||
}
|
||||
|
||||
delay(5);
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
#include <ADCTouch.h>
|
||||
|
||||
const int upButton = A0;
|
||||
const int downButton = A1;
|
||||
const int leftButton = A2;
|
||||
const int rightButton = A3;
|
||||
const int mouseButton = A4;
|
||||
const int scrollButton = A5;
|
||||
|
||||
int ref_up = 0;
|
||||
int ref_down = 0;
|
||||
int ref_left = 0;
|
||||
int ref_right = 0;
|
||||
int ref_mouse = 0;
|
||||
int ref_scroll = 0;
|
||||
|
||||
|
||||
int range = 10; // マウスカーソルの移動幅
|
||||
|
||||
void setup() {
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
pinMode(scrollButton, INPUT);
|
||||
|
||||
ref_up = ADCTouch.read(upButton, 100);
|
||||
ref_down = ADCTouch.read(downButton, 100);
|
||||
ref_left = ADCTouch.read(leftButton, 100);
|
||||
ref_right = ADCTouch.read(rightButton, 100);
|
||||
ref_mouse = ADCTouch.read(mouseButton, 100);
|
||||
ref_scroll = ADCTouch.read(scrollButton, 100);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//マウス移動に関する処理をひとまとめに
|
||||
void moveMouse(int x, int y, int mouse_state, int scroll=0) {
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(y);
|
||||
Serial.print(" ");
|
||||
Serial.print(mouse_state);
|
||||
Serial.print(" ");
|
||||
Serial.println(scroll);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ボタンの検出
|
||||
int v1 = ADCTouch.read(upButton, 100) - ref_up;
|
||||
int v2 = ADCTouch.read(downButton, 100) - ref_down;
|
||||
int v3 = ADCTouch.read(leftButton, 100) - ref_left;
|
||||
int v4 = ADCTouch.read(rightButton, 100) - ref_right;
|
||||
int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
|
||||
int v6 = ADCTouch.read(scrollButton, 100) - ref_scroll;
|
||||
|
||||
//40以上ならクリックしたとみなし、1を、40以下なら0を
|
||||
// A ? B : C;はif (A) { return B;} else {return C;} の略記(三項演算子)
|
||||
int upState = v1 > 40 ? 1 : 0;
|
||||
int downState = v2 > 40 ? 1 : 0;
|
||||
int rightState = v3 > 40 ? 1 : 0;
|
||||
int leftState = v4 > 40 ? 1 : 0;
|
||||
int clickState = v5 > 40 ? 1 : 0;
|
||||
int scrollState = v6 > 20 ? (v6 > 200 ? 1 : -1) : 0;
|
||||
|
||||
// 移動距離を算出(左右同時押しも考慮)
|
||||
int xDistance = (leftState - rightState) * range;
|
||||
int yDistance = (upState - downState) * range;
|
||||
|
||||
//移動もクリックもしてないならシリアル送信は冗長なので、しない
|
||||
// && は AND、!はNOT
|
||||
if (!(xDistance == 0 && yDistance == 0 && clickState == 0 && scrollState == 0)) {
|
||||
moveMouse(xDistance, yDistance, clickState,scrollState);
|
||||
}
|
||||
|
||||
delay(5);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
|
||||
#include <ADCTouch.h>
|
||||
//setup()とloop()で共通して使う値はグローバル変数(関数の外側)で定義しておく
|
||||
int ref = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
//繋げた導体の状態で初期値が変わるので、それを保存しておく必要がある
|
||||
ref = ADCTouch.read(A0, 100); //(使用するピン番号,平均を取るサンプル数)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
int val = ADCTouch.read(A0, 100) - ref;
|
||||
if (val > 40) {
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
|
||||
Serial.println(val);
|
||||
|
||||
delay(40);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
#include <ADCTouch.h>
|
||||
|
||||
void setup() {
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int val = ADCTouch.read(A0, 100);
|
||||
Serial.println(val);
|
||||
delay(40);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
#include <ADCTouch.h>
|
||||
|
||||
const int upButton = A0;
|
||||
const int downButton = A1;
|
||||
const int leftButton = A2;
|
||||
const int rightButton = A3;
|
||||
const int mouseButton = A4;
|
||||
int ref_up = 0;
|
||||
int ref_down = 0;
|
||||
int ref_left = 0;
|
||||
int ref_right = 0;
|
||||
int ref_mouse = 0;
|
||||
|
||||
int range = 10; // マウスカーソルの移動幅
|
||||
|
||||
void setup() {
|
||||
randomSeed(analogRead(A5));
|
||||
|
||||
pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
pinMode(leftButton, INPUT);
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);
|
||||
|
||||
ref_up = ADCTouch.read(upButton, 100);
|
||||
ref_down = ADCTouch.read(downButton, 100);
|
||||
ref_left = ADCTouch.read(leftButton, 100);
|
||||
ref_right = ADCTouch.read(rightButton, 100);
|
||||
ref_mouse = ADCTouch.read(mouseButton, 100);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
//マウス移動に関する処理をひとまとめに
|
||||
void moveMouse(int x, int y, int mouse_state) {
|
||||
Serial.print(x);
|
||||
Serial.print(" ");
|
||||
Serial.print(y);
|
||||
Serial.print(" ");
|
||||
Serial.println(mouse_state);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// ボタンの検出
|
||||
int v1 = ADCTouch.read(upButton, 100) - ref_up;
|
||||
int v2 = ADCTouch.read(downButton, 100) - ref_down;
|
||||
int v3 = ADCTouch.read(leftButton, 100) - ref_left;
|
||||
int v4 = ADCTouch.read(rightButton, 100) - ref_right;
|
||||
int v5 = ADCTouch.read(mouseButton, 100) - ref_mouse;
|
||||
//40以上ならクリックしたとみなし、1を、40以下なら0を
|
||||
// A ? B : C;はif (A) { return B;} else {return C;} の略記(三項演算子)
|
||||
int upState = v1 > 40 ? 1 : 0;
|
||||
int downState = v2 > 40 ? 1 : 0;
|
||||
int rightState = v3 > 40 ? 1 : 0;
|
||||
int leftState = v4 > 40 ? 1 : 0;
|
||||
int clickState = v5 > 40 ? 1 : 0;
|
||||
// 移動距離を算出(左右同時押しも考慮)
|
||||
int xDistance = (leftState - rightState) * range + random(-10,10);
|
||||
int yDistance = (upState - downState) * range + random(-10,10);
|
||||
|
||||
//移動もクリックもしてないならシリアル送信は冗長なので、しない
|
||||
// && は AND、!はNOT
|
||||
if (!(xDistance == 0 && yDistance == 0 && clickState == 0)) {
|
||||
moveMouse(xDistance, yDistance, clickState);
|
||||
}
|
||||
|
||||
delay(5);
|
||||
}
|
After Width: | Height: | Size: 317 KiB |
After Width: | Height: | Size: 206 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 511 KiB |
After Width: | Height: | Size: 617 KiB |
After Width: | Height: | Size: 404 KiB |
After Width: | Height: | Size: 420 KiB |
After Width: | Height: | Size: 406 KiB |
After Width: | Height: | Size: 150 KiB |
After Width: | Height: | Size: 368 KiB |
After Width: | Height: | Size: 443 KiB |
After Width: | Height: | Size: 461 KiB |
After Width: | Height: | Size: 605 KiB |
After Width: | Height: | Size: 1.3 MiB |
After Width: | Height: | Size: 659 KiB |
After Width: | Height: | Size: 408 KiB |
After Width: | Height: | Size: 619 KiB |
After Width: | Height: | Size: 227 KiB |
After Width: | Height: | Size: 575 KiB |
After Width: | Height: | Size: 287 KiB |
After Width: | Height: | Size: 276 KiB |
After Width: | Height: | Size: 928 KiB |
After Width: | Height: | Size: 1010 KiB |
After Width: | Height: | Size: 202 KiB |
After Width: | Height: | Size: 234 KiB |
After Width: | Height: | Size: 979 KiB |
After Width: | Height: | Size: 288 KiB |
After Width: | Height: | Size: 409 KiB |
After Width: | Height: | Size: 506 KiB |
After Width: | Height: | Size: 846 KiB |
After Width: | Height: | Size: 955 KiB |
10
content/docs/2023/code-design/7/slides/index.en.md
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
title: "Code and Design 2023 class 7 Slides"
|
||||
date: 2023-05-19
|
||||
bookHidden: true
|
||||
---
|
||||
|
||||
|
||||
# Slides
|
||||
|
||||
{{< slides_jpg >}}
|
10
content/docs/2023/code-design/7/slides/index.md
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
title: "コードとデザイン 2023年 第7回 スライド"
|
||||
date: 2023-05-19
|
||||
bookHidden: true
|
||||
---
|
||||
|
||||
|
||||
# スライド
|
||||
|
||||
{{< slides_jpg >}}
|
@ -39,7 +39,7 @@ In addition, by learning how to convert data and materials into each other throu
|
||||
4. [(4/28) Binary Numbers WS ](./4)
|
||||
5. [(5/12) Handmade Computer(DIWO Full Adder)](./5)
|
||||
6. [(5/19) Software and Algorithm - Let's try using Arduino](./6)
|
||||
7. (5/26) Considering Inputs (Switches, Handmade Resistors)
|
||||
7. [(5/26) Considering Inputs (Make Unreasonable Mouse)](./7)
|
||||
8. (6/2) Considering Output (motor, solenoid, relay)
|
||||
9. (6/9) Cartesian Robot and Digital Fabrication (Plotter, Laser Cutter)
|
||||
10. (6/16) Cartesian Robot and Digital Fabrication (3D Printer and G-code Hack)
|
||||
|
@ -40,7 +40,7 @@ bookCollapseSection: true
|
||||
4. [(4/28) 二進数WS](./4)
|
||||
5. [(5/12) Handmade Computer(みんなでつくる全加算器)](./5)
|
||||
6. [(5/19) ソフトウェアとアルゴリズムーArduinoを使ってみよう](./6)
|
||||
7. (5/26) 入力を考える(スイッチ、自作抵抗)
|
||||
7. [(5/26) 入力を考える(不条理なマウスを作る)](./7)
|
||||
8. (6/2) 出力を考える(モーター、ソレノイド、リレー)
|
||||
9. (6/9) Cartesian Robotとデジタルファブリケーション(プロッター、レーザーカッター)
|
||||
10. (6/16) Cartesian Robotとデジタルファブリケーション (3DプリンターとGコードハック)
|
||||
|