STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
adcdemo.ino
Go to the documentation of this file.
1// Basic demo for tap/doubletap readings from Adafruit LIS3DH
2
3#include <Wire.h>
4#include <SPI.h>
5#include <Adafruit_LIS3DH.h>
6#include <Adafruit_Sensor.h>
7
8// Used for software SPI
9#define LIS3DH_CLK 13
10#define LIS3DH_MISO 12
11#define LIS3DH_MOSI 11
12// Used for hardware & software SPI
13#define LIS3DH_CS 10
14
15// software SPI
16//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
17// hardware SPI
18//Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS);
19// I2C
21
22void setup(void) {
23#ifndef ESP8266
24 while (!Serial) yield(); // will pause Zero, Leonardo, etc until serial console opens
25#endif
26
27 Serial.begin(9600);
28 Serial.println("Adafruit LIS3DH ADC Test!");
29
30 if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
31 Serial.println("Couldnt start");
32 while (1) yield();
33 }
34 Serial.println("LIS3DH found!");
35
36 lis.setRange(LIS3DH_RANGE_2_G); // 2, 4, 8 or 16 G!
37
38 Serial.print("Range = "); Serial.print(2 << lis.getRange());
39 Serial.println("G");
40}
41
42
43void loop() {
44 int16_t adc;
45 uint16_t volt;
46
47 // read the ADCs
48 adc = lis.readADC(1);
49 volt = map(adc, -32512, 32512, 1800, 900);
50 Serial.print("ADC1:\t"); Serial.print(adc);
51 Serial.print(" ("); Serial.print(volt); Serial.print(" mV) ");
52
53 adc = lis.readADC(2);
54 volt = map(adc, -32512, 32512, 1800, 900);
55 Serial.print("ADC2:\t"); Serial.print(adc);
56 Serial.print(" ("); Serial.print(volt); Serial.print(" mV) ");
57
58 adc = lis.readADC(3);
59 volt = map(adc, -32512, 32512, 1800, 900);
60 Serial.print("ADC3:\t"); Serial.print(adc);
61 Serial.print(" ("); Serial.print(volt); Serial.print(" mV)");
62
63 Serial.println();
64 delay(200);
65}
This is a library for the Adafruit LIS3DH Accel breakout board.
@ LIS3DH_RANGE_2_G
static SerialStub Serial
Definition Arduino.h:128
Adafruit_LIS3DH lis
Definition acceldemo.ino:23
void delay(int ms)
void setup(void)
Definition adcdemo.ino:22
void loop()
Definition adcdemo.ino:43
Class that stores state and functions for interacting with Adafruit_LIS3DH.
static STAR_MCP3201 adc(MCP3201_CS_PIN, &mcp_spi)