Initial Commit

Initial Commit

Uploaded PS2 Arduino controller code
Schematics soon™

#define axisLx 2
#define axisLy 3
#define axisRy 4
#define axisRx 5
#define buttonDDown 6
#define buttonDLeft 7

#define buttonL1 8
#define buttonL2 9
#define buttonSelect 10
#define buttonAnalog 11
#define buttonStart 12
#define buttonR1 13

#define buttonDUp 22
#define buttonDRight 23
#define buttonSquare 24
#define buttonR2 25
#define buttonTriangle 26
#define buttonCircle 27

#define buttonCross 28
#define buttonR3 29
#define buttonL3 30

#define leftMotor A0
#define rightMotor A1
#define analogLed A2

#define attentionPin A3

boolean isInputting = false;
boolean isInputtingDelayed = false;
boolean sentPing = false;
boolean sentPong = false;
boolean isConnected = false;

unsigned long inputDelay = 0;
unsigned long previousInputDelay = 0;
unsigned long currentMillis = 0;

unsigned long pingTimeOut = 0;
unsigned long pongTimeOut = 0;
unsigned long pingTimeIn = 0;
unsigned long pongTimeIn = 0;
unsigned long pingDelay = 1000;
unsigned long pongDelay = 1000;
unsigned long previousCalc = 0;
unsigned long calcDelay = 1000;
unsigned long previousPingDelay = 0;
unsigned long previousPongDelay = 0;
unsigned long lastPingIn = 0;
unsigned long lastPongIn = 0;
unsigned long lastPingOut = 0;
unsigned long lastPongOut = 0;
unsigned long calcPingTimestampIn = 0;
unsigned long calcPongTimestampIn = 0;
unsigned long calcPingTimestampOut = 0;
unsigned long calcPongTimestampOut = 0;

unsigned int leftMotorVal = 0;
unsigned int rightMotorVal = 0;
unsigned int analogLedVal = 0;

unsigned int attentionLevel = 0;
unsigned int previousAttentionLevel = 0;
unsigned long attentionLevelLow = 0;
unsigned long attentionLevelHigh = 0;
unsigned long previousAttentionLevelHigh = 0;
unsigned long previousAttentionLevelLow = 0;

unsigned int leftMotorLevel = 0;
unsigned int previousLeftMotorLevel = 0;
unsigned long leftMotorLevelLow = 0;
unsigned long leftMotorLevelHigh = 0;
unsigned long previousLeftMotorLevelHigh = 0;
unsigned long previousLeftMotorLevelLow = 0;

unsigned int rightMotorLevel = 0;
unsigned int previousRightMotorLevel = 0;
unsigned long rightMotorLevelLow = 0;
unsigned long rightMotorLevelHigh = 0;
unsigned long previousRightMotorLevelHigh = 0;
unsigned long previousRightMotorLevelLow = 0;

unsigned int analogLedLevel = 0;
unsigned int previousAnalogLedLevel = 0;
unsigned long analogLedLevelLow = 0;
unsigned long analogLedLevelHigh = 0;
unsigned long previousAnalogLedLevelHigh = 0;
unsigned long previousAnalogLedLevelLow = 0;

unsigned long resetCalled = 0;
unsigned long resetDone = 0;

unsigned long disconnectCalled = 0;
unsigned long disconnectDone = 0;

unsigned long baudRate = 115200;

byte serial_rx_buffer[12];
byte serial_rx_buffer_inverted[12];
byte serial_rx_buffer_controller[12];
byte serial_rx_buffer_ping_in[12];
byte serial_rx_buffer_ping_out[12];
byte serial_rx_buffer_pong_in[12];
byte serial_rx_buffer_pong_out[12];
byte serial_rx_buffer_motor[12];
byte serial_rx_buffer_reset[12];
byte serial_rx_buffer_disconnect[12];
byte serial_rx_buffer_inverted_controller[12];
unsigned long serial_rx_buffer_counter = 0;
unsigned long controller = 0;

//  The array below is an array of all buttons in the order the bytes have to be sent
unsigned int commandArray[] = {buttonSelect, buttonL3, buttonR3, buttonStart, buttonDUp, buttonDRight, buttonDDown, buttonDLeft, buttonL2, buttonR2, buttonL1, buttonR1, buttonTriangle, buttonCircle, buttonCross, buttonSquare, axisRx, axisRy, axisLx, axisLy, buttonAnalog};
unsigned int motorArray[] = {leftMotor, rightMotor, analogLed};

void setup() {
  currentMillis = millis();
  Serial.begin(baudRate);
  isConnected = true;
  //Serial.println("START OF SETUP");

  //  Define buttons and axis to neutral state on startup
  pinMode(axisLx, OUTPUT);
  pinMode(axisLy, OUTPUT);
  pinMode(axisRy, OUTPUT);
  pinMode(axisRx, OUTPUT);
  pinMode(buttonDDown, OUTPUT);
  pinMode(buttonDLeft, OUTPUT);

  pinMode(buttonL1, OUTPUT);
  pinMode(buttonL2, OUTPUT);
  pinMode(buttonSelect, OUTPUT);
  pinMode(buttonAnalog, OUTPUT);
  pinMode(buttonStart, OUTPUT);
  pinMode(buttonR1, OUTPUT);

  pinMode(buttonDUp, OUTPUT);
  pinMode(buttonDRight, OUTPUT);
  pinMode(buttonSquare, OUTPUT);
  pinMode(buttonR2, OUTPUT);
  pinMode(buttonTriangle, OUTPUT);
  pinMode(buttonCircle, OUTPUT);

  pinMode(buttonCross, OUTPUT);
  pinMode(buttonR3, OUTPUT);
  pinMode(buttonL3, OUTPUT);

  pinMode(leftMotor, INPUT);
  pinMode(rightMotor, INPUT);
  pinMode(analogLed, INPUT);

  digitalWrite(buttonSelect, HIGH);
  digitalWrite(buttonL3, HIGH);
  digitalWrite(buttonR3, HIGH);
  digitalWrite(buttonStart, HIGH);
  digitalWrite(buttonDUp, HIGH);
  digitalWrite(buttonDRight, HIGH);
  digitalWrite(buttonDDown, HIGH);
  digitalWrite(buttonDLeft, HIGH);

  digitalWrite(buttonL2, HIGH);
  digitalWrite(buttonR2, HIGH);
  digitalWrite(buttonL1, HIGH);
  digitalWrite(buttonR1, HIGH);
  digitalWrite(buttonTriangle, HIGH);
  digitalWrite(buttonCircle, HIGH);
  digitalWrite(buttonCross, HIGH);
  digitalWrite(buttonSquare, HIGH);

  analogWrite(axisRx, 128);
  analogWrite(axisRy, 128);
  analogWrite(axisLx, 128);
  analogWrite(axisLy, 128);

  digitalWrite(buttonAnalog, HIGH);

  //  Define Input pins for motors and analog LED
  pinMode(leftMotor, INPUT);
  pinMode(rightMotor, INPUT);
  pinMode(analogLed, INPUT);

  pinMode(attentionPin, INPUT);

  //  Prepare data to sent on startup as a way to tell the controller is in Neutral position
  //  That means, when all buttons and analog sticks are reset to their Neutral positions
  serial_rx_buffer_controller[0] = 0x01; //  Preamble
  serial_rx_buffer_controller[1] = 0x00; //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
  serial_rx_buffer_controller[2] = 0x00; //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
  serial_rx_buffer_controller[3] = 0x7F; //  RX
  serial_rx_buffer_controller[4] = 0x7F; //  RY
  serial_rx_buffer_controller[5] = 0x7F; //  LX
  serial_rx_buffer_controller[6] = 0x7F; //  LY
  serial_rx_buffer_controller[7] = 0x00; //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7  //  All other bits in this Buffer Array Element are unused
  serial_rx_buffer_controller[8] = 0x00; //  Unused
  serial_rx_buffer_controller[9] = 0x00; //  Delay Byte 2
  serial_rx_buffer_controller[10] = 0x00; // Delay Byte 1
  serial_rx_buffer_controller[11] = 0x01; // Postamble

  //  Count bytes and parse ASCII values to their respective commands, such as buttons and axis
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
    Serial.write(serial_rx_buffer_controller[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
    serial_rx_buffer_inverted_controller[serial_rx_buffer_counter] = (255 - serial_rx_buffer_controller[serial_rx_buffer_counter]); //  Invert 0 to 255 and vice versa to make it easier to determine which commands to enable or not, and their values
  }
  Serial.flush();
  //  Now we send PING to the computer as a way to tell we are connected and ready to receive and send data through the serial port
  //  This will be executed whenever the computer starts serial through the Processing Serial Library, which forces the Arduino to reset, due to DTR line (Data Terminal Ready)
  pingTimeOut = currentMillis;
  serial_rx_buffer_ping_out[8] = (byte)((pingTimeOut & 0xFF));
  serial_rx_buffer_ping_out[7] = (byte)((pingTimeOut >> 8) & 0xFF);
  serial_rx_buffer_ping_out[6] = (byte)((pingTimeOut >> 16) & 0xFF);
  serial_rx_buffer_ping_out[5] = (byte)((pingTimeOut >> 24) & 0xFF);
  sentPing = false;
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_ping_out); serial_rx_buffer_counter++) {
    if (serial_rx_buffer_counter == 0) {
      Serial.write(0x04);
    }
    if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4)) {
      Serial.write(0x00);
    }
    if ((serial_rx_buffer_counter == 5) || (serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
      Serial.write(serial_rx_buffer_ping_out[serial_rx_buffer_counter]);
    }
    if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
      Serial.write(0x00);
    }
    if (serial_rx_buffer_counter == 11) {
      Serial.write(0x04);
    }
  }
  Serial.flush();
  sendPing();
  calculatePing();
  calculatePong();
  getAttention();
  readMotors();
  //Serial.println("END OF SETUP");
  //  And we are ready to go
}

void loop() {
  currentMillis = millis();
  //  Get data from Serial Port
  //  Preamble/Postamble = 0x01 for Controller Input // Does the Arduino have to respond with a different Preamble/Postamble value when it receives a valid Controller Input Data?
  //  Preamble/Postamble = Send 0x02 to Arduino for Motors and Analog Status
  //  Preamble/Postamble = Arduino responds with 0x06 for Motors and Analog Status, when Preamble/Postamble = 0x02
  //  Preamble/Postamble = 0x07 for Motors and Analog Status, when Attention Pin is LOW
  //  Preamble/Postamble = 0x08 for Motors and Analog Status, when Attention Pin is HIGH

  //  Preamble/Postamble = 0x03 for PING for BOTH ways
  //  PING/PONG System where PING is sent from the Arduino and PONG is sent from the Computer:
  //  Where ">>" is incoming data and "<<" is outgoing data
  //  << PING 3000  // This is data sent from the Arduino
  //  >> PONG 3000  // This is data the Arduino received

  //  Preamble/Postamble = 0x04 for PONG for BOTH wayy
  //  PING/PONG System where PING is sent from the Computer and PONG is sent from the Arduino:
  //  Where ">>" is incoming data and "<<" is outgoing data
  //  >> PING 1487568769420  // This is data the Arduino received
  //  << PONG 1487568769420  // This is data sent from the Arduino

  //  NOTE: This is in no way supposed to represent actual communication, it's only a way to making visualizing data traffic more easily

  //  Preamble/Postamble = 0xA0 for Soft Reset the Arduino without resetting Variables
  //  Preamble/Postamble = 0xA1 for Command that tells the computer the Reset command 0xA0 was understood by the Arduino

  //  Preamble/Postamble = 0x09 for Disconnect
  //  Preamble/Postamble = 0x0A for Disconnect Understood
  //  Preamble/Postamble = 0x0B for Reconnect Successful
  //  Example:
  //  Arduino sends Disconnect to the computer in case of PING timeout (The Computer didn't respond with PONG in time)
  //  The computer then sends Disconnect Understood back to the Arduino, both close connections on their ends, then start connection again
  //  The Arduino then sends Reconnect Successful to tell the computer Connection is working as intended
  //  Or:
  //  Computer sends Disconnect to the Arduino in case of PING timeout (The Arduino didn't respond with PONG in time)
  //  The Arduino then sends Disconnect Understood back to the Computer, both close connections on their ends, then start connection again
  //  The Computer then sends Reconnect Successful to tell the Arduino Connection is working as intended
  if (Serial.available() > 0) {

    controller = Serial.readBytes(serial_rx_buffer, sizeof(serial_rx_buffer)) && 0xFF;

    //  Set Start Byte (Preamble Byte) and End Byte (Postamble Byte)
    //  1 == 0x01
    if ((serial_rx_buffer[0] == 0x01) && (serial_rx_buffer[11] == 0x01)) {

      //  Count bytes and parse ASCII values to their respective commands, such as buttons and axis
      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
        Serial.write(serial_rx_buffer[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
        //  Invert 0 to 255 and vice versa to make it easier to determine which commands to enable or not, and their values
        serial_rx_buffer_inverted[serial_rx_buffer_counter] = (255 - serial_rx_buffer[serial_rx_buffer_counter]);
        serial_rx_buffer_controller[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
        serial_rx_buffer_inverted_controller[serial_rx_buffer_counter] = (255 - serial_rx_buffer_controller[serial_rx_buffer_counter]);
      }
      //Serial.print('\n');
      Serial.flush();
      // Make the button presses actually work
      isInputting = true;
      previousInputDelay = currentMillis;
    }
    //  Get Motors and Analog status
    else if ((serial_rx_buffer[0] == 0x02) && (serial_rx_buffer[11] == 0x02)) {
      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
        Serial.write(serial_rx_buffer[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
        serial_rx_buffer_motor[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
      }
      readMotors();
    }
    //  Get PING/PONG status
    else if ((serial_rx_buffer[0] == 0x03) && (serial_rx_buffer[11] == 0x03)) {
      //  Get PING status
      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_ping_in); serial_rx_buffer_counter++) {
        //  Pass Serial Buffer to Ping Input Buffer
        serial_rx_buffer_ping_in[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
      }
      getPing();
    }
    else if ((serial_rx_buffer[0] == 0x04) && (serial_rx_buffer[11] == 0x04)) {
      //  Get PONG status
      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_pong_in); serial_rx_buffer_counter++) {
        //  Pass Serial Buffer to Pong Input Buffer
        serial_rx_buffer_pong_in[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
      }
      getPong();
    }
    else if ((serial_rx_buffer[0] == 0xA0) && (serial_rx_buffer[11] == 0xA0)) {
      // Reset Arduino without reseting Variables
      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset); serial_rx_buffer_counter++) {
        //  Pass Serial Buffer to Reset Buffer
        serial_rx_buffer_reset[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
      }
      arduinoReset();
    }
    else if ((serial_rx_buffer[0] == 0x09) && (serial_rx_buffer[11] == 0x09)) {
      // Reset Arduino without reseting Variables
      for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
        //  Pass Serial Buffer to Reset Buffer
        serial_rx_buffer_disconnect[serial_rx_buffer_counter] = serial_rx_buffer[serial_rx_buffer_counter];
      }
      arduinoDisconnect();
    }
  }
  pressButtons();
  sendPing();
  calculatePing();
  calculatePong();
  getAttention();
} // Close Loop Function

void arduinoDisconnect() {
  disconnectCalled = currentMillis;
  //Serial.println(disconnectCalled);
  //Serial.println("DISCONNECTING...");
  serial_rx_buffer_disconnect[0] = 0x0A;
  serial_rx_buffer_disconnect[11] = 0x0A;
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
    Serial.write(serial_rx_buffer_disconnect[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
  }
  Serial.flush();
  Serial.end();
  isConnected = false;
  disconnectDone = currentMillis;
  Serial.begin(baudRate);
  serial_rx_buffer_disconnect[0] = 0x0B;
  serial_rx_buffer_disconnect[11] = 0x0B;
  isConnected = true;
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
    Serial.write(serial_rx_buffer_disconnect[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
  }
  Serial.flush();
  //Serial.println("RECONNECTED!");
  //Serial.println(disconnectDone);
}

void arduinoReset() {
  resetCalled = currentMillis;
  serial_rx_buffer_reset[0] = 0xA1;
  serial_rx_buffer_reset[11] = 0xA1;
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset); serial_rx_buffer_counter++) {
    Serial.write(serial_rx_buffer_reset[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
  }
  Serial.flush();
  asm volatile ("  jmp 0");
  resetDone = currentMillis;
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_reset); serial_rx_buffer_counter++) {
    Serial.write(serial_rx_buffer_reset[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
  }
  Serial.flush();
  //  From here on, the setup() function will be called again, the computer then proceeds to reset its variables just like an usual startup routine
}

void pressButtons() {
  if (isInputtingDelayed == false) {
    //  Define input delay (If Buffer Array Element 9 and 10 !=0)
    inputDelay = (unsigned long)serial_rx_buffer[9] << 8 | (unsigned long)serial_rx_buffer[10];
  }
  if (isInputting == true)
  {
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_controller); serial_rx_buffer_counter++) {
      Serial.write(serial_rx_buffer_controller[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
      //  Invert 0 to 255 and vice versa to make it easier to determine which commands to enable or not, and their values
      serial_rx_buffer_inverted_controller[serial_rx_buffer_counter] = (255 - serial_rx_buffer_controller[serial_rx_buffer_counter]);
    }
    //Serial.print('\n');
    Serial.flush();
    //  Press Button

    //  First 8 buttons, Buffer Array Element 1
    //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
    digitalWrite(commandArray[0], (serial_rx_buffer_inverted_controller[1] & B00000001));
    digitalWrite(commandArray[1], (serial_rx_buffer_inverted_controller[1] & B00000010));
    digitalWrite(commandArray[2], (serial_rx_buffer_inverted_controller[1] & B00000100));
    digitalWrite(commandArray[3], (serial_rx_buffer_inverted_controller[1] & B00001000));
    digitalWrite(commandArray[4], (serial_rx_buffer_inverted_controller[1] & B00010000));
    digitalWrite(commandArray[5], (serial_rx_buffer_inverted_controller[1] & B00100000));
    digitalWrite(commandArray[6], (serial_rx_buffer_inverted_controller[1] & B01000000));
    digitalWrite(commandArray[7], (serial_rx_buffer_inverted_controller[1] & B10000000));

    //  Second 8 buttons, Buffer Array Element 2
    //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
    digitalWrite(commandArray[8], (serial_rx_buffer_inverted_controller[2] & B00000001));
    digitalWrite(commandArray[9], (serial_rx_buffer_inverted_controller[2] & B00000010));
    digitalWrite(commandArray[10], (serial_rx_buffer_inverted_controller[2] & B00000100));
    digitalWrite(commandArray[11], (serial_rx_buffer_inverted_controller[2] & B00001000));
    digitalWrite(commandArray[12], (serial_rx_buffer_inverted_controller[2] & B00010000));
    digitalWrite(commandArray[13], (serial_rx_buffer_inverted_controller[2] & B00100000));
    digitalWrite(commandArray[14], (serial_rx_buffer_inverted_controller[2] & B01000000));
    digitalWrite(commandArray[15], (serial_rx_buffer_inverted_controller[2] & B10000000));

    //  4 Axis, Buffer Array Elements 3, 4, 5, 6
    //  RX, RY, LX, LY
    analogWrite(commandArray[16], serial_rx_buffer_inverted_controller[3]);
    analogWrite(commandArray[17], serial_rx_buffer_inverted_controller[4]);
    analogWrite(commandArray[18], serial_rx_buffer_inverted_controller[5]);
    analogWrite(commandArray[19], serial_rx_buffer_inverted_controller[6]);

    //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7
    //  All other bits in this Buffer Array Element are unused
    digitalWrite(commandArray[20], (serial_rx_buffer_inverted_controller[7] & B00000001));

    //  Buffer Array Element 8 is unused in this code, but is existing in case changes are needed

    //  Buffer Array Elements 9 and 10 are used to tell the Arduino how long commands are executed, on a delay ranging from 1-65535ms
    //if (serial_rx_buffer[9] != 0x00)
    //if (serial_rx_buffer[10] != 0x00)
    if (inputDelay != 0) {
      isInputtingDelayed = true;

      //  The block below executes Soft Delay for holding the buttons down
      if (isInputtingDelayed == true) {
        if (currentMillis - previousInputDelay >= inputDelay) {
          //  Now we need to stop the Soft Delay

          //  Depress Buttons (Only if Buffer Array Element 9 and 10 != 0x00)
          serial_rx_buffer_controller[1] = 0x00;
          serial_rx_buffer_controller[2] = 0x00;
          serial_rx_buffer_controller[3] = 0x7F;
          serial_rx_buffer_controller[4] = 0x7F;
          serial_rx_buffer_controller[5] = 0x7F;
          serial_rx_buffer_controller[6] = 0x7F;
          serial_rx_buffer_controller[7] = 0x00;
          serial_rx_buffer_controller[8] = 0x00;

          for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_controller); serial_rx_buffer_counter++) {
            Serial.write(serial_rx_buffer_controller[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
            //  Invert 0 to 255 and vice versa to make it easier to determine which commands to enable or not, and their values
            serial_rx_buffer_inverted_controller[serial_rx_buffer_counter] = (255 - serial_rx_buffer_controller[serial_rx_buffer_counter]);
          }

          //  First 8 buttons, Buffer Array Element 1
          //  SELECT, L3, R3, START, DUP, DRIGHT, DDOWN, DLEFT
          digitalWrite(commandArray[0], (serial_rx_buffer_inverted_controller[1] & B00000001));
          digitalWrite(commandArray[1], (serial_rx_buffer_inverted_controller[1] & B00000010));
          digitalWrite(commandArray[2], (serial_rx_buffer_inverted_controller[1] & B00000100));
          digitalWrite(commandArray[3], (serial_rx_buffer_inverted_controller[1] & B00001000));
          digitalWrite(commandArray[4], (serial_rx_buffer_inverted_controller[1] & B00010000));
          digitalWrite(commandArray[5], (serial_rx_buffer_inverted_controller[1] & B00100000));
          digitalWrite(commandArray[6], (serial_rx_buffer_inverted_controller[1] & B01000000));
          digitalWrite(commandArray[7], (serial_rx_buffer_inverted_controller[1] & B10000000));

          //  Second 8 buttons, Buffer Array Element 2
          //  L2, R2, L1, R1, Triangle/Delta, Circle/O, Cross/X, Square
          digitalWrite(commandArray[8], (serial_rx_buffer_inverted_controller[2] & B00000001));
          digitalWrite(commandArray[9], (serial_rx_buffer_inverted_controller[2] & B00000010));
          digitalWrite(commandArray[10], (serial_rx_buffer_inverted_controller[2] & B00000100));
          digitalWrite(commandArray[11], (serial_rx_buffer_inverted_controller[2] & B00001000));
          digitalWrite(commandArray[12], (serial_rx_buffer_inverted_controller[2] & B00010000));
          digitalWrite(commandArray[13], (serial_rx_buffer_inverted_controller[2] & B00100000));
          digitalWrite(commandArray[14], (serial_rx_buffer_inverted_controller[2] & B01000000));
          digitalWrite(commandArray[15], (serial_rx_buffer_inverted_controller[2] & B10000000));

          //  4 Axis, Buffer Array Elements 3, 4, 5, 6
          //  RX, RY, LX, LY
          analogWrite(commandArray[16], serial_rx_buffer_inverted_controller[3]);
          analogWrite(commandArray[17], serial_rx_buffer_inverted_controller[4]);
          analogWrite(commandArray[18], serial_rx_buffer_inverted_controller[5]);
          analogWrite(commandArray[19], serial_rx_buffer_inverted_controller[6]);

          //  Analog button (Used to change between Digital and Analog modes in older games), Buffer Array Element 7
          //  All other bits in this Buffer Array Element are unused
          digitalWrite(commandArray[20], (serial_rx_buffer_inverted_controller[7] & B00000001));

          //  Buffer Array Element 8 is unused in this code, but is existing in case changes are needed
          //Serial.print('\n');
          Serial.flush();

          isInputtingDelayed = false;
          isInputting = false;
          previousInputDelay += inputDelay;
          inputDelay = 0;
        }
      }
    }
  }
}

void getPing() {
  //  This function gets PING sent from the computer, then responds with PONG back to the computer
  pingTimeIn = (unsigned long)serial_rx_buffer_ping_in[5] << 24 | (unsigned long)serial_rx_buffer_ping_in[6] << 16 | (unsigned long)serial_rx_buffer_ping_in[7] << 8 | (unsigned long)serial_rx_buffer_ping_in[8];
  pongTimeOut = pingTimeIn;
  for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
    serial_rx_buffer_pong_out[serial_rx_buffer_counter] = serial_rx_buffer_ping_in[serial_rx_buffer_counter];
    if (serial_rx_buffer_counter == 0) {
      Serial.write(0x04);
    }
    if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4)) {
      Serial.write(0x00);
    }
    if ((serial_rx_buffer_counter == 5) || (serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
      Serial.write(serial_rx_buffer_pong_out[serial_rx_buffer_counter]);
    }
    if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
      Serial.write(0x00);
    }
    if (serial_rx_buffer_counter == 11) {
      Serial.write(0x04);
    }
    //Serial.write(serial_rx_buffer[serial_rx_buffer_counter]); //  Write time back to computer
    sentPong = true;
  }
  //previousPingDelay = currentMillis;
  lastPingIn = currentMillis;
  lastPongOut = currentMillis;
  Serial.flush();
  /*
  Serial.print("PONG = ");
  Serial.println(currentMillis);
  Serial.flush();
  Serial.println("PING RECEIVED");
  Serial.println("");
  Serial.print("LAST PING TIME IN = ");
  Serial.println(lastPingIn);
  Serial.print("LAST PONG TIME IN = ");
  Serial.println(lastPongIn);
  Serial.print("LAST PING TIME OUT = ");
  Serial.println(lastPingOut);
  Serial.print("LAST PONG TIME OUT = ");
  Serial.println(lastPongOut);
  Serial.print("PING TIME OUT = ");
  Serial.println(pingTimeOut);
  Serial.print("PONG TIME OUT = ");
  Serial.println(pongTimeOut);
  Serial.print("PING TIME IN = ");
  Serial.println(pingTimeIn);
  Serial.print("PONG TIME IN= ");
  Serial.println(pongTimeIn);
  Serial.flush();
  */
  sentPong = false;
}

void getPong() {
  //  This function gets PONG sent from the computer, then stores it in an Unsigned Long Integer
  pongTimeIn = (unsigned long)serial_rx_buffer_pong_in[5] << 24 | (unsigned long)serial_rx_buffer_pong_in[6] << 16 | (unsigned long)serial_rx_buffer_pong_in[7] << 8 | (unsigned long)serial_rx_buffer_pong_in[8];
  //  This for loop doesn't have to be used, the Arduino doesn't have to respond to PONG with PONG, it doesn't have to respont to PONG at all.
  /*
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_pong_in); serial_rx_buffer_counter++) {
    serial_rx_buffer_ping_out[serial_rx_buffer_counter] = serial_rx_buffer_pong_in[serial_rx_buffer_counter];
    if (serial_rx_buffer_counter == 0) {
      Serial.write(0x04);
    }
    if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4)) {
      Serial.write(0x00);
    }
    if ((serial_rx_buffer_counter == 5) || (serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
      Serial.write(serial_rx_buffer_ping_out[serial_rx_buffer_counter]);
    }
    if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
      Serial.write(0x00);
    }
    if (serial_rx_buffer_counter == 11) {
      Serial.write(0x04);
    }
    //Serial.write(serial_rx_buffer[serial_rx_buffer_counter]); //  Write time back to computer
    sentPong = true;
    }
  */
  previousPongDelay = currentMillis;
  lastPongIn = currentMillis;
  Serial.flush();
  /*
  Serial.println("PONG RECEIVED");
  Serial.println("");
  Serial.print("CURRENT TIME = ");
  Serial.println(currentMillis);
  Serial.flush();
  Serial.print("LAST PING TIME IN = ");
  Serial.println(lastPingIn);
  Serial.print("LAST PONG TIME IN = ");
  Serial.println(lastPongIn);
  Serial.print("LAST PING TIME OUT = ");
  Serial.println(lastPingOut);
  Serial.print("LAST PONG TIME OUT = ");
  Serial.println(lastPongOut);
  Serial.print("PING TIME OUT = ");
  Serial.println(pingTimeOut);
  Serial.print("PONG TIME OUT = ");
  Serial.println(pongTimeOut);
  Serial.print("PING TIME IN = ");
  Serial.println(pingTimeIn);
  Serial.print("PONG TIME IN= ");
  Serial.println(pongTimeIn);
  Serial.flush();
  */
}

void sendPing() {
  //  This function sends PING to the computer 1 time per second, the computer then responds with PONG back to the Arduino, PONG is then processed in another function
  if (currentMillis - previousPingDelay >= pingDelay) {
    pingTimeOut = currentMillis;
    serial_rx_buffer_ping_out[8] = (byte)((pingTimeOut & 0xFF));
    serial_rx_buffer_ping_out[7] = (byte)((pingTimeOut >> 8) & 0xFF);
    serial_rx_buffer_ping_out[6] = (byte)((pingTimeOut >> 16) & 0xFF);
    serial_rx_buffer_ping_out[5] = (byte)((pingTimeOut >> 24) & 0xFF);
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_ping_out); serial_rx_buffer_counter++) {
      if (serial_rx_buffer_counter == 0) {
        Serial.write(0x03);
      }
      if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4)) {
        Serial.write(0x00);
      }
      if ((serial_rx_buffer_counter == 5) || (serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
        Serial.write(serial_rx_buffer_ping_out[serial_rx_buffer_counter]);
      }
      if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
        Serial.write(0x00);
      }
      if (serial_rx_buffer_counter == 11) {
        Serial.write(0x03);
      }
    }
    Serial.flush();
    sentPing = true;
    /*
      Serial.print("pongTimeByte5 = ");
      Serial.println(serial_rx_buffer[5]);
      Serial.print("pongTimeByte6 = ");
      Serial.println(serial_rx_buffer[6]);
      Serial.print("pongTimeByte7 = ");
      Serial.println(serial_rx_buffer[7]);
      Serial.print("pongTimeByte8 = ");
      Serial.println(serial_rx_buffer[8]);
    */
    /*
      Serial.println();
      Serial.print("PING = ");
      Serial.println(pongTime);
      Serial.flush();
      Serial.print("PING PREVIOUS = ");
      Serial.println(previousPingDelay);
      Serial.print("PONG PREVIOUS = ");
      Serial.println(previousPongDelay);
      Serial.flush();
      Serial.print("CURRENT PONG CALCULATED = ");
      Serial.println(calcPongTimestamp);
      Serial.flush();
      Serial.print("CURRENT PING CALCULATED = ");
      Serial.println(calcPingTimestamp);
      Serial.flush();
    */
    previousPingDelay += pingDelay;
  }
  sentPing = false;
}

void calculatePing() {
  //  Calculate delay since last PONG sent from the computer, If the computer doesn't respond with PONG in 30 seconds since the last PONG sent from the computer, connection is interrupted and the restarted
  calcPingTimestampIn = (currentMillis - previousPingDelay);
  if ((calcPongTimestampIn - calcPingTimestampIn >= 30000) && (calcPongTimestampIn - calcPingTimestampIn <= currentMillis)) {
    disconnectCalled = currentMillis;
    //Serial.println(disconnectCalled);
    //Serial.println("DISCONNECTING...");
    //Serial.print("DISCONNECTING PING = ");
    //Serial.println(calcPongTimestampIn);
    serial_rx_buffer_disconnect[0] = 0x0A;
    serial_rx_buffer_disconnect[11] = 0x0A;
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
      Serial.write(serial_rx_buffer_disconnect[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
    }
    Serial.flush();
    //calcPongTimestamp = 0;
    previousPongDelay = currentMillis;
    //Serial.print("RESET PING = ");
    //Serial.println(calcPongTimestamp);
    Serial.end();
    isConnected = false;
    //Serial.println("Sending shit after connection has closed");
    Serial.begin(baudRate);
    serial_rx_buffer_disconnect[0] = 0x0B;
    serial_rx_buffer_disconnect[11] = 0x0B;
    isConnected = true;
    disconnectDone = currentMillis;
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_disconnect); serial_rx_buffer_counter++) {
      Serial.write(serial_rx_buffer_disconnect[serial_rx_buffer_counter]); //  This line writes the serial data back to the computer as a way to check if the Arduino isn't interpreting wrong values
    }
    Serial.flush();
    //Serial.println("Sending shit after connection has began");
    //Serial.println("RECONNECTED!");
    //Serial.println(calcPongTimestampIn);
    disconnectDone = currentMillis;
    //Serial.println(disconnectDone);
  }
  else if (calcPongTimestampIn - calcPingTimestampIn < 30000) {
    //Serial.println("PONG OK");
    //Serial.println(currentMillis);
  }
}

void calculatePong() {
  //  Caclulate if PONG is out of range, then do something
  calcPongTimestampIn = (currentMillis - previousPongDelay);
  //  Seriously, why did I make this function it serves no point, or I just forgot what it was supposed to be used for.(?)
}

void getAttention() {
  //  Get Attention Line levels, if it's low, then it's sending input, if it's high, it's not sending input to the PS2
  attentionLevel = digitalRead(attentionPin);
  if (attentionLevel !=  previousAttentionLevel)
  {
    if (attentionLevel == HIGH)
    {
      //Serial.println("HIGH");
      readMotors();
      previousAttentionLevelHigh = currentMillis;
      //Serial.println(previousAttentionLevelHigh);
      attentionLevelHigh++;
    }
    else if (attentionLevel == LOW)
    {
      //Serial.println("LOW");
      readMotors();
      previousAttentionLevelLow = currentMillis;
      //Serial.println(previousAttentionLevelLow);
      attentionLevelLow++;
    }
  }
  previousAttentionLevel = attentionLevel;
}

