Skip to content

Instantly share code, notes, and snippets.

@jasongao97
Last active November 5, 2020 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongao97/14cf83027f51cd541fc8f0ee988fa4b6 to your computer and use it in GitHub Desktop.
Save jasongao97/14cf83027f51cd541fc8f0ee988fa4b6 to your computer and use it in GitHub Desktop.
Project Balance Ball - Arduino Part
/*
Balance Ball - Hand
Five vibration motor
Arranged from LSM6DS3 example by Riccardo Rizzo
*/
#include <Arduino_LSM6DS3.h>
const int motors[5] = {9, 6, 5, 3, 2};
int vibration[5] = {0, 0, 0, 0, 0};
void setup() {
Serial.begin(9600);
while (!Serial);
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
}
void loop() {
int index = 0;
while (Serial.available() > 0) {
int inByte = Serial.read();
if (inByte == '\n') break;
vibration[index] = inByte;
index++;
}
for (int i = 0; i < 5; i++) {
analogWrite(motors[i], vibration[i]);
}
float x, y, z;
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
Serial.print(x);
Serial.print(',');
Serial.print(-y);
Serial.print(',');
Serial.println(z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment