Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Accelerometer input
- * Takes the input from a lilypad accelerometer on analog pins 0=x, 1=y, 2=z
- * Detect the movment of each accelerometer
- */
- int buttonpin = 2;
- // pied droit
- int xpin = 3; // select the input pin for the sensor
- int ypin = 4; // select the input pin for the sensor
- int zpin = 5; // select the input pin for the sensor
- int yval = 0; // variable to store the value coming from the x axis
- int yval_prec = 0;
- int xval = 0; // variable to store the value coming from the x axis
- int xval_prec = 0; // variable to store the value coming from the x axis
- int zval = 0; // variable to store the value coming from the x axis
- int zval_prec = 0;
- int zdir=90; //initial z orientation is "up"
- //pied gauche
- int xpinG = 2;
- int ypinG = 1;
- int zpinG = 0;
- int yvalG = 0; // variable to store the value coming from the x axis
- int yvalG_prec = 0;
- int xvalG = 0; // variable to store the value coming from the x axis
- int xvalG_prec = 0;
- int zvalG = 0; // variable to store the value coming from the x axis
- int zvalG_prec = 0;
- int initialise = 1;
- int delta =20;
- int isolement_mouvement_init = 3;
- int isolement_mouvement = 3;
- int marche=0;
- int normeG=0;
- int norme=0;
- int normeG_init=0;
- int norme_init=0;
- int delai = 0;
- int temps_echantillonage = 80;
- int temps_init = 0;
- int up=390; int down=290; int mid=(up+down)/2;
- void setup() {
- Serial.begin(9600);
- pinMode(buttonpin, INPUT);
- //Serial.print("normeG_init =");Serial.println(normeG_init);
- isolement_mouvement = isolement_mouvement_init;
- }
- void loop() {
- if(marche>=1){
- //Serial.print("marche");
- xval = analogRead(xpin); // read the value from the x axis, 0-1023
- yval = analogRead(ypin); // read the value from the y axis, 0-1023
- zval = analogRead(zpin); // read the value from the z axis, 0-1023
- xvalG = analogRead(xpinG); // read the value from the x axis, 0-1023
- yvalG = analogRead(ypinG); // read the value from the y axis, 0-1023
- zvalG = analogRead(zpinG); // read the value from the z axis, 0-1023
- displayvalues();
- delay(temps_echantillonage); // rest a little...
- if(digitalRead(buttonpin)==0){ // si on appuye sur le bouton -> arret
- marche++;
- if (marche>3){
- Serial.print("stop");
- marche=-1;
- }
- }
- } else if(marche==0){
- if(digitalRead(buttonpin)==0){// si on appuye sur le bouton -> marche
- marche=1;
- initialisationVariables();
- }
- }
- }
- void displayvalues(){
- int zorientation; int yorientation; int xorientation;
- int zorientationG; int yorientationG; int xorientationG;
- isolement_mouvement--;
- //Serial.print(" : x="); Serial.print(xval);
- if (isolement_mouvement <= 0) {
- normeG = sqrt(((xvalG_prec-xvalG)*(xvalG_prec-xvalG))+((yvalG_prec-yvalG)*(yvalG_prec-yvalG))+((zvalG_prec-zvalG)*(zvalG_prec-zvalG)));
- norme = sqrt(((xval_prec-xval)*(xval_prec-xval))+((yval_prec-yval)*(yval_prec-yval))+((zval_prec-zval)*(zval_prec-zval)));
- /*Serial.print("norme :");Serial.println(norme);
- Serial.print("normeG :");Serial.println(normeG);*/
- if(((normeG>(normeG_init+delta)) || (normeG<(normeG_init-delta)))&&(initialise==1)){
- Serial.print(millis()/1000.0);
- /*Serial.print("Deplacement G (");
- Serial.print(normeG);
- Serial.println(")");*/
- Serial.print(",");
- initialise=0;
- } else if(((norme>(norme_init+delta)) || (norme<(norme_init-delta)))&&(initialise==1)){
- Serial.print(millis()/1000.0);
- /*Serial.print("Deplacement (");
- Serial.print(norme);
- Serial.println(")");*/
- Serial.print(",");
- initialise=0;
- } else {//pour eviter de prendre un déplacement pour plusieurs
- initialise = 1;
- }
- isolement_mouvement = isolement_mouvement_init;
- }
- }
- void initialisationVariables(){
- xval_prec = analogRead(xpin);
- yval_prec = analogRead(ypin);
- zval_prec = analogRead(zpin);
- xvalG_prec = analogRead(xpinG);
- yvalG_prec = analogRead(ypinG);
- zvalG_prec = analogRead(zpinG);
- xval = analogRead(xpin); // read the value from the x axis, 0-1023
- yval = analogRead(ypin); // read the value from the y axis, 0-1023
- zval = analogRead(zpin); // read the value from the z axis, 0-1023
- xvalG = analogRead(xpinG); // read the value from the x axis, 0-1023
- yvalG = analogRead(ypinG); // read the value from the y axis, 0-1023
- zvalG = analogRead(zpinG); // read the value from the z axis, 0-1023
- normeG_init = sqrt(((xvalG_prec-xvalG)*(xvalG_prec-xvalG))+((yvalG_prec-yvalG)*(yvalG_prec-yvalG))+((zvalG_prec-zvalG)*(zvalG_prec-zvalG)));
- norme_init = sqrt(((xval_prec-xval)*(xval_prec-xval))+((yval_prec-yval)*(yval_prec-yval))+((zval_prec-zval)*(zval_prec-zval)));
- Serial.print("[");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement