116ms- Board cảm biến độ nghiêng ADXL345
22,000₫
ĐẶT HÀNG NHANH
Giao hàng tận nơi miễn phí nội thành!Đặt hàng nhanh
Giao hàng tân nơi, miễn phí giao hàng toàn quốc

Bạn vui lòng nhập đúng thông tin đặt hàng gồm: Họ tên, SĐT, Email, Địa chỉ để chúng tôi được phục vụ bạn tốt nhất !
- Mô tả
- Đánh giá (0)
Mô tả
Thư viện: 116ms- Board cảm biến độ nghiêng ADXL345 Library
Code mẫu:
// Watch video here: https://www.youtube.com/watch?v=U0hJBc1Ppv4 /* Arduino Accelerometer ADXL345 Arduino Servo No. 1 Arduino Servo No. 2 #include <Wire.h> #include <Servo.h> Servo servo1; // create servo object to control a servo ADXL345 adxl; //variable adxl is an instance of the ADXL345 library int x, y, z; void setup() { void loop() { rawX = x – 7; if (rawX < -255) rawX = -255; else if (rawX > 255) rawX = 255; mappedRawX = map(rawX, -255, 255, 0, 180); servo1.write(mappedRawX); Serial.print(” mappedRawX = “); Serial.print(mappedRawX); // raw data with offset
Accelerometer connection pins (I2C) to Arduino are shown below:
A5 SCL
A4 SDA
3.3V CS
3.3V VCC
GND GND
5V 5V (Red Wire)
GND GND (Black Wire)
D5 (last wire for control – might be white color)
5V 5V (Red Wire)
GND GND (Black Wire)
D6 (last wire for control – might be white color)
*/
#include <ADXL345.h>
Servo servo2;
int rawX, rawY, rawZ;
int mappedRawX, mappedRawY;
Serial.begin(9600);
adxl.powerOn();
servo1.attach(5);
servo2.attach(6);
}
adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables x,y,z
rawY = y – 6;
rawZ = z + 10;
if (rawY < -255) rawY = -255; else if (rawY > 255) rawY = 255;
mappedRawY = map(rawY, -255, 255, 0, 180);
delay(15);
servo2.write(180 – mappedRawY);
delay(15);
Serial.print(” mappedRawY = “); Serial.println(mappedRawY); // raw data with offset
}
Video chi tiết:
Đánh giá
Chưa có đánh giá nào.