/*
  void doStuff() {
  pongTime = currentMillis;
  serial_rx_buffer[7] = (byte) pongTime;
  serial_rx_buffer[8] = (byte) pongTime >> 8;
  serial_rx_buffer[9] = (byte) pongTime >> 16;
  serial_rx_buffer[10] = (byte) pongTime >> 24;
  sentPing = false;
  if (currentMillis - previousPingDelay >= pingDelay) {
    //pongTime = (unsigned long)serial_rx_buffer[7] << 24 | (unsigned long)serial_rx_buffer[8] << 16 | (unsigned long)serial_rx_buffer[9] << 8 | (unsigned long)serial_rx_buffer[10];
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer); serial_rx_buffer_counter++) {
      if (serial_rx_buffer_counter == 0) {
        //Serial.write(0x04);
      }
      if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4) || (serial_rx_buffer_counter == 5) || (serial_rx_buffer_counter == 6)) {
        //Serial.write(0x00);
      }
      if ((serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8) || (serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
        //Serial.write(serial_rx_buffer[serial_rx_buffer_counter]);
      }
      if (serial_rx_buffer_counter == 11) {
        //Serial.write(0x04);
      }
    }
    //Serial.flush();
    //Serial.println();
    Serial.print("PONG = ");
    Serial.println(pongTime);
    Serial.flush();
    sentPing = true;
    previousPingDelay += pingDelay;
  }
  }
*/

void readMotors() {
  if ((serial_rx_buffer_motor[0] == 0x02) && (serial_rx_buffer_motor[11] == 0x02))
  {
    // Observed value is ~39 when On , 0 when Off (Reading analog instead of digital, so I can get a threshold of the reading)
    //leftMotorVal = (digitalRead(motorArray[0])); // This is the SMALL MOTOR
    leftMotorVal = (analogRead(motorArray[0]));
    //  map() is used to convert min and max values to desired values, in this case, I need to convert 1023 to 255
    leftMotorVal = map(leftMotorVal, 0, 1023, 0, 255);

    // Observed value is ~39 when On , 0 when Off
    rightMotorVal = (analogRead(motorArray[1]));
    //rightMotorVal = (digitalRead(motorArray[1])); // This is the BIG MOTOR
    rightMotorVal = map(rightMotorVal, 0, 1023, 0, 255);

    // Observed value ~108 when HIGH (LED is OFF), ~85 when LOW (LED is ON)
    analogLedVal = (analogRead(motorArray[2]));
    //analogLedVal = (digitalRead(motorArray[2])); // If analogLedVal = High, Analog is OFF, else if analogLedVal = Low, Analog is ON
    analogLedVal = map(analogLedVal, 0, 1023, 0, 255);
    serial_rx_buffer_motor[6] = leftMotorVal;
    serial_rx_buffer_motor[7] = rightMotorVal;
    serial_rx_buffer_motor[8] = analogLedVal;
    //Serial.print('\n');
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_motor); serial_rx_buffer_counter++) {
      if (serial_rx_buffer_counter == 0) {
        Serial.write(0x06);
      }
      if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4) || (serial_rx_buffer_counter == 5)) {
        Serial.write(0x00);
      }
      if ((serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
        Serial.write(serial_rx_buffer_motor[serial_rx_buffer_counter]);
      }
      if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
        Serial.write(0x00);
      }
      if (serial_rx_buffer_counter == 11) {
        Serial.write(0x06);
      }
      serial_rx_buffer_motor[serial_rx_buffer_counter] = 0x00;
    }
    Serial.flush();
    /*
      Serial.print("leftMotorVal = ");
      Serial.print(leftMotorVal);
      Serial.print(" rightMotorVal = ");
      Serial.print(rightMotorVal);
      Serial.print(" analogLedVal = ");
      Serial.println(analogLedVal);
      Serial.flush();
    */
  }
  if (attentionLevel == HIGH)
  {
    // Observed value is ~39 when On , 0 when Off (Reading analog instead of digital, so I can get a threshold of the reading)
    //leftMotorVal = (digitalRead(motorArray[0]));
    leftMotorVal = (analogRead(motorArray[0]));
    //  map() is used to convert min and max values to desired values, in this case, I need to convert 1023 to 255
    leftMotorVal = map(leftMotorVal, 0, 1023, 0, 255);

    // Observed value is ~39 when On , 0 when Off
    rightMotorVal = (analogRead(motorArray[1]));
    //rightMotorVal = (digitalRead(motorArray[1]));
    rightMotorVal = map(rightMotorVal, 0, 1023, 0, 255);

    // Observed value ~108 when HIGH (LED is OFF), ~85 when LOW (LED is ON)
    analogLedVal = (analogRead(motorArray[2]));
    //analogLedVal = (digitalRead(motorArray[2]));
    analogLedVal = map(analogLedVal, 0, 1023, 0, 255);
    serial_rx_buffer_motor[6] = leftMotorVal;
    serial_rx_buffer_motor[7] = rightMotorVal;
    serial_rx_buffer_motor[8] = analogLedVal;
    //Serial.print('\n');
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_motor); serial_rx_buffer_counter++) {
      if (serial_rx_buffer_counter == 0) {
        Serial.write(0x08);
      }
      if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4) || (serial_rx_buffer_counter == 5)) {
        Serial.write(0x00);
      }
      if ((serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
        Serial.write(serial_rx_buffer_motor[serial_rx_buffer_counter]);
      }
      if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
        Serial.write(0x00);
      }
      if (serial_rx_buffer_counter == 11) {
        Serial.write(0x08);
      }
    }
    Serial.flush();
    /*
      Serial.print("leftMotorVal = ");
      Serial.print(leftMotorVal);
      Serial.print(" rightMotorVal = ");
      Serial.print(rightMotorVal);
      Serial.print(" analogLedVal = ");
      Serial.println(analogLedVal);
      Serial.flush();
    */
  }
  else if (attentionLevel == LOW)
  {
    // Observed value is ~39 when On , 0 when Off (Reading analog instead of digital, so I can get a threshold of the reading)
    //leftMotorVal = (digitalRead(motorArray[0]));
    leftMotorVal = (analogRead(motorArray[0]));
    //  map() is used to convert min and max values to desired values, in this case, I need to convert 1023 to 255
    leftMotorVal = map(leftMotorVal, 0, 1023, 0, 255);

    // Observed value is ~39 when On , 0 when Off
    rightMotorVal = (analogRead(motorArray[1]));
    //rightMotorVal = (digitalRead(motorArray[1]));
    rightMotorVal = map(rightMotorVal, 0, 1023, 0, 255);

    // Observed value ~108 when HIGH (LED is OFF), ~85 when LOW (LED is ON)
    analogLedVal = (analogRead(motorArray[2]));
    //analogLedVal = (digitalRead(motorArray[2]));
    analogLedVal = map(analogLedVal, 0, 1023, 0, 255);
    serial_rx_buffer_motor[6] = leftMotorVal;
    serial_rx_buffer_motor[7] = rightMotorVal;
    serial_rx_buffer_motor[8] = analogLedVal;
    //Serial.print('\n');
    for (serial_rx_buffer_counter = 0; serial_rx_buffer_counter < sizeof(serial_rx_buffer_motor); serial_rx_buffer_counter++) {
      if (serial_rx_buffer_counter == 0) {
        Serial.write(0x07);
      }
      if ((serial_rx_buffer_counter == 1) || (serial_rx_buffer_counter == 2) || (serial_rx_buffer_counter == 3) || (serial_rx_buffer_counter == 4) || (serial_rx_buffer_counter == 5)) {
        Serial.write(0x00);
      }
      if ((serial_rx_buffer_counter == 6) || (serial_rx_buffer_counter == 7) || (serial_rx_buffer_counter == 8)) {
        Serial.write(serial_rx_buffer_motor[serial_rx_buffer_counter]);
      }
      if ((serial_rx_buffer_counter == 9) || (serial_rx_buffer_counter == 10)) {
        Serial.write(0x00);
      }
      if (serial_rx_buffer_counter == 11) {
        Serial.write(0x07);
      }
    }
    Serial.flush();
    /*
      Serial.print("leftMotorVal = ");
      Serial.print(leftMotorVal);
      Serial.print(" rightMotorVal = ");
      Serial.print(rightMotorVal);
      Serial.print(" analogLedVal = ");
      Serial.println(analogLedVal);
      Serial.flush();
    */
  }
}

error: pathspec 'ps2_controller/ps2_controller.ino' did not match any file(s) known to git


inicial

inicial

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/DigitalesSED/ProyectoFinal.git/'


Add controller firmware

Add controller firmware

This adds the source code for the controller firmware.  It can be
updated to the controller via the Arduino IDE.

// Copyright 2016 Nathan Kinder and the Smart Card Removinator contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// SPI is used to communicate with shift registers.
#include <SPI.h>

// Serial command syntax
#define CMD_PREFIX '#'
#define CMD_TERM '\r'
#define CMD_MAX_LEN 3

// Serial commands
#define CMD_CARD_1 "SC1"
#define CMD_CARD_2 "SC2"
#define CMD_CARD_3 "SC3"
#define CMD_CARD_4 "SC4"
#define CMD_CARD_5 "SC5"
#define CMD_CARD_6 "SC6"
#define CMD_CARD_7 "SC7"
#define CMD_CARD_8 "SC8"
#define CMD_REMOVE_CARD "REM"
#define CMD_STATUS "STA"
#define CMD_DEBUG "DBG"
#define CMD_HELP "?"

// Standard serial responses
#define RESP_OK "OK"
#define RESP_DBG_ON "DBG_ON"
#define RESP_DBG_OFF "DBG_OFF"
#define ERR_UNKNOWN_CMD "ERR_UNKOWN_CMD"
#define ERR_CMDLEN "ERR_CMDLEN"
#define ERR_PROTOCOL "ERR_PROTOCOL"
#define ERR_NOCARD "ERR_NOCARD"

// Debug output defines
#define LOG_DBG_PREFIX "[DBG] "

// Constants
const byte display_digits[] = { 0x88, 0xDB, 0xA2, 0x92, 0xD1,
                                0x94, 0x84, 0xDA, 0x80, 0x90 };
const int mux_en_pin = 2;
const int mux_a0_pin = 3;
const int mux_a1_pin = 4;
const int mux_a2_pin = 5;
const int display_select_pin = 6;
const int socket_switch_select_pin = 7;

// Globals
char command[CMD_MAX_LEN + 1];
int inserted_card = 0;
boolean debug = false;

// Function prototypes
void setup();
void loop();
int getCommand();
int insertCard(int card);
void removeCard();
int updateDisplay(int digit);
void printCardStatus();
byte getCardStatus(int card);
void toggleDebug();
void debug_print(String msg);
void usage();

void setup()
{
    // Set up pins.
    pinMode(mux_en_pin, OUTPUT);
    pinMode(mux_a0_pin, OUTPUT);
    pinMode(mux_a1_pin, OUTPUT);
    pinMode(mux_a2_pin, OUTPUT);
    pinMode(display_select_pin, OUTPUT);
    pinMode(socket_switch_select_pin, OUTPUT);

    // Set SPI slave select pins high to ignore master.  We will
    // enable SPI devices as needed.
    digitalWrite(display_select_pin, HIGH);
    digitalWrite(socket_switch_select_pin, HIGH);

    // Start the SPI library.
    SPI.begin();

    // Start with no card inserted.
    removeCard();

    // Set up the serial port.
    Serial.begin(9600);
}

void loop()
{
    // Attempt to get a command from the serial port
    if (getCommand() == 0) {
        debug_print(String("Received command \"" + String(command) + "\""));
        if (strcmp(command, CMD_CARD_1) == 0) {
            insertCard(1);
        } else if (strcmp(command, CMD_CARD_2) == 0) {
            insertCard(2);
        } else if (strcmp(command, CMD_CARD_3) == 0) {
            insertCard(3);
        } else if (strcmp(command, CMD_CARD_4) == 0) {
            insertCard(4);
        } else if (strcmp(command, CMD_CARD_5) == 0) {
            insertCard(5);
        } else if (strcmp(command, CMD_CARD_6) == 0) {
            insertCard(6);
        } else if (strcmp(command, CMD_CARD_7) == 0) {
            insertCard(7);
        } else if (strcmp(command, CMD_CARD_8) == 0) {
            insertCard(8);
        } else if (strcmp(command, CMD_REMOVE_CARD) == 0) {
            removeCard();
        } else if (strcmp(command, CMD_STATUS) == 0) {
            printCardStatus();
        } else if (strcmp(command, CMD_HELP) == 0) {
            usage();
        } else if (strcmp(command, CMD_DEBUG) == 0) {
            toggleDebug();
        } else {
            Serial.println(ERR_UNKNOWN_CMD);
        }

        // Clear the previous command
        command[0] = '\0';
    }
}

// getCommand()
//
// Get a command from the serial port, checking for a proper envelope and length.
//
// Returns:
//          0 - If we received a properly enveloped command.
//   Non-zero - If we received an illegally formatted command.  A more
//              detailed error code will be returned via serial.
//
int getCommand()
{
    int rc = 1;
    char inbyte = 0;
    int  command_length = 0;

    if (Serial.available() > 0) {
        inbyte = Serial.read();

        // Make sure the command start sequence is present.
        if (inbyte == CMD_PREFIX) {
            while ((inbyte != CMD_TERM) && (command_length <= CMD_MAX_LEN)) {
                inbyte = Serial.read();
                if ((inbyte > 0) && (inbyte != CMD_TERM)) {
                    command[command_length] = inbyte;
                    command_length++;
                }
            }

            // See if we exceeded the maximum command length.
            if (inbyte != CMD_TERM) {
                Serial.println(ERR_CMDLEN);
                command[0] = '\0';
            } else {
                // Terminate the command string.
                command[command_length] = '\0';
                rc = 0;
            }
        } else {
            // Illegally formatted command or garbage (protocol error).
            Serial.println(ERR_PROTOCOL);
        }
    }

    return rc;
}

// insertCard()
//
// Inserts the specified card.  If another card is already inserted, it will be removed.
//
// One of the card sockets is switched to the card reader output by controlling
// a set of MAX4638 8:1 analog multiplexor ICs.  There is one mux IC per card contact.
// The mux logic pins are tied together in parallel so that they are switched at the
// same time.  This allows us to control all of the mux ICs using only 4 pins.  The
// switching logic uses the following truth table:
//
//     --------------------------------
//     | A2  | A1  | A0  | EN  |  ON  |
//     --------------------------------
//     |  0  |  0  |  0  |  0  | NONE |
//     --------------------------------
//     |  0  |  0  |  0  |  1  |  NO1 |
//     --------------------------------
//     |  0  |  0  |  1  |  1  |  NO2 |
//     --------------------------------
//     |  0  |  1  |  0  |  1  |  NO3 |
//     --------------------------------
//     |  0  |  1  |  1  |  1  |  NO4 |
//     --------------------------------
//     |  1  |  0  |  0  |  1  |  NO5 |
//     --------------------------------
//     |  1  |  0  |  1  |  1  |  NO6 |
//     --------------------------------
//     |  1  |  1  |  0  |  1  |  NO7 |
//     --------------------------------
//     |  1  |  1  |  1  |  1  |  NO8 |
//     --------------------------------
//
// Parameters:
//     card - The card number to insert (1-8).
//
// Returns:
//          0 - Success.
//   Non-zero - If we had some problem inserting the card.  A more
//              detailed error code will be returned via serial.
int insertCard(int card)
{
    // Check if the requested card is actually present.  If not, return
    // ERR_NOCARD via serial and don't do any switching.
    if (!getCardStatus(card)) {
        Serial.println(ERR_NOCARD);
        return 1;
    }

    // Set the logic pins to select the requested card according to
    // the truth table.  We disable the muxes first to ensure we switch
    // directly to the requested card in cases where we have to change
    // the state of multiple pins.
    switch(card) {
        case 1:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, LOW);
            digitalWrite(mux_a1_pin, LOW);
            digitalWrite(mux_a0_pin, LOW);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 2:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, LOW);
            digitalWrite(mux_a1_pin, LOW);
            digitalWrite(mux_a0_pin, HIGH);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 3:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, LOW);
            digitalWrite(mux_a1_pin, HIGH);
            digitalWrite(mux_a0_pin, LOW);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 4:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, LOW);
            digitalWrite(mux_a1_pin, HIGH);
            digitalWrite(mux_a0_pin, HIGH);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 5:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, HIGH);
            digitalWrite(mux_a1_pin, LOW);
            digitalWrite(mux_a0_pin, LOW);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 6:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, HIGH);
            digitalWrite(mux_a1_pin, LOW);
            digitalWrite(mux_a0_pin, HIGH);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 7:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, HIGH);
            digitalWrite(mux_a1_pin, HIGH);
            digitalWrite(mux_a0_pin, LOW);
            digitalWrite(mux_en_pin, HIGH);
            break;
        case 8:
            digitalWrite(mux_en_pin, LOW);
            digitalWrite(mux_a2_pin, HIGH);
            digitalWrite(mux_a1_pin, HIGH);
            digitalWrite(mux_a0_pin, HIGH);
            digitalWrite(mux_en_pin, HIGH);
            break;
        default:
            debug_print(String("Unexpected card in insertCard(): " + String(card)));
            return 1;
        break;
    }

    // Update the display to show the inserted card number.
    updateDisplay(card);
    debug_print(String("Inserted card " + String(card)));
    inserted_card = card;

    // Return our serial response.
    Serial.println(RESP_OK);

    return 0;
}

// removeCard()
//
// Remove the inserted card.  If a card is not inserted,
// this is just a no-op.
//
// We "remove" a card be disabling the multiplexor ICs by setting
// their enable pin to low.
//
void removeCard()
{
    digitalWrite(mux_en_pin, LOW);
    debug_print(String("Removed card " + String(inserted_card)));
    inserted_card = 0;

    // Blank the display
    updateDisplay(-1);
    Serial.println(RESP_OK);
}

// updateDisplay()
//
// Updates the display to the requested digit.
//
// The display is a 7-segment display controlled via a SN74HC595 shift
// register, which we control via SPI.  We send the bits in least-significant
// bit order, meaning that output 'A' of the shift register is controlled by
// the LSB and output 'H' is controlled by the MSB.  The shift register
// outputs are connected to the 7-segment display as follows:
//
//       A
//     -----
//   B |   | C
//   D -----
//   E |   | F
//     -----
//       G
//
// Additionally, there is an LED for a decimal point, which is controlled by
// output 'H' of the shift register.
//
// Parameters:
//     digit - Digit to display.  Valid values are 0-9.  A value
//             of -1 will cause the display to be cleared.
//
// Returns:
//     0 - Success
//     Non-zero - Error due to invalid digit parameter.
//
int updateDisplay(int digit)
{
    int rc = 0;

    // Start a SPI transaction with a max sped of 20MHz.
    SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));

    // Select the display device.
    digitalWrite(display_select_pin, LOW);

    // Display the requested digit by turning on the proper
    // LED segments.
    if ((digit >= 0) && (digit <= 9)) {
        SPI.transfer(display_digits[digit]);
    } else if(digit == -1) {
        // Blank the display, but leave the decimal point LED
        // on as a power indicator.
        SPI.transfer(0x7F);
    } else {
        debug_print(String("Unexpected digit in updateDisplay(): " + String(digit)));
        rc = 1;
    }

    // De-select the display device.  This rising edge pulse will trigger
    // an update to the actual display based off of the shift register contents.
    digitalWrite(display_select_pin, HIGH);

    // End the SPI transaction.
    SPI.endTransaction();

    if (rc == 0) {
        debug_print(String("Updated display to  " + String(digit)));
    }

    return rc;
}

// printCardStatus()
//
// Print the status to the serial port.  This includes which card socket
// is currently "inserted", along with status on which card sockets have
// an actual card present.
//
// The status is printed via serial as a JSON object.  It is
// comprised of two attributes.  The "current" attribute contains
// the number of the currently selected card.  The "present" attribute
// contains an array containing the ascending card socket numbers that
// have a card present.  Here is an example where card 4 is currently
// selected, and card sockets 1-6 have cards present:
//
//     {"current":4,"present":[1,2,3,4,5,6]}
//
// If no card is currently selected, the "current" card will be reported
// as 0.
//
void printCardStatus()
{
    int i = 0;
    int need_comma = 0;
    byte status = 0;
    String status_json = "{\"current\":";

    // Add the currently inserted card to the status.
    status_json += inserted_card;
    status_json += ",\"present\":[";

    // Get the status of all card sockets.
    status = getCardStatus(0);

    // Add any present cards to the JSON array.
    for (i = 1; i <=8; i++) {
        if ((status >> (i - 1)) & 1) {
            if (need_comma) {
                status_json += ",";
            }
            status_json += i;
            need_comma = 1;
        }
    }

    // Terminate the JSON status.
    status_json += "]}";

    // Return the status via serial.
    Serial.println(status_json);
}

// getCardStatus()
//
// Check which card sockets actually have cards inserted.
//
// Each card socket has a switch, which we read via a SN74HC165 shift
// register that we control via SPI.  This allows us to read all 8
// switches at once without taking up 8 input pins.
//
// Paramters:
//   card - The card socket to get the status of.  Valid values
//          are 0-8.  If card is 0, we check the status of all
//          card sockets.
//
// Returns:
//   status - A byte indicating the status for the requested
//            card sockets.  If a single card socket is being
//            checked, this byte will be 0x01 if a card is
//            inserted, and 0x00 if the socket is empty.  If
//            all card sockets are being checked, each bit in
//            the returned byte will represent the status of
//            its associated card socket.  Card socket 1 is
//            represented by the LSB, and card socket 8 is
//            represented by the MSB.
//
byte getCardStatus(int card)
{
    byte status = 0;

    // Start a SPI transaction with a max sped of 20MHz.
    SPI.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0));

    // Pulse the PISO register IC to make it load the card
    // socket switch values.
    digitalWrite(socket_switch_select_pin, LOW);
    delayMicroseconds(20);
    digitalWrite(socket_switch_select_pin, HIGH);

    // Retrieve the switch values via serial.
    status = SPI.transfer(0);
    debug_print(String("Received status: " + String(status)));

    // End the SPI transaction.
    SPI.endTransaction();

    // If we're checking the status of a single card, adjust the
    // returned status to be 1 or 0.
    if ((card >= 1) && (card <= 8)) {
        status = (status >> (card - 1)) & 1;
    }

    return status;
}

// toggleDebug()
//
// Enables or disables debugging serial output.
//
void toggleDebug()
{
    debug = !debug;

    if (debug) {
        Serial.println(RESP_DBG_ON);
    } else {
        Serial.println(RESP_DBG_OFF);
    }
}

// debug_print()
//
// Prints debug message to serial port if debugging output is enabled.
//
// Parameters:
//   msg - The message to print.  A newline will be added automatically.
//
void debug_print(String msg)
{
    if (debug) {
        Serial.print(LOG_DBG_PREFIX);
        Serial.println(msg);
    }
}

