Compare commits

...

10 Commits

169 changed files with 1729 additions and 31 deletions

View File

@ -16,4 +16,67 @@ https://matsuuratomoya.com
授業関係の連絡はこちら↓ Related to courseworks
- teach\[at\]matsuuratomoya.com
- teach\[at\]matsuuratomoya.com
# 使い方のメモ
## 新しい授業資料更新のファイル作成コマンド
```sh
hugo new --kind class content/docs/2023/code-design/10
```
## カスタムショートコード
テーマのショートコードも使える。
https://github.com/alex-shpak/hugo-book#shortcodes 
### `embed_pdf` PDFの埋め込み
embedで埋め込むだけ。Page Bundleになっている必要があるので`index.md`と同ディレクトリでないと使えない
```md
{{< embed_pdf >}}
```
mdと同ディレクトリにあるPDFのうち一番先頭のファイルを埋め込む。
```md
---
...
params:
pdf_path:hoge.pdf
...
---
{{< embed_pdf >}}
```
フロントマッターで相対指定したPDFファイルを埋め込む。
```md
{{< embed_pdf href = "hoge.pdf">}}
```
インライン指定したPDFファイルを埋め込む。
### `slides_jpg`
```md
{{< slides_jpg >}}
```
Page Resourcesの中のJPGを全部名前順に連番で表示する。keynoteでjpgエクスポートした連番ファイルをそのまま突っ込んで表示できる想定。
### `preview_code`
指定したファイルを読み込んで通常のコードハイライト表示をし、ダウンロードのボタンを追加する。
これも埋め込むファイルがPage Resourcesになっている必要があるサブディレクトリに入れることはできない。
`type`でシンタックスハイライトの種類を指定できる。
```md
{{< preview_code href="tone_minimal.ino" type= "ino">}}
```

View File

@ -0,0 +1,18 @@
---
title: Week N
date: {{.Date}}
weight: 1
params:
pdf_path: "hoge.pdf"
draft: true
---
# {{.Date| dateFormat "2006"}} Class Name / Week N
## Slides
{{< embed_pdf >}}
{{< button href=.Page.Params.pdf_path >}}SlidesPDF{{< /button >}}
{{< button href="slides">}}SlidesHTML{{< /button >}}

View File

@ -0,0 +1,18 @@
---
title: 第N週
date: {{.Date}}
weight: 1
params:
pdf_path: "hoge.pdf"
draft: true
---
# {{.Date| dateFormat "2006"}}年 授業名 第N回
## スライド
{{< embed_pdf >}}
{{< button href=.Page.Params.pdf_path >}}スライドPDF{{< /button >}}
{{< button href="slides">}}スライドHTML{{< /button >}}

View File

@ -0,0 +1,10 @@
---
title: "Class Name {{.Date| dateFormat "2006"}} Week N Slides"
date: {{.Date}}
bookHidden: true
---
# Slides
{{< slides_jpg >}}

View File

@ -0,0 +1,10 @@
---
title: "授業名 {{.Date| dateFormat "2006"}}年 第N回 スライド"
date: {{.Date}}
bookHidden: true
---
# スライド
{{< slides_jpg >}}

View File

@ -21,6 +21,7 @@ contentDir = 'content'
weight = 2
title = "Classes by Matsuura Tomoya"
# (Optional) Set Google Analytics if you use it to track your website.
# Always put it on the top of the configuration file, otherwise it won't work

View File

@ -24,7 +24,7 @@ type: docs
近年の活動は電子音響楽器「Exidiophone」の制作とそれを用いた演奏活動、音楽プログラミング言語「mimium」の設計、開発(2019年度未踏IT人材発掘・育成事業採択、また2020年度同事業スーパークリエータ認定)など。
1994年生。2017年東京藝術大学 音楽学部音楽環境創造科卒業、2019年九州大学 大学院芸術工学府 修士課程修了。2018年School for Poetic Computation留学。2019年同大学院博士後期課程修了。博士(芸術工学)。
1994年生。2017年東京藝術大学 音楽学部音楽環境創造科卒業、2019年九州大学 大学院芸術工学府 修士課程修了。2018年School for Poetic Computation留学。2022年同大学院博士後期課程修了。博士(芸術工学)。
2022年より[東京藝術大学芸術情報センターAMC](https://amc.geidai.ac.jp/lab/)特任助教。
@ -49,6 +49,8 @@ Researchmap: <https://researchmap.jp/matsuuratomoya>
### [福岡女学院大学 「サウンド・デザイン」(夏季集中講義)](/docs/2022/fukujo-sounddesign)
### [電子基板制作WS 東京藝大アートDX・芸術情報土木工学特別演習](/docs/2022/geidai-pcbws)
## [2021年度](/docs/2021)
### [福岡女学院大学 「サウンド・デザイン」](/docs/2021/fukujo-sounddesign)

View 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">}}SlidesPDF{{< /button >}}
{{< button href="./slides">}}SlidesHTML{{< /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 >}}

View 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 >}}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 617 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 605 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 659 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 409 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 955 KiB

