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
#include <Adafruit_CircuitPlayground.h> | |
//Declare Pins | |
int analogPin= 11; | |
int analogValue; | |
// For final output | |
int beakPressure; | |
// Variables for Y | |
float prevY; | |
float currentY; | |
float accelerationY; | |
float tiltY; | |
//Variables for X | |
float prevX; | |
float currentX; | |
float accelerationX; | |
float tiltX; | |
void setup() { | |
Serial.begin(9600); | |
CircuitPlayground.begin(); | |
} | |
void loop() { | |
prevY=currentY; // get the value of Y from previous Loop | |
currentY=CircuitPlayground.motionY(); //set current Y to a new Y value from tha accelerometer | |
accelerationY= (currentY-prevY); //get the acceleration | |
prevX=currentX; //get the value ofX from previous Loop | |
currentX=CircuitPlayground.motionX(); //set current X to a new X value from tha accelerometer | |
accelerationX= (currentX-prevX);// get the acceleration | |
analogValue = analogRead(analogPin);// declare Pressure sensor | |
beakPressure= analogValue+ 100; | |
// make sure the value for the intervals is always a positive value | |
tiltY=abs((accelerationY*30)-200); | |
tiltX=abs((accelerationX*20)-250); | |
CircuitPlayground.playTone(beakPressure, tiltY);// Sound output | |
delay(tiltX); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment