Browse code

Variablen sind jetzt Integer und Lage des Sensorr wird geloggt

dewomser authored on26/03/2020 08:59:09
Showing1 changed files

1 1
deleted file mode 100644
... ...
@@ -1,230 +0,0 @@
1
-/******************************************************************************
2
-MMA8452Q_Basic.ino
3
-SFE_MMA8452Q Library Basic Example Sketch
4
-Jim Lindblom @ SparkFun Electronics
5
-Original Creation Date: June 3, 2014
6
-https://github.com/sparkfun/MMA8452_Accelerometer
7
-
8
-This sketch uses the SFE_MMA8452Q library to initialize the
9
-accelerometer, and stream values from it.
10
-
11
-Hardware hookup:
12
-  Arduino --------------- MMA8452Q Breakout
13
-    3.3V  ---------------     3.3V
14
-    GND   ---------------     GND
15
-  SDA (A4) --\/330 Ohm\/--    SDA
16
-  SCL (A5) --\/330 Ohm\/--    SCL
17
-
18
-The MMA8452Q is a 3.3V max sensor, so you'll need to do some 
19
-level-shifting between the Arduino and the breakout. Series
20
-resistors on the SDA and SCL lines should do the trick.
21
-
22
-Development environment specifics:
23
-  IDE: Arduino 1.0.5
24
-  Hardware Platform: Arduino Uno
25
-
26
-This code is beerware; if you see me (or any other SparkFun employee) at the
27
-local, and you've found our code helpful, please buy us a round!
28
-
29
-Distributed as-is; no warranty is given.
30
-******************************************************************************/
31
-#include <Wire.h> // Must include Wire library for I2C
32
-#include <SFE_MMA8452Q.h> // Includes the SFE_MMA8452Q library
33
-
34
-// Begin using the library by creating an instance of the MMA8452Q
35
-//  class. We'll call it "accel". That's what we'll reference from
36
-//  here on out.
37
-MMA8452Q accel;
38
-
39
-
40
-const int buttonPin = 12;
41
-const int ledPin =  13;
42
-int buttonState = 0;
43
-float xyz[360];
44
-int cycle = 0;
45
-int cycle1 = 0;
46
-int messungen = 360;
47
-
48
-
49
-// The setup function simply starts serial and initializes the
50
-//  accelerometer.
51
-void setup()
52
-{
53
-  Serial.begin(9600);
54
-  Serial.println("MMA8452Q Test Code!");
55
-  
56
-  // Choose your adventure! There are a few options when it comes
57
-  // to initializing the MMA8452Q:
58
-  //  1. Default init. This will set the accelerometer up
59
-  //     with a full-scale range of +/-2g, and an output data rate
60
-  //     of 800 Hz (fastest).
61
-  //accel.init();
62
-  //  2. Initialize with FULL-SCALE setting. You can set the scale
63
-  //     using either SCALE_2G, SCALE_4G, or SCALE_8G as the value.
64
-  //     That'll set the scale to +/-2g, 4g, or 8g respectively.
65
-  //accel.init(SCALE_4G); // Uncomment this out if you'd like
66
-  //  3. Initialize with FULL-SCALE and DATA RATE setting. If you
67
-  //     want control over how fast your accelerometer produces
68
-  //     data use one of the following options in the second param:
69
-  //     ODR_800, ODR_400, ODR_200, ODR_100, ODR_50, ODR_12,
70
-  //     ODR_6, or ODR_1. 
71
-  //     Sets to 800, 400, 200, 100, 50, 12.5, 6.25, or 1.56 Hz.
72
-  accel.init(SCALE_8G, ODR_12);
73
-}
74
-
75
-// The loop function will simply check for new data from the
76
-//  accelerometer and print it out if it's available.
77
-void loop()
78
-{
79
-
80
-
81
-buttonState = digitalRead(buttonPin);
82
-  if (buttonState == HIGH) {
83
-    digitalWrite(ledPin, HIGH);
84
-
85
-    for (int cycle = 0 ; cycle < messungen; cycle = cycle + 3) {
86
-      delay (250);
87
-      
88
-      //Serial.print (i);
89
-      //Serial.print("\t");
90
-      //Serial.print(cycle);
91
-      //Serial.print("\t");
92
-      Serial.print (xyz[cycle], 3);
93
-      Serial.print("\t");
94
-      Serial.print (xyz[cycle + 1], 3);
95
-      Serial.print("\t");
96
-      Serial.print (xyz[cycle + 2], 3);
97
-      Serial.print("\t");
98
-      Serial.println(); // Print new line every time.
99
-
100
-    }
101
-    Serial.print ("Daten zu Ende");
102
-    // delay(1000);
103
-    // cycle = 0 ;
104
-digitalWrite(ledPin, LOW);
105
-  } else {
106
-    
107
-
108
-
109
-  
110
-  // Use the accel.available() function to wait for new data
111
-  //  from the accelerometer.
112
-  if (accel.available())
113
-  {
114
-    // First, use accel.read() to read the new variables:
115
-    accel.read();
116
-    
117
-    // accel.read() will update two sets of variables. 
118
-    // * int's x, y, and z will store the signed 12-bit values 
119
-    //   read out of the accelerometer.
120
-    // * floats cx, cy, and cz will store the calculated 
121
-    //   acceleration from those 12-bit values. These variables 
122
-    //   are in units of g's.
123
-    // Check the two function declarations below for an example
124
-    // of how to use these variables.
125
-    if (cycle1 < messungen) {
126
-      cycle1 = cycle1 +3;
127
-    printCalculatedAccels();
128
-    }
129
-    //printAccels(); // Uncomment to print digital readings
130
-    
131
-    // The library also supports the portrait/landscape detection
132
-    //  of the MMA8452Q. Check out this function declaration for
133
-    //  an example of how to use that.
134
-    //printOrientation();
135
-    
136
- //   Serial.println(); // Print new line every time.
137
-  }
138
-}
139
-}
140
-
141
-// The function demonstrates how to use the accel.x, accel.y and
142
-//  accel.z variables.
143
-// Before using these variables you must call the accel.read()
144
-//  function!
145
-void printAccels()
146
-{
147
-  Serial.print(accel.x, 3);
148
-  Serial.print("\t");
149
-  Serial.print(accel.y, 3);
150
-  Serial.print("\t");
151
-  Serial.print(accel.z, 3);
152
-  Serial.print("\t");
153
-}
154
-
155
-// This function demonstrates how to use the accel.cx, accel.cy,
156
-//  and accel.cz variables.
157
-// Before using these variables you must call the accel.read()
158
-//  function!
159
-/************************
160
-void printCalculatedAccels()
161
-{ 
162
-  Serial.print(accel.cx, 3);
163
-  Serial.print("\t");
164
-  Serial.print(accel.cy, 3);
165
-  Serial.print("\t");
166
-  Serial.print(accel.cz, 3);
167
-  Serial.print("\t");
168
-}
169
-**************************/
170
-
171
-void printCalculatedAccels()
172
-{
173
-  messungen = 357;
174
-  cycle=cycle + 3;
175
-  delay(250);
176
-    xyz[cycle] = (accel.cx);
177
-    //  Serial.print("\t");
178
-    xyz[cycle + 1] = (accel.cy);
179
-    //  Serial.print("\t");
180
-    xyz[cycle + 2] = (accel.cz);
181
-    // Serial.print("\t");
182
-Serial.print (xyz[cycle], 3);
183
-Serial.print("\t"); 
184
-Serial.print (xyz[cycle + 1], 3);
185
-Serial.print("\t");
186
-Serial.print (xyz[cycle + 2], 3);
187
-// Serial.print("\t");
188
-// Serial.print(cycle);
189
-Serial.print("\n");
190
-
191
-if (cycle > messungen){
192
-  return;
193
-  }
194
-    
195
-    }
196
-
197
-
198
-
199
-
200
-
201
-
202
-// This function demonstrates how to use the accel.readPL()
203
-// function, which reads the portrait/landscape status of the
204
-// sensor.
205
-void printOrientation()
206
-{
207
-  // accel.readPL() will return a byte containing information
208
-  // about the orientation of the sensor. It will be either
209
-  // PORTRAIT_U, PORTRAIT_D, LANDSCAPE_R, LANDSCAPE_L, or
210
-  // LOCKOUT.
211
-  byte pl = accel.readPL();
212
-  switch (pl)
213
-  {
214
-  case PORTRAIT_U:
215
-    Serial.print("Portrait Up");
216
-    break;
217
-  case PORTRAIT_D:
218
-    Serial.print("Portrait Down");
219
-    break;
220
-  case LANDSCAPE_R:
221
-    Serial.print("Landscape Right");
222
-    break;
223
-  case LANDSCAPE_L:
224
-    Serial.print("Landscape Left");
225
-    break;
226
-  case LOCKOUT:
227
-    Serial.print("Flat");
228
-    break;
229
-  }
230
-}