View File

@ -0,0 +1,10 @@
---
title: "Code and Design 2023 class 7 Slides"
date: 2023-05-26
bookHidden: true
---
# Slides
{{< slides_jpg >}}

View File

@ -0,0 +1,10 @@
---
title: "コードとデザイン 2023年 第7回 スライド"
date: 2023-05-26
bookHidden: true
---
# スライド
{{< slides_jpg >}}

View 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">}}SlidesPDF{{< /button >}}
{{< button href="./slides">}}SlidesHTML{{< /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 >}}

View File

@ -0,0 +1,183 @@
---
title: 第8週
date: 2023-06-02
weight: 8
---
# 2023年 東京藝術大学 芸術情報センター開設科目 「コードとデザイン」 第8回
## スライド
{{< button href="2023-code-and-design-8.pdf">}}スライドPDF{{< /button >}}
{{< button href="slides">}}スライドHTML{{< /button >}}
## Processingサンプルコード
### minimal_pong.pde
{{< button href="examples/minimal_pong/minimal_pong.pde">}}DL{{< /button >}}
```java
class Ball {
float x;
float y;
float vel_x;
float vel_y;
Ball() {
this.x = width/2;
this.y = height/2;
this.vel_x = random(0, 1.0) > 0.5 ? -3 : 3;
this.vel_y = random(0, 1.0) > 0.5 ? -3 : 3;
}
public void update_pos() {
this.x += this.vel_x;
this.y += this.vel_y;
if (this.x <0 || this.x > width) {
this.reflect_horizontal();
}
if (this.y < 0 ) {
this.reflect_vertical();
}
}
void reflect_horizontal() {
this.vel_x = -this.vel_x*1.1;
}
public void reflect_vertical() {
this.vel_y = -this.vel_y*1.1;
}
}
final float bar_width = 100;
final float bar_y = 550;
float bar_pos = 0.;
boolean gameover = false;
Ball ball = new Ball();
void setup() {
size(600, 600);
textMode(CENTER);
rectMode(CENTER);
}
void draw() {
ball.update_pos();
if (ball.y>height) {
gameover = true;
}
if (gameover) {
textSize(24);
text("game over", width/2, height/2);
} else {
bar_pos = mouseX;
if (ball.y > bar_y &&
ball.x > bar_pos - bar_width/2 &&
ball.x < bar_pos + bar_width/2) {
ball.reflect_vertical();
}
background(255);
fill(0);
rect(bar_pos, bar_y, bar_width, 30);
ellipse(ball.x, ball.y, 10, 10);
}
}
void mousePressed() {
if (gameover) {
gameover =false;
ball = new Ball();
}
}
```
### minimal_pong_firmata.pde
{{< button href="examples/minimal_pong_firmata/minimal_pong_firmata.pde">}}DL{{< /button >}}
```java
import processing.serial.*;
import cc.arduino.*;
import org.firmata.*;
class Ball {
float x;
float y;
float vel_x;
float vel_y;
Ball() {
this.x = width/2;
this.y = height/2;
this.vel_x = random(0, 1.0)> 0.5 ? -5:5;
this.vel_y = random(0, 1.0)> 0.5 ? -5:5;
}
public void update_pos() {
this.x += this.vel_x;
this.y += this.vel_y;
if (this.x <0 || this.x > width) {
this.reflect_horizontal();
}
if (this.y < 0 ) {
this.reflect_vertical();
}
}
void reflect_horizontal() {
this.vel_x = -this.vel_x*1.1;
}
public void reflect_vertical() {
this.vel_y = -this.vel_y*1.1;
}
}
final float bar_width = 100;
final float bar_y = 550;
float bar_pos = 0.;
boolean gameover = false;
Ball ball = new Ball();
Arduino arduino;
void setup() {
size(600, 600);
rectMode(CENTER);
textAlign(CENTER);
println(Arduino.list());
//リストアップされたもののうち、"tty.usbmodem"を含む番号を選択(not cu.usbmodem)
arduino = new Arduino(this, Arduino.list()[5], 57600);
arduino.pinMode(2,Arduino.INPUT);
}
void draw() {
bar_pos = map(arduino.analogRead(0), 0., 1024., 0., width);
if (arduino.digitalRead(2) == Arduino.HIGH){
buttonPressed();
}
ball.update_pos();
if (ball.y>height) {
gameover = true;
}
if (gameover) {
textSize(24);
text("game over", width/2, height/2);
} else {
if (ball.y > bar_y &&
ball.x > bar_pos - bar_width/2 &&
ball.x < bar_pos + bar_width/2) {
ball.reflect_vertical();
}
background(255);
fill(0);
rect(bar_pos, bar_y, bar_width, 30);
ellipse(ball.x, ball.y, 10, 10);
}
}
void buttonPressed() {
if (gameover) {
gameover = false;
ball = new Ball();
}
}
```

