[Description]
- Geometric collision (in processing) triggers the DC motor as a haptic feedback.
- Connects the arduino board to a C++ based Racing Game.
- When the vehicle collides with an object, the DC motor vibrates.
[Components]
- DC Motor X 1
- 1.5V AA Battery X 2
- Resistor X 2
- Transistor X 1
[Arduino Code]
int potPin = 2; // select the input pin for the potentiometer
int motorPin = 11; // select the pin for the Motor
int val = 0; // variable for the output value to the game (not used herein)
int m_val = 0; // variable for the input value from the game
void setup() {
Serial.begin(9600);
}
void loop() {
m_val = Serial.read();
if(m_val < 0 )
m_val = 0;
analogWrite(motorPin, m_val); // analogWrite to the motor can be between 0-255
delay(50);
Serial.println(m_val);
}
[C++ Code (Partial)]
DWORD CCommThread::WriteComm(BYTE *pBuff, DWORD nToWrite) {
DWORD dwWritten, dwError, dwErrorFlags;
COMSTAT comstat;
if (!WriteFile(m_hComm, pBuff, nToWrite, &dwWritten, &m_osWrite)) {
if (GetLastError() == ERROR_IO_PENDING) {
while (!GetOverlappedResult(m_hComm, &m_osWrite, &dwWritten, TRUE)) {
dwError = GetLastError();
if (dwError != ERROR_IO_INCOMPLETE) {
ClearCommError(m_hComm, &dwErrorFlags, &comstat);
break;
}
}
}
else {
dwWritten = 0;
ClearCommError(m_hComm, &dwErrorFlags, &comstat);
}
}
return dwWritten;
}
[Image]
Assign6
Comments
Comments from TAs
Nice job -- this project would be a good foundation for building some games using the Arduino and Processing. I like the idea of using the motor for haptic feedback -- It would be interesting to think about what it could be used for. Could there be "productive uses", such as a mouse that vibrates when it moves over a button? Or might there be more playful uses, such as a motor that vibrates in relation to music?