Outils pour utilisateurs

Outils du site


Electroshock controller

This project aims to improve human motivation in diverse situations, starting with the first-person shooter game OpenArena (based on Quake III).

Status

Status du project
Date de début 2015-04
Status prototype working, permanent hardware being designed
Initiateur Erik Rossen

Description

This project was started as one of the exhibits of PTL's stand at LemanMake 2015.

It is largely inspired by the 2001 Tekken Torture Tournament and the interactive sculptures of Rick Gibson.

Since it's inception, the unrelated IndieGoGo project "The Shock Clock" has started.

Hardware used

  • Arduino Uno
  • Arduino mini-breadboard shield
  • Home-made electroshock bracelets made by cannibalising gag pens

Step by Step

1. Setup Arduino Uno environment

  • Follow the guide for the Arduino Uno

List of resources

Arduino code

 
/*
  Shock Controler
 
Receive damage reports on serial port and activate the shock channel
accordingly.

The commands are of the format "CHANNEL_NUMBER DAMAGE\n" where CHANNEL_NUMBER
is 1, 2, or 3 and DAMAGE is 1 to 100 points.  This is directly proportionals to
a shock duration in milliseconds.

TODO: One day, make shock voltage proportional to damage.

NOTE: It is assumed that the shock controller is attached to a trusted
computer, thus there is little or no input checking.
 
Created 21 June 2015
by Erik Rossen
*/

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete
String chanString = "";
String damageString = "";
String chanString1Time = "";
String chanString2Time = "";
String chanString3Time = "";
int chan1Time, chan2Time, chan3Time;
int chan;
int damage;

// define pins for each channel
int chan1p = 9;
int chan2p = 10;
int chan3p = 11;

void setup() {
  // initialize serial:
  Serial.begin(9600);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
  chan1Time = 0;
  chan2Time = 0;
  chan3Time = 0;
  pinMode(chan1p, OUTPUT);
  digitalWrite(chan1p, LOW);
  pinMode(chan2p, OUTPUT);
  digitalWrite(chan2p, LOW);
  pinMode(chan3p, OUTPUT);
  digitalWrite(chan3p, LOW);
}

void loop() {
  if (stringComplete) {
    //Serial.println(inputString); 
    chanString = inputString.substring(0,1);
    damageString = inputString.substring(2);
    inputString = "";
    stringComplete = false;
    chan = chanString.toInt();
    damage = damageString.toInt();
    //Serial.println("CHANNEL: " + chanString + "  DAMAGE: " + damageString);

    if ( chan == 1 ) {
      chan1Time = min(chan1Time + damage, 100);
    }
    if ( chan == 2 ) {
      chan2Time = min(chan2Time + damage, 100);
    }
    if ( chan == 3 ) {
      chan3Time = min(chan3Time + damage, 100);
    }

  }
  
  if ( chan1Time > 0 ) {
    // chanString1Time = chanString1Time + chan1Time; Serial.println(chanString1Time); chanString1Time = "";
    digitalWrite(chan1p, HIGH);
  } else {
    digitalWrite(chan1p, LOW);
  }
  if ( chan2Time > 0 ) {
    // chanString2Time = chanString2Time + chan2Time; Serial.println(chanString2Time); chanString2Time = "";
    digitalWrite(chan2p, HIGH);
  } else {
    digitalWrite(chan2p, LOW);
  }
  if ( chan3Time > 0 ) {
    // chanString3Time = chanString3Time + chan3Time; Serial.println(chanString3Time); chanString3Time = "";
    digitalWrite(chan3p, HIGH);
  } else {
    digitalWrite(chan3p, LOW);
  }

  delay(10); // 1=1ms loop
  chan1Time = max(chan1Time - 1,0);
  chan2Time = max(chan2Time - 1,0);
  chan3Time = max(chan3Time - 1,0);
}

/*
  SerialEvent occurs whenever a new data comes in the
 hardware serial RX.  This routine is run between each
 time loop() runs, so using delay inside loop can delay
 response.  Multiple bytes of data may be available.
 */
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read(); 
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    } 
  }
}
projects/electronics/electroshock.txt · Dernière modification: 2017/01/12 18:08 par rossen