Last active
November 5, 2020 12:31
-
-
Save jasongao97/14cf83027f51cd541fc8f0ee988fa4b6 to your computer and use it in GitHub Desktop.
Project Balance Ball - Arduino Part
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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