// usage()
//
// Prints usage details to serial port
//
void usage()
{
    Serial.println("--- Smart Card Removinator (v0.1) ---");
    Serial.println("Command Format:");
    Serial.print("\t");
    Serial.print("Prefix:");
    Serial.print("\t\t");
    Serial.println("#");
    Serial.print("\t");
    Serial.print("Terminator:");
    Serial.print("\t");
    Serial.println("\\r");
    Serial.println("Commands:");
    Serial.print("\t");
    Serial.print(CMD_CARD_1);
    Serial.print("\t");
    Serial.println("Insert card 1");
    Serial.print("\t");
    Serial.print(CMD_CARD_2);
    Serial.print("\t");
    Serial.println("Insert card 2");
    Serial.print("\t");
    Serial.print(CMD_CARD_3);
    Serial.print("\t");
    Serial.println("Insert card 3");
    Serial.print("\t");
    Serial.print(CMD_CARD_4);
    Serial.print("\t");
    Serial.println("Insert card 4");
    Serial.print("\t");
    Serial.print(CMD_CARD_5);
    Serial.print("\t");
    Serial.println("Insert card 5");
    Serial.print("\t");
    Serial.print(CMD_CARD_6);
    Serial.print("\t");
    Serial.println("Insert card 6");
    Serial.print("\t");
    Serial.print(CMD_CARD_7);
    Serial.print("\t");
    Serial.println("Insert card 7");
    Serial.print("\t");
    Serial.print(CMD_CARD_8);
    Serial.print("\t");
    Serial.println("Insert card 8");
    Serial.print("\t");
    Serial.print(CMD_REMOVE_CARD);
    Serial.print("\t");
    Serial.println("Remove inserted card");
    Serial.print("\t");
    Serial.print(CMD_STATUS);
    Serial.print("\t");
    Serial.println("Return card socket status");
    Serial.print("\t");
    Serial.print(CMD_DEBUG);
    Serial.print("\t");
    Serial.println("Toggle debugging output");
    Serial.print("\t");
    Serial.print(CMD_HELP);
    Serial.print("\t");
    Serial.println("Show usage information");
}

error: pathspec 'firmware/removinator.ino' did not match any file(s) known to git


update

update

error: pathspec 'Photon' did not match any file(s) known to git
error: pathspec 'based/code/ProbeCube_pc_v099b0224.ino' did not match any file(s) known to git


Added MidiDump library example Sketch

Added MidiDump library example Sketch

#include <MidiFileStream.h>
#include <SD.h>

/*
 * Example use of the MidiFileStream library
 * by reading one file from an SD card.
 *
 * This example app is placed in the public domain by its author,
 * Bradford Needham (@bneedhamia, https://www.needhamia.com )
 */

/*
 * Hardware: An Arduino Mega 2560
 *  plus a Sparkfun TransmogriSheild
 *  plus a Sparkfun Wifi CC3000 Shield
 *
 * Or you can use any Arduino plus any shield that supports
 * an SD card. Make sure that pinSelectSD (below) is correct
 * for the card.
 */

/*
 * To operate:
 * 1) Copy a Midi file to the SD card.
 * 2) Change fName (below) to be the name of that Midi file (8.3 format)
 * 3) Download and run this Sketch
 * 4) Open the Serial Monitor at 115200 baud.
 * The tracks and events from the file should be printed on the screen.
 */

const int pinSelectSD = 8; // Sparkfun SD shield Chip Select pin.
const int pinLed = 13;     // the Arduino LED pin

char fName[] = "JOYWORLD.MID"; // The SD card Midi file to read.

boolean errorOccurred;  // if true, there's a problem.
boolean isFinished;     // if true, we successfully finished reading the file.

MidiFileStream midiFile; // the current Midi file being read.
File file;               // the underlying SD card file.

void setup() {
  Serial.begin(115200);

  // If the setup succeeds, we'll update errorOccurred.
  errorOccurred = true;
  isFinished = false;

  pinMode(pinSelectSD, OUTPUT);
  pinMode(pinLed, OUTPUT);

  // Setup the SD card

  Serial.println("Calling SD.begin()...");
  if (!SD.begin(pinSelectSD)) {
    Serial.println("SD.begin() failed. Check: ");
    Serial.println("  Card insertion,");
    Serial.println("  SD shield I/O pins and chip select,");
    Serial.println("  Card formatting.");
    return;
  }
  Serial.println("...succeeded.");

  // Open the file to read

  file = SD.open(fName, FILE_READ);
  if (!file) {
    Serial.print("Failed to open SD card file ");
    Serial.println(fName);
    Serial.println("Does that file exist?");
    return;
  }

  /*
   * Read the Midi header from that file
   * and prepare to read Midi events from that file.
   */

  if (!midiFile.begin(file)) {
    Serial.print("Failed to open Midi file: ");
    Serial.println(fName);
    Serial.print("Check: is it a Midi-format file?");

    // Clean up
    midiFile.end();
    file.close();

    return;
  }

  // Say what the Midi Header told us.
  Serial.print("Midi file format: ");
  Serial.println(midiFile.getFormat());
  Serial.print("Number of tracks: ");
  Serial.println(midiFile.getNumTracks());
  Serial.print("Ticks per beat: ");
  Serial.println(midiFile.getTicksPerBeat());

  // Open the first track of the file.
  if (midiFile.openChunk() != CT_MTRK) {
    Serial.println("Failed to open the first track of the file.");

    // Clean up
    midiFile.end();
    file.close();

    return;
  }

  // remember that everything is ok so far.
  errorOccurred = false;

}

void loop() {
  // If we're finished reading, do nothing.
  if (isFinished) {
    return;
  }

  // If there is a problem, just blink the LED.
  if (errorOccurred) {
    if ((millis() % 1000) < 500) {
      digitalWrite(pinLed, HIGH);
    } else {
      digitalWrite(pinLed, LOW);
    }

    return;
  }

  // read the next Midi event from the file.
  event_t eventType = midiFile.readEvent();
  if (eventType == ET_END) {

    // The track has ended; open the next track.
    chunk_t chunkType = midiFile.openChunk();
    if (chunkType != CT_MTRK) {
      if (chunkType == CT_END) {
        Serial.println("File ended normally.");

        // Clean up
        midiFile.end();
        file.close();

        isFinished = true;
        return;
      }

      // File error: Chunk is not a track.
      Serial.println("Failed to open file track.");

      // Clean up
      midiFile.end();
      file.close();

      errorOccurred = true;
      return;
    }

    // Successfully opened the track
    // loop again to read the next event.

    return;
  }

  // Say something about this event

  Serial.print("delay ");
  Serial.print(midiFile.getEventDeltaTicks());
  Serial.println(" ticks.");

  if (eventType == ET_TEMPO) {
    Serial.print("New Tempo: ");
    Serial.print(midiFile.getEventDataP()->tempo.uSecPerBeat);
    Serial.println(" microseconds per beat.");

    return;
  }

  if (eventType == ET_END_TRACK) {
    Serial.println("End of Track event.");

    return;
  }

  if (eventType == ET_CHANNEL) {
    char code = midiFile.getEventDataP()->channel.code;

    if (code == CH_NOTE_ON) {
      Serial.print("Note On: Midi note number ");
      Serial.println(midiFile.getEventDataP()->channel.param1);

      return;
    }

    if (code == CH_NOTE_OFF) {
      Serial.print("Note Off: Midi note number ");
      Serial.println(midiFile.getEventDataP()->channel.param1);

      return;
    }

    // Otherwise, it's a Channel event that we don't care about
    // Ignore it.

    return;
  }

  // Otherwise, it's an event we don't care about.
  // Ignore it.

  // return;

}

error: pathspec 'examples/MidiDump/MidiDump.ino' did not match any file(s) known to git


Gather and display all sensor data

Gather and display all sensor data

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/recursinging/ruitar.git/'


Create serial.ino

Create serial.ino

connected to sensors

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

/*
 * The setup function. We only start the sensors here
 */
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
}

/*
 * Main function, get and show the temperature
 */
void loop(void)
{
  sensors.requestTemperatures(); // Send the command to get temperatures
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  Serial.println(sensors.getTempFByIndex(0));
  delay(5000);
}

error: pathspec 'serial.ino' did not match any file(s) known to git


update the code

update the code

/*********************************************************************
Guigur 2016
*********************************************************************/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <NewPing.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
NewPing sonar(12, 11, 500); // trigger, echo, max

void displaySensorDetails(void)
{
  sensor_t sensor;
  mag.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" uT");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" uT");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" uT");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void setup()
{
  Serial.begin(115200);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  //addr on the i2c bus
  if(!mag.begin())
  {
    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
    while(1);
  }
}

void loop()
{
  display.clearDisplay();
  display.setCursor(0,0);

  Serial.print("Distance: ");
  Serial.print(sonar.ping_cm());
  Serial.println("cm");

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("Distance");
  display.print(sonar.ping_cm(), DEC);
  display.println(" cm");
  display.display();
  delay(50);
}

error: pathspec 'hardware/IOT_BJTU.ino' did not match any file(s) known to git


first steps

first steps

nothing really tested but it's a start

/*
* Gear Indicator
* Could be used alone or with Arduino DataLogger
* Some useful information about Aprilia RSV/SL bikes work: (See: http://www.aprilia-v60.com/index.php?topic=262315)
* - Speed sensor: purple/green wire=Vcc ~ 9V ? / grey/white: signal ~6.5V, falling to 0V
* - Engine pulses/revolution: 3 if read from the dashboard wire
* - Engine pulses/revolution: 6 if crank shaft sensor is used
* - Wheel pulses/revolution: 5
*/

#define ENGINE_PULSES_PER_REVOLUTION 3
#define WHEEL_PULSES_PER_REVOLUTION 5

#define TIME_LAPSE 100

volatile byte engine_pulses;
volatile byte wheel_pulses;

unsigned int engine_rpm;
unsigned int wheel_rpm;
unsigned float ratio;

unsigned long lastmillis;

void setup() {
  Serial.begin(9600);

  attachInterrupt(0, rpm_counter, FALLING);
  attachInterrupt(1, speed_counter, FALLING);

  engine_pulses = 0;
  wheel_pulses = 0;
  engine_rpm = 0;
  wheel_rpm = 0;
  ratio = 0;

  lastmillis = 0;
}

/**
 * Every n-th ms, measure the engine revolutions per minutes as well as the rear wheel revolutions per minutes
 * Then, measure the ratio between the two in order to determine which gear is currently used.
 * Write theses values in a file stored on the SD card
 * Update the screen (LCD will be used during the tests, then a 7-segments display)
 * Send all the data using I2C protocol
 */
void loop() {

  long current_time_lapse = millis() - lastmillis;
  if (current_time_lapse >= TIME_LAPSE) {
    detachInterrupt(0);
    detachInterrupt(1);

    engine_rpm = (60/ENGINE_PULSES_PER_REVOLUTION)*1000/(current_time_lapse) * engine_pulses;
    wheel_rpm = (60/WHEEL_PULSES_PER_REVOLUTION)*1000/(current_time_lapse) * wheel_pulses;
    ratio = engine_rpm/wheel_rpm;
    engine_pulses = 0;
    wheel_pulses = 0;

    lastmillis = millis();

    attachInterrupt(0, rpm_counter, FALLING);
    attachInterrupt(1, speed_counter, FALLING);
  }

}
void rpm_counter() {
  engine_pulses++;
}

void speed_counter() {
  wheel_pulses++;
}

error: pathspec 'sketches/gear_indicator/gear_indicator.ino' did not match any file(s) known to git


Add: example to receive all frames and print all fields id/type/data

/*
 * demo: CAN-BUS Shield, receive all frames and print all fields id/type/data
 * to receive frame fastly, a poll in loop() is required.
 *
 * Copyright (C) 2020 Seeed Technology Co.,Ltd.
 */
#include <SPI.h>

/*SAMD core*/
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    #define SERIAL SerialUSB
#else
    #define SERIAL Serial
#endif

#define CAN_2515
// #define CAN_2518FD

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10

// Set SPI CS Pin according to your hardware
// For Wio Terminal w/ MCP2518FD RPi Hat：
// Channel 0 SPI_CS Pin: BCM 8
// Channel 1 SPI_CS Pin: BCM 7
// Interupt Pin: BCM25
// *****************************************
// For Arduino MCP2515 Hat:
// SPI_CS Pin: D9