View File

@ -0,0 +1,68 @@
class Ball {
float x;
float y;
float vel_x;
float vel_y;
Ball() {
this.x = width/2;
this.y = height/2;
this.vel_x = random(0, 1.0) > 0.5 ? -3 : 3;
this.vel_y = random(0, 1.0) > 0.5 ? -3 : 3;
}
public void update_pos() {
this.x += this.vel_x;
this.y += this.vel_y;
if (this.x <0 || this.x > width) {
this.reflect_horizontal();
}
if (this.y < 0 ) {
this.reflect_vertical();
}
}
void reflect_horizontal() {
this.vel_x = -this.vel_x*1.1;
}
public void reflect_vertical() {
this.vel_y = -this.vel_y*1.1;
}
}
final float bar_width = 100;
final float bar_y = 550;
float bar_pos = 0.;
boolean gameover = false;
Ball ball = new Ball();
void setup() {
size(600, 600);
textMode(CENTER);
rectMode(CENTER);
}
void draw() {
ball.update_pos();
if (ball.y>height) {
gameover = true;
}
if (gameover) {
textSize(24);
text("game over", width/2, height/2);
} else {
bar_pos = mouseX;
if (ball.y > bar_y &&
ball.x > bar_pos - bar_width/2 &&
ball.x < bar_pos + bar_width/2) {
ball.reflect_vertical();
}
background(255);
fill(0);
rect(bar_pos, bar_y, bar_width, 30);
ellipse(ball.x, ball.y, 10, 10);
}
}
void mousePressed() {
if (gameover) {
gameover =false;
ball = new Ball();
}
}

View File

@ -0,0 +1,81 @@
import processing.serial.*;
import cc.arduino.*;
import org.firmata.*;
class Ball {
float x;
float y;
float vel_x;
float vel_y;
Ball() {
this.x = width/2;
this.y = height/2;
this.vel_x = random(0, 1.0)> 0.5 ? -5:5;
this.vel_y = random(0, 1.0)> 0.5 ? -5:5;
}
public void update_pos() {
this.x += this.vel_x;
this.y += this.vel_y;
if (this.x <0 || this.x > width) {
this.reflect_horizontal();
}
if (this.y < 0 ) {
this.reflect_vertical();
}
}
void reflect_horizontal() {
this.vel_x = -this.vel_x*1.1;
}
public void reflect_vertical() {
this.vel_y = -this.vel_y*1.1;
}
}
final float bar_width = 100;
final float bar_y = 550;
float bar_pos = 0.;
boolean gameover = false;
Ball ball = new Ball();
Arduino arduino;
void setup() {
size(600, 600);
rectMode(CENTER);
textAlign(CENTER);
println(Arduino.list());
//リストアップされたもののうち、"tty.usbmodem"を含む番号を選択(not cu.usbmodem)
arduino = new Arduino(this, Arduino.list()[5], 57600);
arduino.pinMode(2,Arduino.INPUT);
}
void draw() {
bar_pos = map(arduino.analogRead(0), 0., 1024., 0., width);
if (arduino.digitalRead(2) == Arduino.HIGH){
buttonPressed();
}
ball.update_pos();
if (ball.y>height) {
gameover = true;
}
if (gameover) {
textSize(24);
text("game over", width/2, height/2);
} else {
if (ball.y > bar_y &&
ball.x > bar_pos - bar_width/2 &&
ball.x < bar_pos + bar_width/2) {
ball.reflect_vertical();
}
background(255);
fill(0);
rect(bar_pos, bar_y, bar_width, 30);
ellipse(ball.x, ball.y, 10, 10);
}
}
void buttonPressed() {
if (gameover) {
gameover = false;
ball = new Ball();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 748 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 852 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 441 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 465 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 KiB

Some files were not shown because too many files have changed in this diff Show More