Eli_Beeblebrox
Member
Problem persists even when unplugging/replugging USB. I am using a motherboard rear IO port.
I can still press the button to enter program mode, I can hold it to restore it to the blink sketch which it will do just fine even after disconnecting. It has this issue with any sketch I upload to it. My teensy 3.6 can run these sketches just fine, and they use only pins that are shared between them as far as I can tell.
Photos wouldn't be useful, you can't see past the wires at the only angle the breadboard is visible from
I doubt the code will be of much help as again, this happens no matter what sketch I put on it but here's the current one anyway
I can still press the button to enter program mode, I can hold it to restore it to the blink sketch which it will do just fine even after disconnecting. It has this issue with any sketch I upload to it. My teensy 3.6 can run these sketches just fine, and they use only pins that are shared between them as far as I can tell.
Photos wouldn't be useful, you can't see past the wires at the only angle the breadboard is visible from
I doubt the code will be of much help as again, this happens no matter what sketch I put on it but here's the current one anyway
Code:
#include <Bounce.h>
int inputPinZ = A4;
int inputPinX = A5;
int inputPinY = A6;
int inputPinZrotate = A9;
int inputPinsliderLeft = A7;
int inputPinsliderRight = A8;
const int center = 512;
int centerZmod = 0; // initialize modifiers to set axes centers to 512 after some maths
int centerXmod = 0;
int centerYmod = 0;
int centersliderLeftmod = 0;
int centersliderRightmod = 0;
const int deadzoneZ = 5; // adjustable deadzones here
const int deadzoneX = 5;
const int deadzoneY = 5;
const int deadzonesliderRight = 50;
const int deadzonesliderLeft = 50;
int limitZ = 33;
int limitsliderRight = 200;
int limitsliderLeft = 200;
int readZ = 0;
int readX = 0;
int readY = 0;
int readZrotate = 0;
int readsliderLeft = 0;
int readsliderRight = 0;
int outputZ = 0;
int outputX = 0;
int outputY = 0;
int outputZrotate = 0;
int outputsliderLeft = 0;
int outputsliderRight = 0;
#define HAT_UP_PIN 2
#define HAT_DOWN_PIN 4
#define HAT_LEFT_PIN 34
#define HAT_RIGHT_PIN 7
#define HAT_DEBOUNCE_DELAY 5
//#define BUTTON_DEBOUNCE_DELAY 5
#define HAT_UP_STATE 0 // define the indices for the hat state array
#define HAT_DOWN_STATE 1
#define HAT_LEFT_STATE 2
#define HAT_RIGHT_STATE 3
int hat_state[4] = {0, 0, 0, 0}; // create an array to store the state of the hat switches
Bounce hat_up_button = Bounce(HAT_UP_PIN, HAT_DEBOUNCE_DELAY);
Bounce hat_down_button = Bounce(HAT_DOWN_PIN, HAT_DEBOUNCE_DELAY);
Bounce hat_left_button = Bounce(HAT_LEFT_PIN, HAT_DEBOUNCE_DELAY);
Bounce hat_right_button = Bounce(HAT_RIGHT_PIN, HAT_DEBOUNCE_DELAY);
int hat_value_map[4][4] = { // create a map to get the hat value from the hat switch states
{-1, 270, 90, -1},
{0, 315, 45, -1},
{180, 225, 135, -1},
{-1, -1, -1, -1} };
byte x; // variables for hat_value_map lookups
byte y;
boolean hat_change = false; // flag to detect when the hat state has changed
void setup() {
Serial.begin(9600);
while (millis() < 500) { // center calibration only runs for the first XXX miliseconds
readZ = 1024-analogRead(inputPinZ);
centerZmod = center - readZ;
readX = analogRead(inputPinX);
centerXmod = center - readX;
readY = analogRead(inputPinY);
centerYmod = center - readY;
readsliderLeft = analogRead(inputPinsliderLeft);
centersliderLeftmod = center - readsliderLeft;
readsliderRight = analogRead(inputPinsliderRight);
centersliderRightmod = center - readsliderRight;}
pinMode(HAT_UP_PIN, INPUT_PULLUP); // initialize top hat pins
pinMode(HAT_DOWN_PIN, INPUT_PULLUP);
pinMode(HAT_LEFT_PIN, INPUT_PULLUP);
pinMode(HAT_RIGHT_PIN, INPUT_PULLUP);
pinMode(0, INPUT_PULLUP); // initialize all buttons
pinMode(1, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
pinMode(33, INPUT_PULLUP);
pinMode(35, INPUT_PULLUP);
pinMode(36, INPUT_PULLUP);
pinMode(37, INPUT_PULLUP);
pinMode(38, INPUT_PULLUP);
pinMode(39, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(17, INPUT_PULLUP);
}
void loop() {
readZ = 1024-analogRead(inputPinZ);
outputZ = readZ + centerZmod;
if(outputZ > center - deadzoneZ && outputZ < center + deadzoneZ) outputZ = center;
else outputZ = readZ + centerZmod;
if(outputZ <= center - deadzoneZ) outputZ = outputZ + deadzoneZ;
if(outputZ >= center + deadzoneZ) outputZ = outputZ - deadzoneZ;
if(outputZ >= center + limitZ) outputZ = center + limitZ;
if(outputZ <= center - limitZ) outputZ = center - limitZ;
readX = analogRead(inputPinX);
outputX = readX + centerXmod;
if(outputX > center - deadzoneX && outputX < center + deadzoneX) outputX = center;
else outputX = readX + centerXmod;
if(outputX <= center - deadzoneX) outputX = outputX + deadzoneX;
if(outputX >= center + deadzoneX) outputX = outputX - deadzoneX;
readY = analogRead(inputPinY);
outputY = readY + centerYmod;
if(outputY > center - deadzoneY && outputY < center + deadzoneY) outputY = center;
else outputY = readY + centerYmod;
if(outputY <= center - deadzoneY) outputY = outputY + deadzoneY;
if(outputY >= center + deadzoneY) outputY = outputY - deadzoneY;
readZrotate = 1024-analogRead(inputPinZrotate);
readsliderLeft = analogRead(inputPinsliderLeft);
outputsliderLeft = readsliderLeft + centersliderLeftmod;
if(outputsliderLeft > center - deadzonesliderLeft && outputsliderLeft < center + deadzonesliderLeft) outputsliderLeft = center;
else outputsliderLeft = readsliderLeft + centersliderLeftmod;
if(outputsliderLeft <= center - deadzonesliderLeft) outputsliderLeft = outputsliderLeft + deadzonesliderLeft;
if(outputsliderLeft >= center + deadzonesliderLeft) outputsliderLeft = outputsliderLeft - deadzonesliderLeft;
if(outputsliderLeft >= center + limitsliderLeft) outputsliderLeft = center + limitsliderLeft;
if(outputsliderLeft <= center - limitsliderLeft) outputsliderLeft = center - limitsliderLeft;
readsliderRight = analogRead(inputPinsliderRight);
outputsliderRight = readsliderRight + centersliderRightmod;
if(outputsliderRight > center - deadzonesliderRight && outputsliderRight < center + deadzonesliderRight) outputsliderRight = center;
else outputsliderRight = readsliderRight + centersliderRightmod;
if(outputsliderRight <= center - deadzonesliderRight) outputsliderRight = outputsliderRight + deadzonesliderRight;
if(outputsliderRight >= center + deadzonesliderRight) outputsliderRight = outputsliderRight - deadzonesliderRight;
if(outputsliderRight >= center + limitsliderRight) outputsliderRight = center + limitsliderRight;
if(outputsliderRight <= center - limitsliderRight) outputsliderRight = center - limitsliderRight;
Serial.println(outputsliderRight); // send it to the computer as ASCII digits
Joystick.Z(outputZ);
Joystick.X(outputX);
Joystick.Y(outputY);
Joystick.Zrotate(readZrotate);
Joystick.sliderLeft(outputsliderLeft);
Joystick.sliderRight(outputsliderRight);
hat_up_button.update(); // update the button objects for the hat switches
hat_down_button.update();
hat_left_button.update();
hat_right_button.update();
if (hat_up_button.fallingEdge()) { // update hat state array if any hat switches have been pressed
hat_state[HAT_UP_STATE] = 1;
hat_change = true; }
if (hat_down_button.fallingEdge()) {
hat_state[HAT_DOWN_STATE] = 1;
hat_change = true; }
if (hat_left_button.fallingEdge()) {
hat_state[HAT_LEFT_STATE] = 1;
hat_change = true; }
if (hat_right_button.fallingEdge()) {
hat_state[HAT_RIGHT_STATE] = 1;
hat_change = true; }
if (hat_up_button.risingEdge()) { // update hat state array if any hat switches have been released
hat_state[HAT_UP_STATE] = 0;
hat_change = true; }
if (hat_down_button.risingEdge()) {
hat_state[HAT_DOWN_STATE] = 0;
hat_change = true; }
if (hat_left_button.risingEdge()) {
hat_state[HAT_LEFT_STATE] = 0;
hat_change = true; }
if (hat_right_button.risingEdge()) {
hat_state[HAT_RIGHT_STATE] = 0;
hat_change = true; }
if (hat_change) { // set the hat value based on the hat switch states
y = hat_state[HAT_UP_STATE] | (hat_state[HAT_DOWN_STATE] << 1);
x = hat_state[HAT_LEFT_STATE] | (hat_state[HAT_RIGHT_STATE] << 1);
Joystick.hat(hat_value_map[y][x]);
hat_change = false; // reset the hat state change flag
}
if (digitalRead(0) == LOW) {
Joystick.button(1, 1); }
else {
Joystick.button(1, 0); }
if (digitalRead(1) == LOW) {
Joystick.button(2, 1); }
else {
Joystick.button(2, 0); }
if (digitalRead(3) == LOW) {
Joystick.button(4, 1); }
else {
Joystick.button(4, 0); }
if (digitalRead(5) == LOW) {
Joystick.button(6, 1); }
else {
Joystick.button(6, 0); }
if (digitalRead(6) == LOW) {
Joystick.button(7, 1); }
else {
Joystick.button(7, 0); }
if (digitalRead(8) == LOW) {
Joystick.button(9, 1); }
else {
Joystick.button(9, 0); }
if (digitalRead(9) == LOW) {
Joystick.button(10, 1); }
else {
Joystick.button(10, 0); }
if (digitalRead(10) == LOW) {
Joystick.button(11, 1); }
else {
Joystick.button(11, 0); }
if (digitalRead(11) == LOW) {
Joystick.button(12, 1); }
else {
Joystick.button(12, 0); }
if (digitalRead(12) == LOW) {
Joystick.button(13, 1); }
else {
Joystick.button(13, 0); }
if (digitalRead(24) == LOW) {
Joystick.button(14, 1); }
else {
Joystick.button(14, 0); }
if (digitalRead(25) == LOW) {
Joystick.button(15, 1); }
else {
Joystick.button(15, 0); }
if (digitalRead(26) == LOW) {
Joystick.button(16, 1); }
else {
Joystick.button(16, 0); }
if (digitalRead(27) == LOW) {
Joystick.button(17, 1); }
else {
Joystick.button(17, 0); }
if (digitalRead(28) == LOW) {
Joystick.button(18, 1); }
else {
Joystick.button(18, 0); }
if (digitalRead(29) == LOW) {
Joystick.button(19, 1); }
else {
Joystick.button(19, 0); }
if (digitalRead(30) == LOW) {
Joystick.button(20, 1); }
else {
Joystick.button(20, 0); }
if (digitalRead(31) == LOW) {
Joystick.button(21, 1); }
else {
Joystick.button(21, 0); }
if (digitalRead(32) == LOW) {
Joystick.button(22, 1); }
else {
Joystick.button(22, 0); }
if (digitalRead(33) == LOW) {
Joystick.button(23, 1); }
else {
Joystick.button(23, 0); }
if (digitalRead(35) == LOW) {
Joystick.button(25, 1); }
else {
Joystick.button(25, 0); }
if (digitalRead(36) == LOW) {
Joystick.button(26, 1); }
else {
Joystick.button(26, 0); }
if (digitalRead(37) == LOW) {
Joystick.button(27, 1); }
else {
Joystick.button(27, 0); }
if (digitalRead(38) == LOW) {
Joystick.button(28, 1); }
else {
Joystick.button(28, 0); }
if (digitalRead(39) == LOW) {
Joystick.button(29, 1); }
else {
Joystick.button(29, 0); }
if (digitalRead(14) == LOW) {
Joystick.button(30, 1); }
else {
Joystick.button(30, 0); }
if (digitalRead(15) == LOW) {
Joystick.button(31, 1); }
else {
Joystick.button(31, 0); }
if (digitalRead(16) == LOW) {
Joystick.button(32, 1); }
else {
Joystick.button(32, 0); }
if (digitalRead(17) == LOW) {
Joystick.button(24, 1); }
else {
Joystick.button(24, 0); }
delay(5);
}