30 September 2019

Mapping: Your Personal, Portable Therapist

For the mapping assignment, I focused on the questions: "Can we express a mood with a single pixel?" and "How can I incorporate a buzzer into this?"

How could I use the analog controls to express mood, and which controls would correlate with different emotions? Why would these correlations exist?

The thought of where to include a buzzer almost immediately made me think of a therapy session. The therapist (RGB LED) would show an emotional response via color to your actions as a patient (expressed via analog controls). Originally, I wanted to have it so that the buzzer would go off after a short time, ideally cutting the therapy interaction off in a surprising moment to (hopefully humorously) convey the idea that even though you may be making emotional progress and communicating well, it will end at a set time regardless of the actual experience of the session.

Here's a sketch of the idea:



I focused on the assignment requirements, so I wasn't able to spend too much time trying to figure out how to have a timer run in the background to trigger the buzzer while the code for interaction runs without delay. However, I did incorporate the buzzer idea in a different way - if you "cry" too much (measured by the water detection) the session will end.

Here's the schematic and images of the setup:

Schematic
All the things
Wires on a breadboard

I do sometimes have a problem where the sound sensor code is trigger by the water sensor (and not because of the buzzer going off). It seems like the kind of issue that would be resolved with a decoupling capacitor as described in the readings. However, from the PDF paired with the kit, I believe there should be a capacitor in the sound sensor already. I did try adding one but it caused more problems so I took it out.

At the end, this was the result:



Code below:

const int Rpin = 3;
const int Gpin = 5;
const int Bpin = 6;
const int water = A0;
const int tiltx = A1;
const int tilty = A2;
const int sound = A3;
const int stahp = 9;
const int buzzer = 12;
void setup() {
pinMode(Rpin, OUTPUT);
pinMode(Bpin, OUTPUT);
pinMode(Gpin, OUTPUT);
pinMode(stahp, INPUT_PULLUP);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
//you can interact with the therapist only when button is NOT pushed
while (digitalRead(stahp) == HIGH) {
int sVal = analogRead(A3); //ideally this registers when someone is talking, for now it just reads when you make a dramatic or agitated sigh
delay(1);
//if you sigh, your therapist knows to start listening, the colors change to indicate as much
if (sVal >= 45) {
Serial.print("Listening...");
digitalWrite(Rpin, 20);
delay(500);
digitalWrite(Gpin, 20);
delay(500);
digitalWrite(Bpin, 20);
delay(500);
}
//reading the analog inputs
int watVal = analogRead(A0);
delay(1); //helps to do this because arduino only has one ADC chip that it switches between analog pins
int xVal = analogRead(A1);
delay(1);
int yVal = analogRead(A2);
delay(1);
//water == tears
int watmappedVal = map(watVal, 0, 1023, 10, 255); // take this number with this range and convert it to this range
analogWrite(Bpin, watmappedVal);
//but too many tears == end of session
if (watVal >= 220) {
Serial.print("Sorry, that's all the time we have for today...");
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(200);
}
//tracks joystick along x axis, representative of nodding your head 'yes' - turns LED greener
int xmappedVal2 = map(xVal, 0, 499, 255, 40);
analogWrite(Gpin, xmappedVal2);
int xmappedVal = map(xVal, 500, 1023, 40, 255);
analogWrite(Gpin, xmappedVal);
//your therapist is happy when you're really on the same page
if (xVal <= 400 || xVal >= 600) {
Serial.print("I'm glad you agree...");
}
//tracks joystick along y axis, representative of shaking your head 'no' - turns LED redder
int ymappedVal = map(yVal, 518, 1023, 50, 255);
analogWrite(Rpin, ymappedVal);
int ymappedVal2 = map(yVal, 0, 517, 255, 50); //I feel like this could be more efficient but when I tried '+ map(yVal, 0, 517, 255, 50)' but it makes it so neither changes
analogWrite(Rpin, ymappedVal2); //also for some reason adding this seemed to weaken ymappedVal
// if you're too disagreeable, your therapist has something to say about that
if (yVal <= 400 || yVal >= 600) {
Serial.print("It's a shame you don't agree...");
}
// to measure the values and check them against what I want to happen
Serial.print(xVal);
Serial.print("\t");
Serial.print(yVal);
Serial.print("\t");
Serial.print(watVal);
Serial.print("\t");
Serial.println(sVal);
}
// light sequence, end of the session?
digitalWrite(Gpin, HIGH);
digitalWrite(Rpin, LOW);
digitalWrite(Bpin, LOW);
delay(200);
digitalWrite(Gpin, LOW);
digitalWrite(Rpin, LOW);
digitalWrite(Bpin, LOW);
delay(200);
digitalWrite(Bpin, HIGH);
digitalWrite(Rpin, LOW);
digitalWrite(Gpin, LOW);
delay(200);
digitalWrite(Bpin, LOW);
digitalWrite(Rpin, LOW);
digitalWrite(Gpin, LOW);
delay(200);
digitalWrite(Rpin, HIGH);
digitalWrite(Bpin, LOW);
digitalWrite(Gpin, LOW);
delay(200);
digitalWrite(Rpin, LOW);
digitalWrite(Bpin, LOW);
digitalWrite(Gpin, LOW);
delay(200);
}

Yours truly,
Toupee4

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.