Hi, I want to know the best way to, make code to run ONE
Arduino, ONE 3 AXIS ACCELERATION SENSOR MMA7660 module, and ONE LED.
What I want the code to do is. I want to put the
3 axis mma7660 module on the clothes dryer in my home.
The 3 axis mma7660 module will work with the Arduino.
The Arduino will read the 3 axis mma7660 module
(shake or not shake).
Arduino would read the state of the 3 axis mma 7660 module from minute to minute. Read state of 3 axis mma 7660 module,
then one minute would go by, then read the state of the
3 axis mma 7660 module, and so on.
If the dryer is running and shaking, the led would be off.
If the dryer isn't running the led would be on.
Is there some easy code that would do this.
#include <Arduino.h>
#include <I2C.h>
#include <MMA7660.h>
MMA7660::MMA7660()
{
I2c.begin();
}
void MMA7660::init(){
//set mode to standy to set sample rate
write(MODE_REG, 0x00);
write(INTSU_REG, 0x00);
write(SR_REG, 0x00); //120 samples and auto-sleep
write(MODE_REG, 0x01); //set mode to active
}
void MMA7660::setPowerMode(int mode){
}
void MMA7660::setSamples(int samples){
}
void MMA7660::enableTap(){
write(MODE_REG, 0x00);
write(INTSU_REG, 0x04); //turn on tap interrupt
write(SR_REG, 0x00);
write(PDET_REG, 0x86); //enable Z-AXIS tap and set threshold to 6 taps
write(PD_REG, 0x14); //set debounce filter to 21 measurements
write(MODE_REG, 0xC1);
//read(TILT_REG);
}
void MMA7660::enableShake(uint8_t axis){
write(MODE_REG, 0x00);
write(INTSU_REG, axis);
write(MODE_REG, 0xC1);
}
uint8_t MMA7660::readTilt(){
return read(TILT_REG);
}
int MMA7660::readAxis(uint8_t axis){
uint8_t data = 0x40;
//check if the alert bit is set, if so re-read
while(data & 0x40){
data = read(axis);
}
//if it's a negative value convert the two's complement
if(data & 0x20){
data += 0xC0; //the register returns a 6 bit number, fix for uint8_t
data = ~data;
data++;
return (int)data * -1;
}
return (int)data;
}
void MMA7660::write(uint8_t REG_ADDRESS, uint8_t DATA){
I2c.write((uint8_t)MMA7660_CTRL_ID,(uint8_t)REG_ADDRESS,(uint8_t)DATA);
}
uint8_t MMA7660::read(uint8_t REG_ADDRESS){
I2c.read((uint8_t)MMA7660_CTRL_ID, (uint8_t)REG_ADDRESS,(uint8_t) 0x01);
return I2c.receive();
}
#ifndef MMA7660_h
#define MMA7660_h
#include <Arduino.h>
#define MMA7660_CTRL_ID 0x4C
#define XOUT_REG 0x00
#define YOUT_REG 0x01
#define ZOUT_REG 0x02
#define TILT_REG 0x03
#define SRST_REG 0x04 //Sampling rate status
#define SPCNT_REG 0x05 //Sleep count
#define INTSU_REG 0x06 //Interrupt setup
#define MODE_REG 0x07
#define SR_REG 0x08 //Auto-wake/sleep and portrait/landscape filter
#define PDET_REG 0x09 //Tap detection
#define PD_REG 0x0A //Tap debounce count
#define X_AXIS 0x00
#define Y_AXIS 0x01
#define Z_AXIS 0x02
#define X_SHAKE 0x80
#define Y_SHAKE 0x40
#define Z_SHAKE 0x20
// library interface description
class MMA7660
{
// user-accessible "public" interface
public:
MMA7660();
void init();
void setPowerMode(int mode);
void setSamples(int samples);
void enableTap();
void enableShake(uint8_t axis);
uint8_t readTilt();
int readAxis(uint8_t axis);
uint8_t read(uint8_t REG_ADDRESS);
private:
void write(uint8_t REG_ADDRESS, uint8_t DATA);
};
#endif
Here is what I am shooting for
http://diy.viktak.com/2012/07/washing-machine-monitor.html?m=1
But with (ONE ARDUINO) (ONE 3 AXIS MM7660 MODULE) (ONE LED).