
keyestudio
www.keyestudio.com
106
Sample Code
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
The circuit:
VCC: 5V
GND: ground
SCL: UNO SLC
SDA: UNO SDA
This example code is in the public domain.
*/
#include <Wire.h>
// Registers for ADXL345
#define ADXL345_ADDRESS (0xA6 >> 1) // address for device is 8 bit but shift to the
// right by 1 bit to make it 7 bit because the
// wire library only takes in 7 bit addresses
#define ADXL345_REGISTER_XLSB (0x32)
int accelerometer_data[3];
// void because this only tells the cip to send data to its output register
// writes data to the slave's buffer
void i2c_write(int address, byte reg, byte data) {
// Send output register address
Wire.beginTransmission(address);
// Connect to device
Wire.write(reg);
// Send data
Wire.write(data); //low byte
Wire.endTransmission();
}
// void because using pointers
// microcontroller reads data from the sensor's input register
void i2c_read(int address, byte reg, int count, byte* data) {
// Used to read the number of data received
int i = 0;
// Send input register address
Wire.beginTransmission(address);
// Connect to device
Wire.write(reg);
Wire.endTransmission();
Summary of Contents for KS0077
Page 1: ...keyestudio www keyestudio com 1 Super Learning Kit for Arduino...
Page 14: ...keyestudio www keyestudio com 14 Connection for UNO R3 Connection for 2560 R3...
Page 32: ...keyestudio www keyestudio com 32 Connection for 2560 R3...
Page 42: ...keyestudio www keyestudio com 42 Connection for MEGA 2560...
Page 45: ...keyestudio www keyestudio com 45 Connection for UNO R3 Connection for 2560 R3...
Page 59: ...keyestudio www keyestudio com 59 Connection for 2560 R3...
Page 66: ...keyestudio www keyestudio com 66 Connection for 2560 R3...
Page 72: ...keyestudio www keyestudio com 72 Manual for LED Segment Display Connection for UNO R3...
Page 85: ...keyestudio www keyestudio com 85 8 bit Connection Method Connection for UNO R3...
Page 94: ...keyestudio www keyestudio com 94 Connection for 2560 R3 Connect the motor to digital pin 9...