CPR Trainer
By: Joe & Dan
January 6th 2010
We had decided to come up with a CPR training dummy that would show the user if they are doing the chest compressions the right way. This could be done by using the Nunchuck from a Wii gaming system and an arduino board. The nunchuck is placed on the inside of the dummy and connected to the arduino through analog pins 5,4,3, and 2 as Inputs via an adapter found Here.
The Library was found on the same website
The code that we are currently using is:
#include <Wire.h>
#include "nunchuck_funcs.h"
int an[] = {11,12,13,11,12,13,10,13,10,12,10,11,10,9,9,11,12,9,8,11,8,10,8,9,8,7,9,7,10,7,7,11,12,7,13,7};
int ca[] = {12,11,11,13,13,12,13,10,12,10,11,10,9,10,11,9,9,12,11,8,10,8,9,8,7,8,7,9,7,10,11,7,7,12,7,13};
int loop_cnt=0;
int t = 2500;
byte accx,accy,zbut,cbut;
int ledPin = 13;
int x=0;
void setup()
{
for (int pin =7; pin<=13; pin++)
{
pinMode(pin,INPUT); // Set as input
}
Serial.begin(19200);
nunchuck_setpowerpins();
nunchuck_init(); // send the initilization handshake
Serial.print("WiiChuckDemo ready\n");
}
void loop()
{
if( loop_cnt > 100 ) { // every 100 msecs get new data
loop_cnt = 0;
nunchuck_get_data();
accx = nunchuck_accelx(); // ranges from approx 70 - 182
accy = nunchuck_accely(); // ranges from approx 65 - 173
zbut = nunchuck_zbutton(); // show data everytime the Z button is pressed
cbut = nunchuck_cbutton(); // show data everytime the C button is pressed
x = nunchuck_accelx(); // sets variable x = nunchuck_accelx
x= map(x,0,255,0,35); // sets variable x = map(x,0,255,0,35)
delayMicroseconds(t); // sets delay to variable (t)
pinMode (an[x], OUTPUT); // declares an[x] as an OUTPUT
pinMode (ca[x], OUTPUT); // declares ca[x] as an OUTPUT
digitalWrite(an[x], HIGH); // set an[x] to HIGH
digitalWrite(ca[x], LOW); // set ca[x] to LOW
delayMicroseconds(t); // sets delay to variable (t)
digitalWrite(an[x], LOW); // sets an[x] to LOW
digitalWrite(ca[x], LOW); // sets an[x] to LOW
delayMicroseconds(t); // shows variable (t) for delay
pinMode (an[x], INPUT); // sets an[x] as an INPUT
pinMode (ca[x], INPUT); // sets ca[x] as an INPUT
Serial.print("accx: "); Serial.print((byte)accx,DEC);
Serial.print("\taccy: "); Serial.print((byte)accy,DEC);
Serial.print("\tzbut: "); Serial.print((byte)zbut,DEC);
Serial.print("\tcbut: "); Serial.println((byte)cbut,DEC);
}
loop_cnt++;
delay(1);
}
Conversions for the serial monitor:
+1g = 180
-1g = 72
0g = 128
-2g = 0
+2g = 255
This is a calculation of the amount of G's that are being experienced.
So when it's not moving, the normal force = the force of gravity which is 0g (not moving).
y = 63.75x + 128
January 7th 2010 - Jan 07, 2010 5:24:25 PM
January 13, 2010 - Jan 13, 2010 5:8:48 PM
January 14, 2010 - Jan 14, 2010 5:49:48 PM