#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#define MAX_DATA_SIZE 64
#endif

#ifdef CAN_2515
#include "mcp2515_can.h"
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#define MAX_DATA_SIZE 8
#endif

void setup() {
    SERIAL.begin(115200);

#ifdef CAN_2518FD
    while (0 != CAN.begin((byte)CAN_500K_1M)) {            // init can bus : baudrate = 500k
#else
    while (CAN_OK != CAN.begin(CAN_500KBPS)) {             // init can bus : baudrate = 500k
#endif
        SERIAL.println("CAN BUS Shield init fail");
        SERIAL.println(" Init CAN BUS Shield again");
        delay(100);
    }
    SERIAL.println("CAN BUS Shield init ok!");
}

uint32_t id;
uint8_t  type; // bit0: ext, bit1: rtr
uint8_t  len;
byte cdata[MAX_DATA_SIZE] = {0};

void loop() {
    // check if data coming
    if (CAN_MSGAVAIL != CAN.checkReceive()) {
        return;
    }

    char prbuf[0x40];
    int i, n;

    unsigned long t = millis();
    // read data, len: data length, buf: data buf
    CAN.readMsgBuf(&len, cdata);

    id = CAN.getCanId();
    type = (CAN.isExtendedFrame() << 0) |
           (CAN.isRemoteRequest() << 1);
    /*
     * MCP2515(or this driver) could not handle properly
     * the data carried by remote frame
     */

    n = sprintf(prbuf, "%04lu.%03d ", t / 1000, int(t % 1000));
    /* Displayed type:
     *
     * 0x00: standard data frame
     * 0x02: extended data frame
     * 0x30: standard remote frame
     * 0x32: extended remote frame
     */
    static const byte type2[] = {0x00, 0x02, 0x30, 0x32};
    n += sprintf(prbuf + n, "RX: [%08lX](%02X) ", (unsigned long)id, type2[type]);
    // n += sprintf(prbuf, "RX: [%08lX](%02X) ", id, type);

    for (i = 0; i < len; i++) {
        n += sprintf(prbuf + n, "%02X ", cdata[i]);
    }
    SERIAL.println(prbuf);
}
// END FILE

error: pathspec 'examples/receive_monitor/receive_monitor.ino' did not match any file(s) known to git


Created a new overall project sketch that utilizes the new gyro (not yet tested)

#include <Wire.h>

// Masking Defs
#define BIT_MASK 8191 // 13 bits, all ones
#define EIGHT_BIT_MAX 255 // 8 bits, all ones, the maximum value the LED would take (255), used for flipping ranges
#define ABS_MASK 32767 // 15 bits, all ones, && with 16 bit signed integer to take off sign bit
#define QUARTER ABS_MASK >> 2 // 15 bits all ones divided by 4
#define HALF ABS_MASK >> 1 // 15 bits all ones divided by 2
#define THREE_QUARTER QUARTER + HALF // summed together to produce 3/4
#define SHIFT_NUM 6 // right shifting the masked accelerometer data by this number will change the range to 0 -> 127

#define r 10
#define g 12
#define b 9

#define ITG3701_CONFIG           0x1A
#define ITG3701_GYRO_CONFIG      0x1B
#define ITG3701_INT_PIN_CFG      0x37
#define ITG3701_INT_ENABLE       0x38
#define ITG3701_GYRO_ZOUT_H      0x47
#define ITG3701_GYRO_ZOUT_L      0x48
#define ITG3701_USER_CTRL        0x6A
#define ITG3701_PWR_MGMT_1       0x6B // Device defaults to the SLEEP mode
#define ITG3701_PWR_MGMT_2       0x6C
#define ITG3701_WHO_AM_I         0x75 // Should return 0x68
#define ITG3701_ADDRESS 0x68

long sum;
int accel_in = 0;
int masked_in;
int calVal;  // Gyroscope DC Offset Calibration Value

void setup()
{
  pinMode(r,OUTPUT);
  pinMode(g,OUTPUT);
  pinMode(b,OUTPUT);
  Wire.begin();
  initGyro();
}

void loop()
{
  sum = 0;
  for(int i = 0; i < 8; i++)
  { sum = sum + readGyro();
    delay(1);
  }
  sum = sum >> 3;
  accel_in = (int)sum;

masked_in = accel_in & BIT_MASK; // 13 bit mask of accelerometer data

if(accel_in < QUARTER){ // first quarter of accelerometer range
analogWrite(r,0);
analogWrite(g,masked_in >> SHIFT_NUM); // green ranges 0 -> 127
analogWrite(b,EIGHT_BIT_MAX - ( masked_in >> SHIFT_NUM)); // blue ranges 255 -> 128
}
else if(accel_in < HALF){ // second quarter of accelerometer range
analogWrite(r,0);
analogWrite(g,(EIGHT_BIT_MAX >> 1) + (masked_in >> SHIFT_NUM)); // green ranges 128 -> 255
analogWrite(b,(EIGHT_BIT_MAX >> 1) - (masked_in >> SHIFT_NUM)); // blue ranges 127 -> 0
}
else if(accel_in < THREE_QUARTER){// third quarter of accelerometer range
analogWrite(r,masked_in >> SHIFT_NUM); // red ranges 0 -> 127
analogWrite(g,EIGHT_BIT_MAX - ( masked_in >> SHIFT_NUM)); // green ranges 255 -> 128
analogWrite(b,0);
}
else{ // final quarter of accelerometer range
analogWrite(r,(EIGHT_BIT_MAX >> 1) + (masked_in >> SHIFT_NUM)); // red ranges 128 -> 255
analogWrite(g,(EIGHT_BIT_MAX >> 1) - (masked_in >> SHIFT_NUM)); // green ranges 127 -> 0
analogWrite(b,0);
}

}

int readGyro(void)
{
  byte z_High = read8(ITG3701_GYRO_ZOUT_H);
  byte z_Low = read8(ITG3701_GYRO_ZOUT_L);

  return abs(((int)z_High << 8 | z_Low)-calVal);
}

void initGyro(void)
{
  write8(ITG3701_PWR_MGMT_1,0x81);  // Reset the device to put all registers back to default values
  delay(100);
  write8(ITG3701_PWR_MGMT_1,0x09);  // Disable the temp sensor and set the PLL as the clock source
  write8(ITG3701_PWR_MGMT_2,0x06);  // Disable the x and y axis
  write8(ITG3701_INT_ENABLE,0x01);  // Enable the data ready interrupt
  write8(ITG3701_INT_PIN_CFG,0x20); // Set interrupt status bits to clear on a read of INT_STATUS (also set INT to latch active high push pull and disable F_SYNC)
  write8(ITG3701_GYRO_CONFIG,0x18); // Set the FSR to 4000 dps
  write8(ITG3701_CONFIG,0x00);      // Set sample rate to 8kHz and the bandwidth to 250Hz (delay 0.97ms)
  delay(100);
  long sum = 0;
  for(int i = 128; i > 0; i--)  // Take 128 readings from the Gyro
  {
    sum = sum + ((int)read8(ITG3701_GYRO_ZOUT_H) << 8 | read8(ITG3701_GYRO_ZOUT_L));
    delay(1);
  }
  sum = sum >> 7;  // Divide by 128
  calVal = sum;    // Set the global cal value to match calibration

}

byte read8(byte reg)
{ byte value;
  Wire.beginTransmission(ITG3701_ADDRESS);
  Wire.write((byte)reg);
  Wire.endTransmission();
  Wire.requestFrom(ITG3701_ADDRESS, (byte)1);
  value = Wire.read();
  Wire.endTransmission();

  return value;
}

void write8(byte reg, byte value)
{
  Wire.beginTransmission(ITG3701_ADDRESS);
  Wire.write((byte)reg);
  Wire.write(value);
  Wire.endTransmission();
}

error: pathspec 'SpinCode_2p0/SpinCode_2p0.ino' did not match any file(s) known to git


register durcheinander

register durcheinander

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/trinamic/T-Bone.git/'


Add files via upload

Add files via upload

Initial commit

int lastInterruptIndex = -1;
char InterruptLog[1024] = {0};

void setup()
{
  Serial.begin(9600);
  Serial.println("i am 12 and wat is this");
  InitialiseIO();
  InitialiseInterrupt();
  Serial.println("Jonathan is blind");
}

void loop() {
  /* Nothing to do: the program jumps automatically to Interrupt Service Routine "blink"
   in case of a hardware interrupt  */
   int wut = 0;

   delay(1000);
   for( int i = 0; i < lastInterruptIndex; i++){
    Serial.println(InterruptLog[i], HEX);
   }

   wut = analogRead(A0);
   Serial.println(A0);
}

void InitialiseIO(){
  /*pinMode(A0, INPUT);     // Pin A0 is input to which a switch is connected
  digitalWrite(A0, HIGH);   // Configure internal pull-up resistor
  pinMode(A1, INPUT);    // Pin A1 is input to which a switch is connected
  digitalWrite(A1, HIGH);   // Configure internal pull-up resistor
  pinMode(A2, INPUT);    // Pin A2 is input to which a switch is connected
  digitalWrite(A2, HIGH);      // Configure internal pull-up resistor
  */
}

void InitialiseInterrupt(){
  cli();    // switch interrupts off while messing with their settings
  PCICR =0x02;          // Enable PCINT1 interrupt
  PCMSK1 = 0b00000111;
  sei();    // turn interrupts back on
}

ISR(PCINT1_vect) {    // Interrupt service routine. Every single PCINT8..14 (=ADC0..5) change
            // will generate an interrupt: but this will always be the same interrupt routine
  volatile char store = 0x0;

  if (digitalRead(A0)==0){
    store += 0x1;
    Serial.println("A0");
  }

  if (digitalRead(A1)==0){
    store += 0x2;;
    Serial.println("A1");
  }

  if (digitalRead(A2)==0) {
    store += 0x4;
    Serial.println("A2");
  }

  if (store > 0x0){
    lastInterruptIndex++;
    InterruptLog[lastInterruptIndex] = store;
  }
}

error: pathspec 'src/sketch_jan20a.ino' did not match any file(s) known to git


initial code

initial code

#define LIN_OUT 1 // use the log output function
#define FFT_N 128 // set number of FFT points

#include <math.h>
#include <FFT.h>
#include "LPD8806.h"
#include "SPI.h"

int peak_index;
int max_value;
int sum_fft;
float frequency;
float SAMPLE_RATE = 9600.0;
int SKIP_MULT = 16;
int MAX_FFT_BIN = 16383;
int brightness_mult;

float base_freak = SAMPLE_RATE / FFT_N / 2;

// Number of RGB LEDs in strand:
int nLEDs = 32;

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 2;
int clockPin = 3;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);

void setup() {
    Serial.begin(9600);
    TIMSK0 = 0;           // turn off timer0 for lower jitter
    ADCSRA = 0xe5;        // set the adc to free running mode
    ADMUX = 0x40;         // use adc0
    DIDR0 = 0x01;         // turn off the digital input for adc0

    // Start up the LED strip
    strip.begin();

    // Update the strip, to start they are all 'off'
    strip.show();
}

void calculateFFT() {
    for (int i = 0 ; i < FFT_N * 2; i += 2) { // save samples
        /*
         * sample at slower rate, minimum sample rate is 9.6 kHz
         * so reduce sample rate by skipping ADC read cycles by
         * SKIP_MULT
         */
        for (int j = 0; j < SKIP_MULT; j++) {
            while(!(ADCSRA & 0x10)); // wait for adc to be ready
            ADCSRA = 0xf5;           // restart adc
        }

        byte m = ADCL;             // fetch adc data
        byte j = ADCH;
        int k = (j << 8) | m;      // form into an int
        k -= 0x0200;               // form into a signed int
        k <<= 6;                   // form into a 16b signed int
        fft_input[i] = k;          // put real data into even bins
        fft_input[i+1] = 0;        // set odd bins to 0
    }
    fft_window();                  // window the data for better frequency response
    fft_reorder();                 // reorder the data before doing the fft
    fft_run();                     // process the data in the fft
    fft_mag_lin();                 // take the output of the fft
}

