Showing
1 changed file
with
98 additions
and
0 deletions
README.md
0 → 100644
| 1 | +# haptic README.md | ||
| 2 | + | ||
| 3 | +본 프로젝트는 *새로운 피드백 요소가 추가된 게임 컨트롤러 제작*을 주제로 2021학년도 1학기에 진행되었다. 열 피드백을 주제로, 각각 높은 온도와 낮은 온도를 어떻게 전달해야 할지에 주안점을 둔다. | ||
| 4 | + | ||
| 5 | +## Environment | ||
| 6 | + | ||
| 7 | +--- | ||
| 8 | + | ||
| 9 | +`Unity 2019.4.18f1` | ||
| 10 | + | ||
| 11 | +`Arduino 1.8.15 (Windows)` | ||
| 12 | + | ||
| 13 | +## Directory | ||
| 14 | + | ||
| 15 | +--- | ||
| 16 | + | ||
| 17 | +`code` Arduino code를 포함한다. | ||
| 18 | + | ||
| 19 | +`PADMOTOR.ino` 실제 기기를 구동시키는 코드 | ||
| 20 | + | ||
| 21 | +`reports` 면담보고서, 기초조사서 등을 포함한다. | ||
| 22 | + | ||
| 23 | +`test` 테스트를 위한 Unity 파일을 포함한다. | ||
| 24 | + | ||
| 25 | +## Code | ||
| 26 | + | ||
| 27 | +--- | ||
| 28 | + | ||
| 29 | +### PADMOTOR.ino | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +int Mosfet1 = 7 ; // 펠티어 연결 모스펫 7번포트 | ||
| 33 | +int Mosfet2 = 6 ; // 모터 연결 모스펫 6번포트 | ||
| 34 | +char data; // 데이터 입력 종류 | ||
| 35 | + | ||
| 36 | +void setup() | ||
| 37 | +{ | ||
| 38 | + Serial.begin(9600); | ||
| 39 | + pinMode(Mosfet1, OUTPUT); | ||
| 40 | + pinMode(Mosfet2, OUTPUT); | ||
| 41 | +} | ||
| 42 | +``` | ||
| 43 | + | ||
| 44 | +연결 포트를 선언한다. Mosfet1은 펠티어에, Mosfet2는 모터로 연결되었다. | ||
| 45 | + | ||
| 46 | +```c | ||
| 47 | +void loop() | ||
| 48 | +{ | ||
| 49 | + if(Serial.available()>0) // 입력된 데이터가 있다면 | ||
| 50 | + { | ||
| 51 | + data = Serial.read(); // 데이터에 입력값 넣기 | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + if(data == 'f') // f를 입력했을 경우 펠티어 모스펫 on | ||
| 55 | + { | ||
| 56 | + digitalWrite(Mosfet1,HIGH); | ||
| 57 | + } | ||
| 58 | + else if(data == 'd') // d를 입력했을 경우 펠티어 모스펫 off | ||
| 59 | + { | ||
| 60 | + digitalWrite(Mosfet1,LOW); | ||
| 61 | + } | ||
| 62 | + else if(data == 's') // s를 입력했을 경우 모터 on | ||
| 63 | + { | ||
| 64 | + digitalWrite(Mosfet2,HIGH); | ||
| 65 | + } | ||
| 66 | + else if(data == 'a') // a를 입력했을 경우 모터 off | ||
| 67 | + { | ||
| 68 | + digitalWrite(Mosfet2,LOW); | ||
| 69 | + } | ||
| 70 | +} | ||
| 71 | +``` | ||
| 72 | + | ||
| 73 | +각각 `f`, `d`, `s`, `a`의 값을 받아 ON/OFF를 처리하도록 했다. | ||
| 74 | + | ||
| 75 | +### SerialHandler.cs | ||
| 76 | + | ||
| 77 | +```csharp | ||
| 78 | +public string portName = "COM1"; | ||
| 79 | +public int baudRate = 9600; | ||
| 80 | +``` | ||
| 81 | + | ||
| 82 | +아두이노와 Unity 사이는 유선으로 연결해, 시리얼 통신으로 진행했다. | ||
| 83 | + | ||
| 84 | +### Player.cs | ||
| 85 | + | ||
| 86 | +Unity 내에서 Player의 움직임에 따라 아두이노로 데이터를 보내는 부분이다. | ||
| 87 | + | ||
| 88 | +```csharp | ||
| 89 | +private void OnTriggerEnter(Collider other) { | ||
| 90 | + if (other.name == "ColdSphere") serialHandler.Write("s"); | ||
| 91 | + else if (other.name == "HotSphere") serialHandler.Write("f"); | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +private void OnTriggerExit(Collider other) { | ||
| 95 | + if (other.name == "ColdSphere") serialHandler.Write("a"); | ||
| 96 | + else if (other.name == "HotSphere") serialHandler.Write("d"); | ||
| 97 | +} | ||
| 98 | +``` | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment