Hello everyone,
I am new to programming and I really want to get into it. Lately, I have been inspired by Allen Pan and his project on hackster.io to make the firebending gloves so that I could have a pair of my own. But, I have been having issues trying to figure out how to program the LIS3DH and the Pro-mini with an Uno. I have looked everywhere online to figure it out but I still do not completely understand it. I have been able to program the example blink function on the Pro-mini with the Uno but I have not been able to figure out how to implement the code that Allen Pan wrote with the LIS3DH and the Pro-mini. Whenever I try and compile the data, it always pops up in an error. I have tried working different ways with the code but all attempts have failed and I have no clue where to go from there. With the code, I keep getting an error that will not let me compile the data. I have downloaded the LIS3DH Adafruit Library folder. I will be getting a FTDI chip soon so if that would be better to program with. Also, I still am a little confused on where to connect the LIS3DH pins to the Pro-mini when I am trying to download the data. If anyone can please help me figure these issues out it would be much appreciated!
Thanks.
Error message that pops up:
Arduino: 1.8.9 (Mac OS X), Board: "Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)"
In file included from /var/folders/mj/k24pm_yj0x79_t67ygnhm66w0000gp/T/arduino_modified_sketch_45932/acceldemo.ino:5:0:
/Users/boys/Documents/Arduino/libraries/Adafruit_LIS3DH/Adafruit_LIS3DH.h:30:29: fatal error: Adafruit_Sensor.h: No such file or directory
compilation terminated.
exit status 1
Error compiling for board Arduino Pro or Pro Mini.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Code that I am using:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
// Used for software SPI
#define LIS3DH_CLK 13
#define LIS3DH_MISO 12
#define LIS3DH_MOSI 11
// Used for hardware & software SPI
#define LIS3DH_CS 10
//software SPI
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
//A fist experiences significant acceleration during a good punch,
//followed by massive deceleration at the end of the punch.
//This happens within a fairly small window of time, so it's
//pretty easy to distinguish a punch from normal gesticulations.
unsigned long punchStart = 0;//variable for non-blocking punch timeframe check
const long punchInterval = 200;//timeframe of a punch in ms, from max acceleration to max deceleration, 200 is very generous
int punchAccel = 20;//the beginning of a punch in m/s^2, could be over 50m/s^2 depending on the puncher
int punchDecel = -40;//the end of a punch in m/s^2, could be less than -100m/s^2 depending on the puncher
int flameTime = 250;//how long the flame lasts, in ms
void setup(void) {
//Test to see if accelerometer is communicating
Serial.begin(9600);
Serial.println("LIS3DH test!");
if (! lis.begin(0x18)) { // change this to 0x19 for alternative i2c address
Serial.println("Couldnt start");
while (1);
}
Serial.println("LIS3DH found!");
lis.setRange(LIS3DH_RANGE_16_G); //+-16G range for good punch detection
Serial.print("Range = "); Serial.print(2 << lis.getRange());
Serial.println("G");
pinMode(8, OUTPUT); //Solenoid valve
pinMode(9, OUTPUT); //Arc lighter
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
lis.read();
sensors_event_t event;
lis.getEvent(&event);
//look for punch starting, at least 20 m/s^2
if (event.acceleration.x > punchAccel){
Serial.println(event.acceleration.x);
punchStart = millis();
}
unsigned long currentMillis = millis();
//look for punch ending, less than -40 m/s^2
if (event.acceleration.x < punchDecel && currentMillis - punchStart < punchInterval){
Serial.println(event.acceleration.x);
Serial.println("Punch");
Fire(flameTime);
}
}
void Fire(int flameTime){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
delay(flameTime);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}