// Fill the dots progressively along the strip.
void setColor(uint32_t c) {
    int i;

    for (i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c);
        strip.show();
    }
}

void loop() {
    //cli();
    calculateFFT();  // result is placed in fft_log_out
    //sei();

    peak_index = 0;
    max_value = 0;
    sum_fft = 0;

    for (int i=0; i < (FFT_N / 2); i++) {
        if (max_value < fft_lin_out[i]) {
            // peak index determines frequency
            peak_index = i;
            max_value = fft_lin_out[i];
        }
        if (i > 0) {
            // sum of all bins determines brightness
            sum_fft += fft_lin_out[i];
        }
    }

    frequency = (peak_index * (SAMPLE_RATE / SKIP_MULT)) / (FFT_N / 4);
    brightness_mult = floor(95 * max_value / MAX_FFT_BIN);

    if (max_value < 80 || sum_fft < 400 || peak_index == 0) {
        // signal too weak or we got the 1st peak (0Hz), no lights
        setColor(strip.Color(0, 0, 0));
    } else if (frequency > 0 && frequency < base_freak * 2) {
        // red
        setColor(strip.Color(brightness_mult,   0,   0));
    }
    else if (frequency >= base_freak * 2 && frequency < (base_freak * 3)) {
        // yellow
        setColor(strip.Color( brightness_mult, brightness_mult,   0));
    }
    else if (frequency >= base_freak * 3 && frequency < (base_freak * 4)) {
        // green
        setColor(strip.Color(  0, brightness_mult,   0));
    }
    else if (frequency >= base_freak * 4 && frequency < base_freak * 5) {
        // cyan
        setColor(strip.Color(  0, brightness_mult, brightness_mult));
    }
    else if (frequency >= base_freak * 5 && frequency < base_freak * 6) {
        // blue
        setColor(strip.Color(  0,   0, brightness_mult));
    }
    else if (frequency >= base_freak * 6 && frequency < SAMPLE_RATE/4) {
        // violence!!!
        setColor(strip.Color(brightness_mult,   0, brightness_mult));
    }

    Serial.print("FFT sum: ");
    Serial.print(sum_fft);
    Serial.print("\tPeak index: ");
    Serial.print(peak_index);
    Serial.print("\tMax value: ");
    Serial.print(max_value);
    Serial.print("\tFrequency: ");
    Serial.println(frequency);
//    delay(30);
}

error: pathspec 'super_freq.ino' did not match any file(s) known to git


code arduino

code arduino

/*
  3DScan
  H.P.
 */
int Pin0 = 8;
int Pin1 = 9;
int Pin2 = 10;
int Pin3 = 11;
int _step = 0;
int cmd=0;
boolean dir = true;

void setup() {
 Serial.begin(9600);
 pinMode(Pin0, OUTPUT);
 pinMode(Pin1, OUTPUT);
 pinMode(Pin2, OUTPUT);
 pinMode(Pin3, OUTPUT);
 pinMode(13, OUTPUT);
// PIN 13 commands the lasers
}

void loop() {
  if (Serial.available()>0)
  {
    cmd=int(Serial.read())-48;
  //cmd is an integer 0-9
    Serial.println(cmd);
  //feedback a trace of the command
  switch(cmd){
    case 0:
    // lasers OFF
      digitalWrite(13, LOW);
      break;
    case 1:
    // lasers ON
      digitalWrite(13, HIGH);
      break;

    case 4:
    // change direction
      dir=! dir;
      break;

    case 5:
    // 1024 steps for a test
      for (int i=0;i<1024;i++) {
        step();
        delay(10); }
      break;

    case 9:
    // power off
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
     break;

    default:
      step();
  }
  }
}

void step() {
  //implements a step within a 8 steps sequence
   switch(_step){
   case 0:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, HIGH);
   break;
   case 1:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, HIGH);
     digitalWrite(Pin3, HIGH);
   break;
   case 2:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, HIGH);
     digitalWrite(Pin3, LOW);
   break;
   case 3:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, HIGH);
     digitalWrite(Pin2, HIGH);
     digitalWrite(Pin3, LOW);
   break;
   case 4:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, HIGH);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
   case 5:
     digitalWrite(Pin0, HIGH);
     digitalWrite(Pin1, HIGH);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
     case 6:
     digitalWrite(Pin0, HIGH);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
   case 7:
     digitalWrite(Pin0, HIGH);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, HIGH);
   break;
   default:
     digitalWrite(Pin0, LOW);
     digitalWrite(Pin1, LOW);
     digitalWrite(Pin2, LOW);
     digitalWrite(Pin3, LOW);
   break;
 }
 if(dir){
   _step++;
 }else{
   _step--;
 }
 if(_step>7){
   _step=0;
 }
 if(_step<0){
   _step=7;
 }
}

error: pathspec '_3DScan.ino.ino' did not match any file(s) known to git


PrusaLights

PrusaLights

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

const int kLightsOnPin = 2;

const int kNeoPixelsPinA = 4;
const int kNumberOfPixelsA = 7;
const int kNeoPixelsPinB = 3;
const int kNumberOfPixelsB = 7;

Adafruit_NeoPixel pixelsA(kNumberOfPixelsA, kNeoPixelsPinA, NEO_RGBW + NEO_KHZ800);
Adafruit_NeoPixel pixelsB(kNumberOfPixelsB, kNeoPixelsPinB, NEO_RGBW + NEO_KHZ800);

void setup()
{
	Serial.begin(115200);

	pixelsA.begin();
	pixelsA.clear();
	pixelsB.begin();
	pixelsB.clear();

	pinMode(kLightsOnPin, INPUT);

	delay(500);
}

void loop()
{
	bool lightsOn = digitalRead(kLightsOnPin) == HIGH;

	const int kLightsOffValue = 0;
	const int kLightsOnValue = 255;

	if (lightsOn)
	{
		pixelsA.fill(0xffffffff, 0, kNumberOfPixelsA);
		pixelsB.fill(0xffffffff, 0, kNumberOfPixelsB);
	}
	else
	{
		pixelsA.clear();
		pixelsB.clear();
	}

	pixelsA.show();
	pixelsB.show();

	delay(10);
}

error: pathspec 'PrusaLights/PrusaLights.ino' did not match any file(s) known to git


We need blinking and arduino code

We need blinking and arduino code

I hear the web needs more blink

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/caioproiete/illacceptanything.git/'


some update

some update

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/JackBDu/robot-tour-guide.git/'


tes timer

tes timer

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Duke-Medical-Instrumentation/InceptionTI.git/'


Delete Thermal_HUD_bicubic.ino

Delete Thermal_HUD_bicubic.ino

Thermal Imaging HUD code/Thermal_HUD_bicubic/Thermal_HUD_bicubic.ino

error: pathspec 'Thermal' did not match any file(s) known to git
error: pathspec 'Imaging' did not match any file(s) known to git
error: pathspec 'HUD' did not match any file(s) known to git
error: pathspec 'code/Thermal_HUD_bicubic/Thermal_HUD_bicubic.ino' did not match any file(s) known to git


Interrup based dual encoder reader

Interrup based dual encoder reader

/* read a rotary encoder with interrupts
   Encoder hooked up with common to GROUND,
   encoder0PinA to pin 2, encoder0PinB to pin 4 (or pin 3 see below)
   it doesn't matter which encoder pin you use for A or B

   uses Arduino pull-ups on A & B channel outputs
   turning on the pull-ups saves having to hook up resistors
   to the A & B channel outputs

*/

#define encoder0PinA  2
#define encoder0PinB  8

#define encoder1PinA  3
#define encoder1PinB  9

volatile unsigned int encoder0Pos = 0;
volatile unsigned int encoder1Pos = 0;

void setup() {
  pinMode(encoder0PinA, INPUT);
  digitalWrite(encoder0PinA, HIGH);       // turn on pull-up resistor
  pinMode(encoder0PinB, INPUT);
  digitalWrite(encoder0PinB, HIGH);       // turn on pull-up resistor
  attachInterrupt(digitalPinToInterrupt(encoder0PinA), doEncoder0, CHANGE);  // encoder pin on interrupt 0 - pin 2

  pinMode(encoder1PinA, INPUT);
  digitalWrite(encoder1PinA, HIGH);       // turn on pull-up resistor
  pinMode(encoder1PinB, INPUT);
  digitalWrite(encoder1PinB, HIGH);       // turn on pull-up resistor
  attachInterrupt(digitalPinToInterrupt(encoder1PinA), doEncoder1, CHANGE);  // encoder pin on interrupt 0 - pin 2

  Serial.begin (9600);
  Serial.println("start");                // a personal quirk

}

void loop(){
// do some stuff here - the joy of interrupts is that they take care of themselves
  Serial.println (String(encoder0Pos) + "," + String(encoder1Pos));
  delay(100);
}

void doEncoder0() {
  /* If pinA and pinB are both high or both low, it is spinning
   * forward. If they're different, it's going backward.
   *
   * For more information on speeding up this process, see
   * [Reference/PortManipulation], specifically the PIND register.
   */
  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
    encoder0Pos++;
  } else {
    encoder0Pos--;
  }
}

void doEncoder1() {
  /* If pinA and pinB are both high or both low, it is spinning
   * forward. If they're different, it's going backward.
   *
   * For more information on speeding up this process, see
   * [Reference/PortManipulation], specifically the PIND register.
   */
  if (digitalRead(encoder1PinA) == digitalRead(encoder1PinB)) {
    encoder1Pos++;
  } else {
    encoder1Pos--;
  }
}

/* See this expanded function to get a better understanding of the
 * meanings of the four possible (pinA, pinB) value pairs:
 */
void doEncoder_Expanded(){
  if (digitalRead(encoder0PinA) == HIGH) {   // found a low-to-high on channel A
    if (digitalRead(encoder0PinB) == LOW) {  // check channel B to see which way
                                             // encoder is turning
      encoder0Pos = encoder0Pos - 1;         // CCW
    }
    else {
      encoder0Pos = encoder0Pos + 1;         // CW
    }
  }
  else                                        // found a high-to-low on channel A
  {
    if (digitalRead(encoder0PinB) == LOW) {   // check channel B to see which way
                                              // encoder is turning
      encoder0Pos = encoder0Pos + 1;          // CW
    }
    else {
      encoder0Pos = encoder0Pos - 1;          // CCW
    }

  }
  Serial.println (encoder0Pos, DEC);          // debug - remember to comment out
                                              // before final program run
  // you don't want serial slowing down your program if not needed
}

/*  to read the other two transitions - just use another attachInterrupt()
in the setup and duplicate the doEncoder function into say,
doEncoderA and doEncoderB.
You also need to move the other encoder wire over to pin 3 (interrupt 1).
*/

error: pathspec 'encoder_reader/interrupt_encoder_reader/interrupt_encoder_reader.ino' did not match any file(s) known to git


WHAT A BEAUTIFUL ACCIDENT

WHAT A BEAUTIFUL ACCIDENT

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/rosalindfdt/huzzahbadge.git/'


added arduino source code;

added arduino source code;

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/bbolgradov/arduino-laser.git/'


Swap from green to blue

Swap from green to blue

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/mcrosson/arduino_safe_lighting.git/'