Code for lights going while there is acceleration on the shirt. (school project)

Here is the code, I assumed X = if it is accelerating, since that is what the teacher said, so the code is meant to light up while the shirt is accelerating. If not, then it does nothing. It currently will not stop lighting up regardless if the shirt is still or moving. Please help :o

void setup() {
CircuitPlayground.begin();
pinMode(vibeMotor, OUTPUT);
}

void loop() {
X = CircuitPlayground.motionX();

while (X > 4){
digitalWrite(vibeMotor, LOW);

for (int n = 0; n < 3; n++) {
for (int i = 10; i >= 0; i--) {
CircuitPlayground.setPixelColor (i, 255, 255, 255 );
delay (30);
for (int i = 10; i >= 0; i--) {
CircuitPlayground.setPixelColor (i, 0, 0, 0 );
delay (30);
}
}

digitalWrite(vibeMotor, LOW);
CircuitPlayground.setPixelColor (0, 255, 0, 0);
CircuitPlayground.setPixelColor (9, 255, 0, 0);
delay (100);
CircuitPlayground.setPixelColor (1, 255, 0, 0);
CircuitPlayground.setPixelColor (8, 255, 0, 0);
delay (100);
CircuitPlayground.setPixelColor (2, 255, 0, 0);
CircuitPlayground.setPixelColor (7, 255, 0, 0);
delay (100);
CircuitPlayground.setPixelColor (3, 255, 0, 0);
CircuitPlayground.setPixelColor (6, 255, 0, 0);
delay (100);
CircuitPlayground.setPixelColor (4, 255, 0, 0);
CircuitPlayground.setPixelColor (5, 255, 0, 0);
delay (100);

}
break;
}
delay (10);

if (X < 4){
digitalWrite(vibeMotor, HIGH);
}
}

thanks in advance!

X = CircuitPlayground.motionX();

What is the value of X when there is no acceleration and what is the value of X when there is sufficient acceleration? Serial.print the value of X to see. You may need to adjust the threshold.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom.. :slight_smile:

Hi,
Have you checked this link to Adafruit. (who have all these weird names, "Playground"???)

Have you got the 'Playground oriented in the correct direction to detect your X or horizontal" movement?

Tom.... :slight_smile:

First, figure out what constitutes "acceleration".

The sensor will always output about 9.8 m/s2 as that's gravity. You will want to filter that out.

Also "no movement" for a shirt means it's in the closet. When worn by a living person it's moving at all times, and the movement is changing which is an acceleration. Breathing, heartbeats, and other motion from the wearer's body. So you will have to define a minimum range of acceleration before you react to it.

Finally, it's three axis. Gravity is not necessarily exactly in the Z direction, as the person wearing the shirt is not always walking perfectly straight up. They're moving, twisting and turning their body as they go.

Start with this part: the acceleration. Just have it light up an LED or so. When you're happy with the acceleration detection part (this is almost certainly the really hard part) it's time to make it pretty and start flashing LEDs based on the acceleration state.

Hi,
Use your serial port and IDE monitor to check that you are getting valid readings.

Tom.. :slight_smile: