Created
May 2, 2018 06:44
-
-
Save noamr/69df334135840e93a88e33363ed7d542 to your computer and use it in GitHub Desktop.
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 <AxisJoystick.h> | |
// these constants won't change: | |
const int piezo1 = A0; // the piezo is connected to analog pin 0 | |
const int piezo2 = A1; // the piezo is connected to analog pin 0 | |
const int piezo3 = A2; // the piezo is connected to analog pin 0 | |
const int piezo4 = A3; // the piezo is connected to analog pin 0 | |
const int minValue = 384; // threshold value to decide when the detected sound is a knock or not | |
const int maxValue = 1024; | |
const int THRESHOLD = 950; | |
// these variables will change: | |
int sensorReading = 0; // variable to store the value read from the sensor pin | |
int ledState = LOW; // variable used to store the last LED status, to toggle the light | |
#define JOYSTICK_SW_PIN 2 | |
#define JOYSTICK_VRX_PIN A6 | |
#define JOYSTICK_VRY_PIN A7 | |
AxisJoystick* joystick; | |
void setup() { | |
Serial.begin(19200); // use the serial port | |
joystick = new AxisJoystick(JOYSTICK_SW_PIN, JOYSTICK_VRX_PIN, JOYSTICK_VRY_PIN); | |
} | |
int printValue(int index, int val) { | |
if (val > THRESHOLD) { | |
Serial.print("TOUCH "); | |
Serial.println(index); | |
} | |
} | |
int printJoystick(int move) { | |
if (move == AxisJoystick::Move::PRESS) { | |
Serial.println("JS PRESS"); | |
} else if (move == AxisJoystick::Move::UP) { | |
Serial.println("JS UP"); | |
} else if (move == AxisJoystick::Move::DOWN) { | |
Serial.println("JS DOWN"); | |
} else if (move == AxisJoystick::Move::RIGHT) { | |
Serial.println("JS RIGHT"); | |
} else if (move == AxisJoystick::Move::LEFT) { | |
Serial.println("JS LEFT"); | |
} else { | |
return 0; | |
} | |
return 1; | |
} | |
void loop() { | |
printValue(1, analogRead(piezo1)); | |
printValue(2, analogRead(piezo2)); | |
printValue(3, analogRead(piezo3)); | |
printValue(4, analogRead(piezo4)); | |
printJoystick(joystick->singleRead()); | |
delay(30); // delay to avoid overloading the serial port buffer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment