Skip to content

Instantly share code, notes, and snippets.

@anoken
Last active November 30, 2021 02:04
Show Gist options
  • Save anoken/0a38985ef961385141395ea251a9693a to your computer and use it in GitHub Desktop.
Save anoken/0a38985ef961385141395ea251a9693a to your computer and use it in GitHub Desktop.
wio_terminal_test_code
#include"LIS3DHTR.h"
LIS3DHTR<TwoWire> lis(I2C_MODE);
void setup() {
Serial.begin(115200);
lis.begin(Wire1, LIS3DHTR_DEFAULT_ADDRESS); //I2C Address
if (!lis) {
Serial.println("ERROR");
while (1);
}
lis.setOutputDataRate(LIS3DHTR_DATARATE_50HZ); //Data output rate
lis.setFullScaleRange(LIS3DHTR_RANGE_2G); //Scale range set to 2g
}
void loop() {
if (!lis) {
Serial.println("LIS3DHTR didn't connect.");
while (1);
return;
}
//3 axis
Serial.print("x:"); Serial.print(lis.getAccelerationX()); Serial.print(" ");
Serial.print("y:"); Serial.print(lis.getAccelerationY()); Serial.print(" ");
Serial.print("z:"); Serial.println(lis.getAccelerationZ());
delay(50);
}
float mic_ave = 0.0;
float mic_dX = 0.0;
float mic_dX_abs_ave = 0.0;
void setup() {
Serial.begin(115200);
pinMode(WIO_MIC, INPUT);
}
void loop() {
float mic_new = analogRead(WIO_MIC);
mic_ave = 0.9 * mic_ave + 0.1 * mic_new;
mic_dX = mic_new - mic_ave;
mic_dX_abs_ave = 0.5*mic_dX_abs_ave+0.5*abs(mic_dX);
Serial.print(mic_dX); Serial.print(" ");
Serial.print(mic_dX_abs_ave); Serial.print(" ");
Serial.println("");
delay(5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment