Making Things Interactive

March 20, 2008

assignment 8: Personal Medication Tracker

Filed under: 8: State Machine,Assignments,Gee Kim — gskim @ 3:15 am

The state machine here shows how my Personal Medication Tracker works. This device is a tool that helps keep track of medication intake. So it begins by waiting for a patient. Once a patient stands on a mat (with a button sensor beneath it), the device recognizes that a patient is standing there, and prints onto the screen “Personal Medication Tracker, Name:, and Date:” Then it begins by asking a yes or no question on the screen, the answer would print onto the screen following the question. Then there is a delay until it is time to take the next medication. Then the next question is asked, and the answer in printed. Another delay until it is time to take the last medication. Then the last question is asked, and the answer is printed.

This information can be printed for the patient’s reference. There is also space for the patient to fill out their name and date.

(To refresh the device for the next day, simply press the refresh button on the arduino.)

medication-tracker-diagram.jpg


int switch1 = 5;  // patient sensor
int switch2 = 3;  // "yes" button
int switch3 = 6;  // "no" button
int led1 = 2;     // morning pill 1
int led2 = 1;     // morning pill 2
int led3 = 4;     // afternoon pill 1
int led4 = 7;     // dinner pill 1
int led5 = 8;     // dinner pill 2

void setup ()
{
  pinMode (switch1, INPUT);
  pinMode (switch2, INPUT);
  pinMode (switch3, INPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  pinMode (led5, OUTPUT);
  Serial.begin (9600);
}

void loop ()
{
  if (digitalRead(switch1==HIGH)){
    {
      Serial.println ("Personal Medication Tracker");
      Serial.println ("Name:");
      Serial.println ("Date:");
      Serial.println ("");
      Serial.println ("Did you take your morning pills?");
      YESorNOmorning ();
      Serial.println ("Did you take your afternoon pills?");
      YESorNOafternoon ();
      Serial.println ("Did you take your night pills?");
      YESorNOnight ();
    }
  }
}

void YESorNOmorning ()
{
  delay (5000);
  if (digitalRead(switch2==HIGH))
  {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    Serial.println ("YES");
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))
   {
     digitalWrite(led1,LOW);
     digitalWrite(led2,LOW);
     Serial.println ("NO");
     Serial.println ("");
    }
     delay(5000);
}

void YESorNOafternoon ()
{
  delay (1000);
  if (digitalRead(switch2==HIGH))
  {
    digitalWrite(led3,HIGH);
    Serial.println ("YES");
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))
   {
     digitalWrite(led3,LOW);
     Serial.println ("NO");
     Serial.println ("");
    }
     delay(5000);
}

void YESorNOnight ()
{
  delay (1000);
  if (digitalRead(switch2==HIGH))
  {
    digitalWrite(led4,HIGH);
    digitalWrite(led5,HIGH);
    Serial.println ("YES");
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))
   {
     digitalWrite(led4,LOW);
     digitalWrite(led5,LOW);
     Serial.println ("NO");
     Serial.println ("");
   }
   delay(5000);
}


revised code


int switch1 = 5;  // patient sensor
int switch2 = 3;  // "yes" button
int switch3 = 6;  // "no" button
int led1 = 2;     // morning pill 1
int led2 = 1;     // morning pill 2
int led3 = 4;     // afternoon pill 1
int led4 = 7;     // dinner pill 1
int led5 = 8;     // dinner pill 2

void setup ()
{
  pinMode (switch1, INPUT);
  pinMode (switch2, INPUT);
  pinMode (switch3, INPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  pinMode (led5, OUTPUT);
  Serial.begin (9600);
}

void loop ()
{
  if (digitalRead(switch1==HIGH)){  // start machine at 8:00 am
    {                               //
      Serial.println ("Personal Medication Tracker");
      Serial.println ("Name:");     //
      Serial.println ("Date:");     //
      Serial.println ("");          //
      Serial.println ("Did you take your morning pills?");
      YESorNOmorning ();            //
      delay (14400000);             // 12:00pm
      Serial.println ("Did you take your afternoon pills?");
      YESorNOafternoon ();          //
      delay (21600000);             // 6:00pm
      Serial.println ("Did you take your night pills?");
      YESorNOnight ();              //
      delay (50400000);             // 8:00am

    }
  }
}

void YESorNOmorning ()              // when it's morning
{
  delay (5000);                     // delay 5 seconds
  if (digitalRead(switch2==HIGH))   // when "yes" button is pressed
  {
    digitalWrite(led1,HIGH);        // morning medicine 1 taken, led goes on
    digitalWrite(led2,HIGH);        // morning medicine 2 taken, led goes on
    Serial.println ("YES");         // print "yes"
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH))  // when "no" button is pressed
   {
     digitalWrite(led1,LOW);        // morning medicine 1 not taken, led stays off
     digitalWrite(led2,LOW);        // morning medicine 2 not taken, led stays off
     Serial.println ("NO");         // print "no"
     Serial.println ("");
    }
     delay(5000);                   // delay 5 seconds
}

void YESorNOafternoon ()           // when it's afternoon
{
  delay (5000);                    // delay 5 seconds
  if (digitalRead(switch2==HIGH))  // when "yes" button is pressed
  {
    digitalWrite(led3,HIGH);       // morning afternoon medicine 1 taken, led goes on
    Serial.println ("YES");        // print "yes"
    Serial.println ("");
   }
  if (digitalRead(switch3==HIGH))  // when "no" button is pressed
   {
     digitalWrite(led3,LOW);       // afternoon medicine 1 not taken, led stays off
     Serial.println ("NO");        // print "no"
     Serial.println ("");
    }
     delay(5000);                  // delay 5 seconds
}

void YESorNOnight ()               // when night
{
  delay (1000);
  if (digitalRead(switch2==HIGH))  // when "yes" button is pressed
  {
    digitalWrite(led4,HIGH);       // night medicine 1 taken, led goes on
    digitalWrite(led5,HIGH);       // night medicine 2 taken, led goes on
    Serial.println ("YES");        // print "yes"
    Serial.println ("");
   }
   if (digitalRead(switch3==HIGH)) // when "no" button is pressed
   {
     digitalWrite(led4,LOW);       // night medicine 1 not taken, led stays off
     digitalWrite(led5,LOW);       // night medicine 2 not taken, led stays off
     Serial.println ("NO");        // print "no"
     Serial.println ("");
   }
   delay(5000);                    // delay 5 seconds
}
//
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: