ping_zx_bartart.ino

#include <Wire.h>
#include <ZX_Sensor.h>
//#include <NewPing.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Constants
const int ZX_ADDR = 0x10;  // ZX Sensor I2C address

// Global Variables
ZX_Sensor zx_sensor = ZX_Sensor(ZX_ADDR);
uint8_t x_pos;
uint8_t z_pos;

//int potPin = A0;  // potentiometer
//int potVal = 0;

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

#define P1             3
#define P2             4
#define P3             5
#define P4             6
#define P5             7
#define P6             8
#define P7             9
#define NUMPIXELS      1

Adafruit_NeoPixel px1 = Adafruit_NeoPixel(NUMPIXELS, P1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel px2 = Adafruit_NeoPixel(NUMPIXELS, P2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel px3 = Adafruit_NeoPixel(NUMPIXELS, P3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel px4 = Adafruit_NeoPixel(NUMPIXELS, P4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel px5 = Adafruit_NeoPixel(NUMPIXELS, P5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel px6 = Adafruit_NeoPixel(NUMPIXELS, P6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel px7 = Adafruit_NeoPixel(NUMPIXELS, P7, NEO_GRB + NEO_KHZ800);

//NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
int x;
int z;
int p1b = 1;
int p2b = 1;
int p3b = 1;
int p4b = 1;
int p5b = 1;
int p6b = 1;
int p7b = 1;

void setup() {

  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  zx_sensor.init();
  /*
  uint8_t ver;

  if ( zx_sensor.init() ) {
    Serial.println("ZX Sensor initialization complete");
  } else {
    Serial.println("Something went wrong during ZX Sensor init!");
  }

  ver = zx_sensor.getModelVersion();
  if ( ver == ZX_ERROR ) {
    Serial.println("Error reading model version number");
  } else {
    Serial.print("Model version: ");
    Serial.println(ver);
  }
  if ( ver != ZX_MODEL_VER ) {
    Serial.print("Model version needs to be ");
    Serial.print(ZX_MODEL_VER);
    Serial.print(" to work with this library. Stopping.");
    while(1);
  }

  // Read the register map version and ensure the library will work
  ver = zx_sensor.getRegMapVersion();
  if ( ver == ZX_ERROR ) {
    Serial.println("Error reading register map version number");
  } else {
    Serial.print("Register Map Version: ");
    Serial.println(ver);
  }
  if ( ver != ZX_REG_MAP_VER ) {
    Serial.print("Register map version needs to be ");
    Serial.print(ZX_REG_MAP_VER);
    Serial.print(" to work with this library. Stopping.");
    while(1);
  }
  */
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  px1.begin(); // This initializes the NeoPixel library.
  px2.begin();
  px3.begin();
  px4.begin();
  px5.begin();
  px6.begin();
  px7.begin();
}

void loop() {

  // send data via serialport
  // using substring and delimiter
//  if(sonar.ping_cm()){
//    Serial.print("{\"ping\":");
//    Serial.print(sonar.ping_cm());
//    Serial.println("}");
//  }
  if ( zx_sensor.positionAvailable() ) {
    x_pos = zx_sensor.readX();
    if ( x_pos != ZX_ERROR ) {
      Serial.print("{\"x\":");
      Serial.print(x_pos);
      Serial.println("}");
      x = x_pos;
    }
    z_pos = zx_sensor.readZ();
    if ( z_pos != ZX_ERROR ) {
      Serial.print("{\"z\":");
      Serial.print(z_pos);
      Serial.println("}");
      z = z_pos;
    }
  }
//  potVal = analogRead(potPin);
//  Serial.println(potVal);

/*
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");

  // If there is position data available, read and print it
  if ( zx_sensor.positionAvailable() ) {
    x_pos = zx_sensor.readX();
    if ( x_pos != ZX_ERROR ) {
      Serial.print("X: ");
      Serial.print(x_pos);
      Serial.print("Ping: ");
      Serial.println(sonar.ping_cm());
    }
    z_pos = zx_sensor.readZ();
    if ( z_pos != ZX_ERROR ) {
      Serial.print(" Z: ");
      Serial.println(z_pos);
    }
  }
*/
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
 //for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    px1.setPixelColor(0, px1.Color(255,0,255)); // magenta
    px1.show();
    //px1.setBrightness(0);
    px2.setPixelColor(0, px2.Color(0,0,255));   // blue
    px2.show();
    //px2.setBrightness(0);
    px3.setPixelColor(0, px3.Color(0,125,255)); // ocean
    px3.show();
    //px3.setBrightness(0);
    px4.setPixelColor(0, px4.Color(0,255,125)); // turquoise
    px4.show();
    //px4.setBrightness(0);
    px5.setPixelColor(0, px5.Color(0,255,0));   // green
    px5.show();
    //px5.setBrightness(0);
    px6.setPixelColor(0, px6.Color(255,255,0)); // yellow
    px6.show();
    //px6.setBrightness(0);
    px7.setPixelColor(0, px7.Color(255,0,0));   // red
    px7.show();
    //px7.setBrightness(0);
    if(z < 30){
      p1b++; //= 64;
      p2b++; //= 64;
      p3b++; //= 64;
      p4b++; //= 64;
      p5b++; //= 64;
      p6b++; //= 64;
      p7b++; //= 64;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else{
    if(x < 34){
      p1b = 0;
      p2b = 0;
      p3b = 0;
      p4b = 0;
      p5b = 0;
      p6b = 16;
      p7b = 64;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else if(x < 68){
      p1b = 0;
      p2b = 0;
      p3b = 0;
      p4b = 0;
      p5b = 16;
      p6b = 64;
      p7b = 16;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else if(x < 102){
      p1b = 0;
      p2b = 0;
      p3b = 0;
      p4b = 16;
      p5b = 64;
      p6b = 16;
      p7b = 0;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else if(x < 136){
      p1b = 0;
      p2b = 0;
      p3b = 16;
      p4b = 64;
      p5b = 16;
      p6b = 0;
      p7b = 0;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else if(x < 171){
      p1b = 0;
      p2b = 16;
      p3b = 64;
      p4b = 16;
      p5b = 0;
      p6b = 0;
      p7b = 0;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else if(x < 205){
      p1b = 16;
      p2b = 64;
      p3b = 16;
      p4b = 0;
      p5b = 0;
      p6b = 0;
      p7b = 0;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
    else{
      p1b = 64;
      p2b = 16;
      p3b = 0;
      p4b = 0;
      p5b = 0;
      p6b = 0;
      p7b = 0;
      px7.setBrightness(p7b);
      px7.show();
      px6.setBrightness(p6b);
      px6.show();
      px5.setBrightness(p5b);
      px5.show();
      px4.setBrightness(p4b);
      px4.show();
      px3.setBrightness(p3b);
      px3.show();
      px2.setBrightness(p2b);
      px2.show();
      px1.setBrightness(p1b);
      px1.show();
    }
//    if(p1b <= 1){
//      p1b = 0;
//    }
//    else if(p1b >= 63){
//      p1b = 64;
//    }
//    if(p2b <= 1){
//      p2b = 0;
//    }
//    else if(p2b >= 63){
//      p2b = 64;
//    }
//    if(p3b <= 1){
//      p3b = 0;
//    }
//    else if(p3b >= 63){
//      p3b = 64;
//    }
//    if(p4b <= 1){
//      p4b = 0;
//    }
//    else if(p4b >= 63){
//      p4b = 64;
//    }
//    if(p5b <= 1){
//      p5b = 0;
//    }
//    else if(p5b >= 63){
//      p5b = 64;
//    }
//    if(p6b <= 1){
//      p6b = 0;
//    }
//    else if(p6b >= 63){
//      p6b = 64;
//    }
//    if(p7b <= 1){
//      p7b = 0;
//    }
//    else if(p7b >= 63){
//      p7b = 64;
//    }
    }
  //}
}

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


added compass

added compass

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/ocean-x/erikson-1.git/'


initial commit

initial commit

const unsigned int C = 7;
const unsigned int B = 4;
const unsigned int A = 2;
const unsigned int POTS = A0;
const unsigned int NUM_JOINTS = 5;
const float J0 = 170/2;
const float J1 = 170/2;
const float J2 = 170/2;
const float J3 = 170/2;
const float J4 = 45/2;

const float P0_LOWER = 0;
const float P0_UPPER = 0;
const float P1_LOWER = 140;
const float P1_UPPER = 600;
const float P2_LOWER = 50;
const float P2_UPPER = 700;
const float P3_LOWER = 0;
const float P3_UPPER = 0;
const float P4_LOWER = 240;
const float P4_UPPER = 420;

int pot_val = 0;

void muxDigitalWrite(const unsigned int& c, const unsigned int& b, const unsigned int& a) {
  digitalWrite(C, c);
  digitalWrite(B, b);
  digitalWrite(A, a);
}

// MUX: MAX4617CPE
// C B A (A is LSB)
void setMux(const unsigned int& pot_num) {
  switch(pot_num) {
    case 0:
      muxDigitalWrite(0,0,0);
      break;
    case 1:
      muxDigitalWrite(0,0,1);
      break;
    case 2:
      muxDigitalWrite(0,1,0);
      break;
    case 3:
      muxDigitalWrite(0,1,1);
      break;
    case 4:
      muxDigitalWrite(1,0,0);
      break;
    default:
      Serial.println("Invalid pot selection");
  }
}

float getPotValue(const unsigned int& pot_num) {
  setMux(pot_num);
  return analogRead(POTS);
}

float getJointAngle(const unsigned int& joint_num) {
  float joint_val = getPotValue(joint_num);
  switch (joint_num) {
    case 0:
      joint_val = map(joint_val, P0_LOWER, P0_UPPER, J0, -J0);
      break;
    case 1:
      joint_val = map(joint_val, P1_LOWER, P1_UPPER, J1, -J1);
      break;
    case 2:
      joint_val = map(joint_val, P2_LOWER, P2_UPPER, J2, -J2);
      break;
    case 3:
      joint_val = map(joint_val, P3_LOWER, P3_UPPER, J3, -J3);
      break;
    case 4:
      joint_val = map(joint_val, P4_LOWER, P4_UPPER, J4, -J4);
      break;
  }
  return joint_val;
}

void getJointAngle(float* joints) {
  for (unsigned int i = 0; i < NUM_JOINTS - 1; ++i) {
    joints[i] = getJointAngle(i);
  }
}

void setup() {
  Serial.begin(9600);
  pinMode(C, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(A, OUTPUT);
}

void loop() {
  Serial.println("Select a joint (0-4)");
  while (Serial.available() == 0);
  {
    int joint = Serial.parseInt();
    Serial.println(getJointAngle(joint));
  }
  delay(1000);

}

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


Added sketch for FlowSensor

Added sketch for FlowSensor

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


Adds push direction to energy arduino 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/bassjansson/vera.git/'


Added code for gate-alarm

Added code for gate-alarm

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/rniemand/ArduinoProjects.git/'


Create h_sumo_search.ino

Create h_sumo_search.ino

/*
 * autonomous sumo test 1
 * simple h bridge controlling 2-wheel bot
 * HC-SR04 used for object detection
 * objective: search and push
*/

//motor A connected between A01 and A02
//motor B connected between B01 and B02

int STBY = 10; //standby

//Motor A
int PWMA = 3; //Speed control
int AIN1 = 9; //Direction
int AIN2 = 8; //Direction

//Motor B
int PWMB = 5; //Speed control
int BIN1 = 11; //Direction
int BIN2 = 12; //Direction

#define leftEcho 2  // left Echo Pin
#define leftTrig 4  // left Trigger Pin
#define rightEcho 7 // right Echo Pin
#define rightTrig 6 // right Trigger Pin

// POSSIBLY CHANGE THIS FOR ARENA SIZE
int maximumRange = 20; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, leftDistance, rightDistance; // Duration used to calculate distance

boolean found = false;  // used for search()

boolean tagged = false; // used for follow()
int rightDirMod = 0;
int leftDirMod = 0;

void setup(){
  Serial.begin (9600);
  pinMode(STBY, OUTPUT);

  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);

  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);

  pinMode(leftTrig, OUTPUT);
  pinMode(leftEcho, INPUT);
  pinMode(rightTrig, OUTPUT);
  pinMode(rightEcho, INPUT);

  //search();
}

void loop(){
  search();
  follow();
}

void move(int motor, int speed, int direction){
//Move specific motor at speed and direction
//motor: 0 for B 1 for A
//speed: 0 is off, and 255 is full speed
//direction: 0 clockwise, 1 counter-clockwise

  digitalWrite(STBY, HIGH); //disable standby

  boolean inPin1 = LOW;
  boolean inPin2 = HIGH;

  if(direction == 1){
    inPin1 = HIGH;
    inPin2 = LOW;
  }

  if(motor == 1){
    digitalWrite(AIN1, inPin1);
    digitalWrite(AIN2, inPin2);
    analogWrite(PWMA, speed);
  }else{
    digitalWrite(BIN1, inPin1);
    digitalWrite(BIN2, inPin2);
    analogWrite(PWMB, speed);
  }
}

void stop(){
//enable standby
  digitalWrite(STBY, LOW);
}

void calcDistance() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */
 digitalWrite(leftTrig, LOW);
 delayMicroseconds(2);
 digitalWrite(leftTrig, HIGH);
 delayMicroseconds(10);
 digitalWrite(leftTrig, LOW);
 duration = pulseIn(leftEcho, HIGH);
 //Calculate the distance (in cm) based on the speed of sound.
 leftDistance = duration/58.2;

 digitalWrite(rightTrig, LOW);
 delayMicroseconds(2);
 digitalWrite(rightTrig, HIGH);
 delayMicroseconds(10);
 digitalWrite(rightTrig, LOW);
 duration = pulseIn(rightEcho, HIGH);
 //Calculate the distance (in cm) based on the speed of sound.
 rightDistance = duration/58.2;
}

/*
 * spins until it finds an object, then stops
 */
void search() {
  while(!found) {
    // 0 is forward, 1 is backward
    move(1, 128, 1); //right motor
    move(2, 128, 0); //left motor
    calcDistance();
    Serial.println(leftDistance);
    Serial.println(rightDistance);
    delay(10);
    if((leftDistance <= maximumRange && leftDistance >= minimumRange) ||
       (rightDistance <= maximumRange && rightDistance >=minimumRange)) {
        found = true;
        Serial.println("FOUND");
      stop();
      //uncomment for looped testing of search function
      //delay(1000);
      //found = false;
    }
  }
}

void follow() {
  while(!tagged) {
    //happens every loop
    move(1, 128, rightDirMod); //right motor with rightDirMod
    move(2, 128, leftDirMod); //left motor with leftDirMod

    Serial.println(leftDistance);
    Serial.println(rightDistance);

    //change dir
    //0 is forward, 1 is backward
    if((leftDistance - rightDistance) > 10 ) {
      //if right sensor is closer, slight turn right
      rightDirMod = 0;
      leftDirMod = 1;
    } else if((leftDistance - rightDistance) < -10) {
      //if left sensor is closer, slight turn left
      rightDirMod = 1;
      leftDirMod = 0;
    } else {
      rightDirMod = 0;
      leftDirMod = 0;
    }
    calcDistance();
    if((leftDistance <= 5 && leftDistance >= minimumRange) ||
         (rightDistance <= 5 && rightDistance >=minimumRange)) {
          tagged = true;
          Serial.println("GOTCHA");
        stop();
    }
    delay(10);
  }
  while(true) {
    stop();
  }
}

  /*
   * loop
   * move toward object
   *    if left sensor is closer, slight turn left
   *    if right sensor is closer, slight turn right
   *    if both are pretty much same, keep straight
   *    stop when both sensor's distance is lower than 10
   * have a constant for the degree of turn
   *
   * if robot loses sight (sensors output -1, do search again)
   */

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


Add I2C chord messages

Add I2C chord messages

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/mvines/futboard.git/'


Added intial source code

Added intial source code

/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

 This example code is in the public domain.
 */

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}

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


cambiado el nombre del servidor

cambiado el nombre del servidor

error: pathspec 'Arduino' did not match any file(s) known to git
error: pathspec 'Light' did not match any file(s) known to git
error: pathspec 'Control/IoTDimmer.ino' did not match any file(s) known to git


Delete Blink_led.ino

Delete Blink_led.ino

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/wetwot/ArduinoEvent.git/'


tuning. isgood obstacle need to fix

tuning. isgood obstacle need to fix

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


Initial check in of project framework.

Initial check in of project framework.

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/FirstBuild/pizzaduino.git/'


Add files via upload

Add files via upload

Changed the shimmer function to use a single array to contain many important values. Overhauled the entire shimmer function. Changed the timer delay functions slightly. Removed Lightning until I can actually figure out a nice way to implement it. Detailed changelog to come.

// Neopixel Salt Lamp v2.0
// By Chris Barrett - Polaris Interplanetary - Special Projects Division
// Supports two modes; All pixel colour fade, and 8 pixel RGB mixer. All modes are asynchronous, and compartmentalized into functions.

//  Dec  2016     - Changed shimmer to use a different array based system to try and finally end flickering.
//  June 2016     - Re-implemented rotary encoder functions for brightness control
//                - New timing function to space out updates
//                - LIGHTNING FUNCTION
//                - produces a quicker shimmer effect, may replace shimmer with it later.
//  January 2016  - Shimmer has been overhauled. Cleaner, faster and more productive. NO MORE MID FADE FLICKER?
//                - Collision detection has been implemented, not sure if it works, will need to check further.

#include <Adafruit_NeoPixel.h>  //  Neopixel library
//#include <avr/power.h>        //  Not sure why this is here, lol
#include <Encoder.h>            //  Rotary encoder library.

#define PIN            6        //  Which pin on the Arduino is connected to the NeoPixels

#define NUMPIXELS      37      //  Highest pixel location.
#define LOWPIXELS      0       //  Lowest pixel location This was helpful in prototyping because I could use a long strip of lights and only address the last few and stick them in the salt crystal.

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

Encoder myEnc(2, 3);                                //  Encoder function variables

//--------------------------------------------------//  TIMER STUFF

/* These are from Blink without Delay
Shows another way to execute delays. */
unsigned long previousMillis = 0;
unsigned long lastbolt = 0;
unsigned long interval = 60;
int maxb;

int butpin = 5;                                     //  integer to store button pin
int butval;                                         //  Button digital read variable
int butsel = 1;                                     //  Button mode selection variable.
int butbounce;                                      //  button debounce
int rcount;                                         //  Counter for red
int gcount;                                         //  Counter for green
int bcount;                                         //  Counter for blue
int rval;                                           //  int stores red brightness
int gval;                                           //  int stores green brightness
int bval;                                           //  int stores blue brightness
int rgo;                                            //  red go int, 0 for off, 1 for upwards, 2 for downwards
int ggo;                                            //  green go int, 0 for off, 1 for upwards, 2 for downwards
int bgo;                                            //  blue go int, 0 for off, 1 for upwards, 2 for downwards
int magicnumber;                                    //  magic number determines when to fire colours
int supbright;
int interntimer;

//--------------------------------------------------//  The following values are for the "Shimmer" routine
int PixRay[NUMPIXELS][7];
long oldPosition  = 255;                            //  integer to store encoder value
int firstrun = 0;                                   //  array to write first run values to pixels
int randosparkle =0;                                //  integer to hold the random number value

//--------------------------------------------------// LIGHTNING
int boltgo[8];
int boltloc[8];
int boltbright[8];
int boltupdn[8];
int boltready[8];

void setup() {                                      //-----------------------------------------------(Setup)
    pinMode(butpin, INPUT);                         //  Set buttonpin as input
 //   Serial.begin(9600);                           //  Initialize Serial Debug
   pixels.begin();                                  //  This initializes the NeoPixel library.

    for (int i=0; i <= (NUMPIXELS-1); i++){             //  set magic number for all pixray locations
      PixRay[i][5] = {i};
    }

}

void loop() {                                       //-----------------------------------------------(Main Loop)

  if (firstrun == 0){
  }

  butcheck();

unsigned int tnow = millis();

   // some other logic here would decide when to change the LED state
   // For this sample, just toggle every 4 seconds
  if((tnow - previousMillis) >= interval) {

      if (oldPosition > 1 && oldPosition < 255){
        supbright = oldPosition;
      }

      if (oldPosition < 0){
        supbright = 0;
      }

      if (oldPosition > 255){
        supbright = 255;
      }

      if (butsel == 1){
          clearscreen();
          shimmer();
      }

      if (butsel == 2){
          clearscreen();
          colourfade();
      }

      if (butsel == 3){
          clearscreen();
      }

      pixels.show();                                  // This sends the updated pixel color to the hardware.
    previousMillis = tnow;
}

}

void clearscreen(){                                 //-----------------------------------------------(clears the strip)
    for(int i=0;i<NUMPIXELS;i++){
        pixels.setPixelColor(i, pixels.Color(0,0,0));
    }
}

void butcheck(){                                    //-----------------------------------------------(Button Check Function)

    long newPosition = myEnc.read();
    if (newPosition != oldPosition) {

    if (newPosition >= 100){
      myEnc.write(100);
    }
    if (newPosition < 0){
      myEnc.write(0);
    }
        oldPosition = newPosition;
       // Serial.println(newPosition);
    }

    interval = map(newPosition, 0, 100, 80, 0);
    maxb = map(newPosition, 0, 100, 0, 255);

    pinMode(butpin, INPUT);
    butval = digitalRead(butpin);                   // check button pin for a high

    if (butval == HIGH){                            // if high signal read add one to the button selection variable
      butbounce = 1;
    }

    if (butbounce == 1 && butval == LOW){
     butsel = butsel + 1;
     butbounce = 0;
    }

    if (butsel > 2){                               //  resets the button value variable. I use this method so I can add more modes if I want later.
    butsel = 1;
    }
}

void colourfade(){                                  //-----------------------------------------------(Colour Fade Function)

    magicnumber = random(0,30);                     //creates a magic number

    if (magicnumber == 3 && rgo == 0){              //checks to see if magic number has selected red and red is not currently firing
      rgo = 1;                                      //sets the red go bit to 1 meaning positive alternation
    }

    if (magicnumber == 10 && ggo == 0){              //checks to see if magic number has selected green
      ggo = 1;
    }

    if (magicnumber == 20 && bgo == 0){             //checks to see if magic number has selected blue
      bgo = 1;
    }

    // ---------------------------------------------// Write Red

    if (rgo == 1){                                  // checks for ascent stage bit, adds one to red brightness
      rval = rval + 1;
    }

    if (rgo == 2){                                  // checks for descent stage bit, subtracts one from brightness
      rval = rval - 1;
    }

    if (rval >= maxb){                               // sets red bit to 2 meaning negative alternation
      rgo = 2;
    }

    if (rval == 0 && rgo == 2){                     // when counter runs out and go bit is 2, reset everything.
      rgo = 0;
      rval = 0;
    }

    // ---------------------------------------------// Write Blue

    if (bgo == 1){                                  // checks for ascent stage bit, adds one to blue brightness
      bval = bval + 1;
    }

    if (bgo == 2){                                  // checks for descent stage bit, subtracts one from brightness
      bval = bval - 1;
    }

    if (bval >= maxb){
      bgo = 2;
    }

    if (bval == 0 && bgo == 2){
      bgo = 0;
      bval = 0;
    }

    // ---------------------------------------------// Write Green

    if (ggo == 1){                                  // checks for ascent stage bit, adds one to green brightness
      gval = gval + 1;
    }

    if (ggo == 2){                                  // checks for descent stage bit, subtracts one from brightness
      gval = gval - 1;
    }

    if (gval >= maxb){
      ggo = 2;
    }

    if (gval == 0 && ggo == 2){
      ggo = 0;
      gval = 0;
    }

    for(int i=LOWPIXELS;i<NUMPIXELS;i++){
        pixels.setPixelColor(i, pixels.Color(rval,gval,bval));
    }

}

void shimmer() {                                    //-----------------------------------------------(Shimmer Function)

     randosparkle = random(0,(NUMPIXELS*10));                   //picks a random number

    for (int i=0; i <= (NUMPIXELS-1); i++){                     //For loop to check random number against magic numbers and set the pixel for activation
      if (PixRay[i][5] == randosparkle && PixRay[i][0] == 0){
        PixRay[i][0] = 1;
        PixRay[i][1] = random(0,3);
      }
    }

//    unsigned int tnow = millis();

 //   if((tnow - previousMillis) >= interval) {
      for (int i=0; i <= (NUMPIXELS-1); i++){                     //For loop to activate a pixel
          if (PixRay[i][0] == 1){
              drawPixel(i);
          }
      }
//      previousMillis = tnow;
//    }
}

void drawPixel(int pixelv){              //-----------------------------------------------(Red Pixel Draw Function)

    if (PixRay[pixelv][4] == 0){                      //check if counter is within envelope
        PixRay[pixelv][2] = PixRay[pixelv][2] + 1;
    }

    if (PixRay[pixelv][4] == 1){                      //check if counter is within envelope
        PixRay[pixelv][2] = PixRay[pixelv][2] - 1;
    }

    if (PixRay[pixelv][2] >= maxb){                    //check if counter is within second half of fade
      PixRay[pixelv][4] = 1;
      PixRay[pixelv][2] = maxb;
    }

    if (PixRay[pixelv][1] == 0){
      pixels.setPixelColor(pixelv, pixels.Color(PixRay[pixelv][2],0,0));
    }

    if (PixRay[pixelv][1] == 1){
      pixels.setPixelColor(pixelv, pixels.Color(0,PixRay[pixelv][2],0));
    }

    if (PixRay[pixelv][1] == 2){
      pixels.setPixelColor(pixelv, pixels.Color(0,0,PixRay[pixelv][2]));
    }

    if (PixRay[pixelv][2] <= 0 && PixRay[pixelv][4] == 1){               //check if counter is done alternation
       pixels.setPixelColor(pixelv, pixels.Color(0,0,0));                //turn selected pixel off
       PixRay[pixelv][2] = 0;                                            //set brightness to zero
       PixRay[pixelv][0] = 0;                                            //deactivate pixel activate bit
       PixRay[pixelv][4] = 0;                                            //reset counter
    }

}

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


Add Christmas twinkle lights on NeoPixel strip

// A basic everyday NeoPixel strip test program.

// NEOPIXEL BEST PRACTICES for most reliable operation:
// - Add 1000 uF CAPACITOR between NeoPixel strip's + and - connections.
// - MINIMIZE WIRING LENGTH between microcontroller board and first pixel.
// - NeoPixel strip's DATA-IN should pass through a 300-500 OHM RESISTOR.
// - AVOID connecting NeoPixels on a LIVE CIRCUIT. If you must, ALWAYS
//   connect GROUND (-) first, then +, then data.
// - When using a 3.3V microcontroller with a 5V-powered NeoPixel strip,
//   a LOGIC-LEVEL CONVERTER on the data line is STRONGLY RECOMMENDED.
// (Skipping these may work OK on your workbench but can fail in the field)

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 21

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < LED_COUNT; i++ ) {
    strip.setPixelColor(i, red, green, blue);
  }
  strip.show();
}

// setup() function -- runs once at startup --------------------------------

void setup() {
  // These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
  // Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}

// loop() function -- runs repeatedly as long as board is on ---------------

void loop() {

  int i;
  int color;

/* Twinkle Christmas colors */

    for(i = 0; i < LED_COUNT; i++)
    {
        color = random(4);
          switch (color) {
            case 0:
              strip.setPixelColor(i, 255, 255, 255);
              break;
            case 1:
              strip.setPixelColor(i, 255, 0, 0);
              break;

            case 2:
              strip.setPixelColor(i, 0, 255, 0);
              break;

            case 3:
              strip.setPixelColor(i, 0, 0, 0);
      }
    }
    strip.show();
    delay(100);
    setAll(0, 0, 0);

  }

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


Starting point arduino sketch included

Starting point arduino sketch included

// For the Dallas DS18B20 one wire Temp Sensors
#include <OneWire.h>
#include <DallasTemperature.h>
//For the MPL3115A2 I2C Temp and Pressure Sensor
#include <Wire.h>
#include "MPL3115A2.h"
// For the LCD Display
#include <LiquidCrystal.h>

// Debug Flag
#define DEBUG 0
//#define TO_SERIAL 1
#define VERSION 0.1

#define BACKLIGHT 13
int light = A0;

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

// Define Global variables to be used throughout the sketch
// 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 dallasTemp(&oneWire);
//
MPL3115A2 mplTempPressure;

// LCD
LiquidCrystal lcd(9,8,7,6,5,4);
// Create the "Degree" character
uint8_t degree[8] = {
  B00010,
  B00101,
  B00101,
  B00010,
  B00000,
  B00000,
  B00000,
  B00000,
};
// Create a down arrow
uint8_t falling[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B11111,
  B01110,
  B00100,
  B00000,
};
// Create an up arrow
uint8_t rising[8] = {
  B00000,
  B00100,
  B01110,
  B11111,
  B00000,
  B00000,
  B00000,
  B00000,
};
// Create a symbol for stable
uint8_t stable[8] = {
  B00000,
  B00100,
  B01110,
  B11111,
  B01110,
  B00100,
  B00000,
  B00000,
};
// Create a symbol for unknown
uint8_t empty[8] = {
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
};
// Variables to hold the values
float inTemp = 0.0;
float inTemp2 = 0.0;
float outTemp = 0.0;
float pressure = 0.0;

// Hold historic values to help error checking
float inTempHist = 0.0;
float inTemp2Hist = 0.0;
float outTempHist = 0.0;
float pressureHist = 0.0;

boolean firstRun = true;
float maxVariation = 0.5; // difference between readings, should be good for both temp an pressure
int smooth = 5; // How much weighting the historic value gets vs last reading (Smoothing)

// Keep a historic record
int const readingsPerMin = 12; //number of readings per minute
float readings[readingsPerMin];
float mins[60];
float hours[24];
// Indexes to next value to be written
int rdgIndex = 0;
int minIndex = 0;
int hrIndex = 0;

// Long historic value to allow estimate of rising or falling pressure
float longPressureHist = 0.0;
float pressureChangeMin = 0.1;
long measureTime = 0;
long measureInterval = 60000/readingsPerMin; // 5 second intervals between measurements
long loopCount = 0;
//long loops = 1*60*60/(measureTime/1000); //about 1 hour
long loops = 12;

// This helper function allows for smoothing of displayed values
// and the updating of historic record
float updateT(float hist, float value){
  float newVal = 0.0;
  if(value < hist + maxVariation && value > hist - maxVariation){
    newVal = (smooth*hist + value)/(smooth+1.0);
  } else {
    newVal = hist;
  }
  return newVal;
}

float updateP(float hist, float value){
  float newVal = updateT(hist, value);
  float sum=0.0;
  rdgIndex++;
  if(rdgIndex == readingsPerMin){ // We have filled the readings buffer
    // Roll the pointer round
    rdgIndex = 0;
    minIndex++;
    if(minIndex == 60){ // We have filled the minutes buffer
      // Roll the pointer round
      minIndex = 0;
      hrIndex++;
      if(hrIndex == 24){ // We have filled the hours buffer
        hrIndex = 0;
      }
      sum = 0.0;
      for (int i=0; i<60; i++){
        sum += mins[i];
      }
      hours[hrIndex] = sum/60.0;
    }
    sum = 0.0;
    for(int i=0; i< readingsPerMin; i++){
      sum += readings[i];
    }
    mins[minIndex] = sum/readingsPerMin;
  }
  readings[rdgIndex] = newVal;
  return newVal;
}

float hrChange(int age){
  int histIndex = (hrIndex + (24 - age)) % 24;
  if(hours[hrIndex] < 0.0 || hours[histIndex] < 0.0){
    return -9999.0;
  } else {
    return hours[hrIndex] - hours[histIndex];
  }
}

float minChange(int age){
  int histIndex = (minIndex + (60 - age)) % 60;
  if(mins[minIndex] < 0.0 || mins[histIndex] < 0.0){
    return -9999.0;
  } else {
    return mins[minIndex] - mins[histIndex];
  }
}

byte symbol (float diff, float tolerance){
  if (diff < -9000){ // Comparison with uninitialised value
    return byte(4);
  } else if(diff > tolerance){
    return byte(1);
  } else if (diff < -tolerance) {
    return byte(2);
  } else {
    return byte(3);
  }
}

// a helper function for placing temperature readings on the LCD
int startTemp(float temp){
  int start = 0;
  // Adjust start position for Right Justify
  if(temp > 0){
    start++;
  }
  if(abs(temp) < 9.95){
    start++;
  }
  return start;
}

void printSerial(String label, float inT1, float inT2, float outT, float p){
  Serial.print(label);
  Serial.print(inT1);
  Serial.print(", ");
  Serial.print(inT2);
  Serial.print(", ");
  Serial.print(outT);
  Serial.print(", ");
  Serial.println(p);
}

void printLCD(float inT1, float inT2, float outT, float p){
  lcd.clear();
  lcd.setCursor(startTemp(inT1),0);
  lcd.print(inT1,1);
  lcd.write(byte(0)); // degree symbol
  lcd.print("C");
  lcd.setCursor(9 + startTemp(inT2),0);
  lcd.print(outT,1);
  lcd.write(byte(0)); // degree symbol
  lcd.print("C");
  if(p > 999.95){ // Account for rounding...
    lcd.setCursor(0,1);
  } else {
    lcd.setCursor(1,1);
  }
  lcd.print(p,1);
  lcd.print(" mb");
  #if DEBUG > 1
    lcd.setCursor(10,1);
    lcd.print(loopCount);
    lcd.setCursor(15,1);
    lcd.write(symbol(minChange(30), 0.2));
  #else
    lcd.setCursor(13,1);
    lcd.write(symbol(hrChange(23), 1.0));
    lcd.write(symbol(hrChange(6), 0.5));
    lcd.write(symbol(minChange(30), 0.2));
  #endif
}

void setup(void)
{
  #if defined(TO_SERIAL)
  // start serial port
  Serial.begin(9600);
  #endif

  // Start up the Dallas library
  dallasTemp.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement

  // Start the MPL library
  mplTempPressure.begin();
  //Configure it to measure atmospheric pressure
  mplTempPressure.setModeBarometer();
  mplTempPressure.setOversampleRate(7); // Set oversample to recommended 128
  mplTempPressure.enableEventFlags();

  //LCD
  pinMode(BACKLIGHT, OUTPUT);
  analogWrite(BACKLIGHT, 128);
  pinMode(light, INPUT);
  lcd.begin(16, 2);
  lcd.print("Weather Station");
  lcd.setCursor(0,1);
  lcd.print("Version ");
  lcd.print(VERSION);
  lcd.createChar(0,degree);
  lcd.createChar(1,rising);
  lcd.createChar(2,falling);
  lcd.createChar(3,stable);
  lcd.createChar(4,empty);
  delay(1000);

  // Zero out the history arrays
  for(int i=0; i<readingsPerMin; i++)
    readings[i] = -3000.0;
  for(int i=0; i<60; i++)
    mins[i] = -3000.0;
  for(int i=0; i<24; i++)
    hours[i] = -3000.0;
}

void loop(void)
{
  long start = millis();

  // Set the backlight depending on the ambient light
  int bright = analogRead(light);
  analogWrite(BACKLIGHT, map(bright,0,1000,5,255));

  // Possibly write out debug information
   #if DEBUG > 3
     #if defined(TO_SERIAL)
      Serial.println(start);
      Serial.print("Bright: ");
      Serial.println(bright);
      delay(10);
    #endif
  #endif

  if (millis() > measureTime){
    //Ask the dallas sensors to perform a reading
    dallasTemp.requestTemperatures(); // Send the command to get temperatures
    inTemp = dallasTemp.getTempCByIndex(0);
    outTemp = dallasTemp.getTempCByIndex(1);

    // Ask the MPL to perform a reading
    inTemp2 = mplTempPressure.readTemp();
    pressure = mplTempPressure.readPressure()/100; // Divide by 100 to get mBar

    // Do some error checking - regularly see 0.0 coming back from the pressure sensor...
    if(firstRun){
      int check = 0;
      if(pressure > 500.0){
        pressureHist = pressure;
        longPressureHist = pressure;
        check++;
      }
      if(inTemp > -20.0){
        inTempHist = inTemp;
        check++;
      }
      if(inTemp2 > -20.0){
        inTemp2Hist = inTemp2;
        check++;
      }
      if(outTemp > -50.0){
        outTempHist = outTemp;
        check++;
      }
      if(check == 4){
        firstRun=false;
      }
    } else {
      pressureHist = updateP(pressureHist, pressure);
      inTempHist = updateT(inTempHist, inTemp);
      inTemp2Hist = updateT(inTemp2Hist, inTemp2);
      outTempHist = updateT(outTempHist, outTemp);
    }

    printLCD(inTempHist, inTemp2Hist, outTempHist, pressureHist);

    #if defined(TO_SERIAL)
      printSerial("raw  ", inTemp, inTemp2, outTemp, pressure);
      printSerial("hist ", inTempHist, inTemp2Hist, outTempHist, pressureHist);
    #endif

    loopCount++;

    // Debug information to Serial
    #if DEBUG > 3
      #if defined(TO_SERIAL)
        long processTime = millis() - start;
        Serial.print("Milliseconds for the loop: ");
        Serial.println(processTime);
        processTime++; //we have taken about 1ms here so compensate :-)
      #endif
    #endif

    while (measureTime < millis()){
      measureTime += measureInterval;
    }
  }
}

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


Arduino Code

Arduino Code

long previousMillis = 0;
bool rainbowAnimation = false;
bool sentCommand = false;
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

// VARIABLES

// INT
int stripLength = strip.numPixels();
int currentPixel = 0;
int state;
bool test = true;
int blue = 0;
int green = 0;
int red = 255;

int i = 0, j = 0;

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  Serial.print("Ready");

}

void loop() {

    //colorWipe(100, strip.Color(red, green, blue));
    //solidColor(strip.Color(0,255,0));
    String data = Serial.readString();

    if(data.substring(0,7) == "Rainbow" || rainbowAnimation){
      // Reset Color
      if(data.substring(0,7) == "Rainbow") i = 0, j = 0;

      int wait = data.substring(7).toInt();

      rainbowAnimation = true;
      sentCommand = true;
      rainbow(wait);
    }
    if(data.substring(0,10) == "SolidColor"){
      rainbowAnimation = false;

      String redString = data.substring(10,13);
      String greenString = data.substring(13,16);
      String blueString = data.substring(16,19);
      solidColor(strip.Color(redString.toInt(),greenString.toInt(),blueString.toInt()));
    }
    if(data == "Off"){
      rainbowAnimation= false;

      strip.clear();
      strip.show();
    }
}

// Fill the dots one after the other with a color
void colorWipe(int wait, float color) {

  if(currentPixel <= stripLength){
      strip.setPixelColor(currentPixel, color);
      strip.show();
      currentPixel ++;

      if (blue < 255 && green == 0) {
        blue += 5;
        red -= 5;

        Serial.print("Red : ");
        Serial.println(red, DEC);
        Serial.print("Blue : ");
        Serial.println(blue, DEC);

        if(blue >= 225){
          blue = 255;
          red = 0;
        }
    }
    else if(red == 0 && blue > 0){
      blue -= 5;
      green += 5;

      Serial.print("Green : ");
      Serial.println(green, DEC);
      Serial.print("Blue : ");
      Serial.println(blue, DEC);
    }

      else {
          blue = 0;
          green = 0;
          red = 255;
          Serial.println("restarted");
      }
      delay(wait);
  }

  else {
      currentPixel = 0;
      strip.clear();
    }
}

// SOLID COLOR
void solidColor(float color){
  currentPixel = 0;
  while(currentPixel <= stripLength){
      strip.setPixelColor(currentPixel, color);
      strip.show();
      currentPixel ++;
    }
}

void rainbow(long wait){

  // Delay
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > wait || sentCommand) {
    previousMillis = currentMillis;

    if(j < 256){

      for(i=0; i<stripLength; i++) {
        strip.setPixelColor(i, Wheel((i+j) & 255));
      }

      strip.show();
      j++;
    } else j = 0;
  }
  if(sentCommand) sentCommand = false;
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
long Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

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


Create gimbal.ino

Create gimbal.ino

Contains the Arduino code necessary to alter the gimbal based on info sent to it over tx and rx via linux.

/*
 * @author: jstuder
 *
 */
#include <Servo.h>

//the servo to counter the pitch of the drone
Servo pitch, roll;
const int PARALLEL = 50; //45 allows for 30 degrees of + and - with ease
const int PERPENDICULAR = PARALLEL + 90;

//A constant to control the speed of angle change, lower is faster
const int SPEED = 10;

/*
 * @parameters
 *  byte angle -> the angle you want to go to
 *  int speed -> the delay between a move of 1 degree (lower is faster)
 */
void goToAngle(byte pitchAngle, byte rollAngle, int speed);

/*
 * @parameters
 * bool isPLL -> true if gimbal needs to be parallel to the ground, false if it
 *               needs to be perpendicular
 * int xAdj -> pass a positive or negative value to adjust the left-right axis of the gimbal
 *             (modifies servo2)
 * int yAdj -> pass a positive or negative value to adjust the forward-backward axis of the gimbal
 *             (modifies pitch)
 */
void mntn(bool isPLL, byte rAdj, byte pAdj);

void setup() {

  //assigns analog pin 0 to output
  pinMode(A0,OUTPUT);
  pinMode(A2, OUTPUT);
  pitch.attach(A0); //attaches pitch to analog 0
  roll.attach(A2);

  delay(1000); //gives a little leeway before start up. Not essential
  goToAngle(50, 40, SPEED); //sets the gimbal to parallel as default

  //enables serial
  Serial1.begin(115200);
  Serial.begin(115200);
  Serial.println("Ready");
  Serial1.println("hello??");
}

void loop()
{
  //used to track parallel or perpendicular
  static boolean isParallel = true;
  if (Serial1.available())
  {
    //reads as a string to allow for 'change' to be a condition
    String in;
    int i = 0;
    in = Serial1.readString();
    Serial.println(in);
    char inC[in.length()];
    in.toCharArray(inC, in.length());

    //allows yChange to default to the previous value. If input is invalid the gimbal doesn't move.
    byte pChange = pitch.read();
    byte rChange = roll.read();
    //if 'change' is sent, allows the gimbal to switch orientation
    if (inC[0] == 's')
    {
      isParallel = !isParallel;
      Serial.println("CHANGE"); //debugging purposes
      pChange = 0; //allows the change to be precise. on change, you should be hovering
      rChange = 0;
    }
    else
    {
      String rString = "";
      String pString = "";
      int count = 0;
      do
      {
        rString += inC[count];
        count++;
      } while (inC[count] != ' ');

      do
      {
        pString += inC[count];
        count++;
      } while (inC[count] != ' ');

      rChange = rString.toInt();
      pChange = pString.toInt();

    }
    Serial.print(rChange); //debugging purposes
    Serial.print(" ");
    Serial.println(pChange);
    //calls the "maintain" function
    mntn(isParallel, rChange, pChange);
  }
}

void mntn(bool isPLL, byte rAdj, byte pAdj)
{
  //sets the new angle equal to the change from the old angle
  //runs if the gimbal needs to be parallel to the ground
  rAdj += 40;
  if (isPLL)
  {
    Serial.println("PLL"); //debugging purposes
    pAdj += PARALLEL;
    goToAngle(pAdj, rAdj, SPEED);
  }
  else if (!isPLL)
  {
    Serial.println("PERP"); //debugging purposes
    pAdj += PERPENDICULAR;
    goToAngle(pAdj, rAdj, SPEED);
  }
}

void goToAngle(byte pitchAngle, byte rollAngle, int speed)
{
  byte currentPAngle = pitch.read();
  byte currentRAngle = roll.read();
  if(pitchAngle > currentPAngle)
  {
    for (int i = currentPAngle; i < pitchAngle; i++)
    {
      pitch.write(i);
      delay(speed);
    }
  }
  else
  {
    for (int i = currentPAngle; i > pitchAngle; i--)
    {
      pitch.write(i);
      delay(speed);
    }
  }

  if(rollAngle > currentRAngle)
  {
    for (int i = currentRAngle; i < rollAngle; i++)
    {
      roll.write(i);
      delay(speed);
    }
  }
  else
  {
    for (int i = currentRAngle; i > rollAngle; i--)
    {
      roll.write(i);
      delay(speed);
    }
  }
}

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


left, right, tilt, down

left, right, tilt, down

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/ocean-x/erikson-1.git/'


Moved

Moved

#include <RTClib.h>
#include "arduinoFFT.h"
#include <Wire.h>
#include <Timer32.h>
#include <string.h>
#include <SD.h>
#include <SPI.h>
#include "Fishino.h"
#include <WebSocket.h>
#include <Arduino.h>

//variabili websocket
#ifndef MYNET_H
// SSID della rete WiFi
#define MY_SSID  "Fishino32"

// PASSWORD of network.
#define MY_PASS ""

// 'IP desiderato per il fishino
#define IPADDR  192, 168, 1, 251
#endif

#ifndef _FISHINO32_
const int SD_CS = 4;
#else
const int SD_CS = SDCS;
#endif

#ifdef IPADDR
IPAddress ip(IPADDR);
#endif

// Enabe debug tracing to Serial port.
#define DEBUG

arduinoFFT FFT = arduinoFFT();
const int samples = 64; //campioni
const double sampling = 200;  //frequenza di campionamento
uint8_t exponent;
double vRealx[samples];
double vImagx[samples];
double vRealy[samples];
double vImagy[samples];
double vRealz[samples];
double vImagz[samples];
double vReala[samples];
double vImaga[samples];
int i = 0;
int j = 0;
double jr[samples];
double ji[samples];
double freq[200/2];

long int ti;
volatile bool intFlag=false;

#define SIZE 8 //numero di FFT calcolate prima di scrivere su SD
const int chipSelect_SD_default = SDCS;
const int chipSelect_SD = chipSelect_SD_default;
String data= "";
#if defined(ARDUINO_ARCH_SAMD)
   #define Serial SerialUSB
#endif
RTC_Millis rtc;
char nome_file[17];
char **data_base;

WebSocketServer wsServer;
uint8_t mac[WL_MAC_ADDR_LENGTH]={0x11,0x22,0x33,0x44,0x55,0x66};

#define SCL_INDEX 0x00
#define SCL_TIME 0x01
#define SCL_FREQUENCY 0x02

#define    MPU9250_ADDRESS            0x68

#define    ACC_FULL_SCALE_2_G        0x00
#define    ACC_FULL_SCALE_4_G        0x08
#define    ACC_FULL_SCALE_8_G        0x10
#define    ACC_FULL_SCALE_16_G       0x18

#define   a   0
#define   x   1
#define   y   2
#define   z   3

// This function read Nbytes bytes from I2C device at address Address.
// Put read bytes starting at register Register in the Data array.
void I2Cread(uint8_t Address, uint8_t Register, uint8_t Nbytes, uint8_t* Data)
{
  // Set register address
  Wire.beginTransmission(Address);
  Wire.write(Register);
  Wire.endTransmission();

  // Read Nbytes
  Wire.requestFrom(Address, Nbytes);
  uint8_t index=0;
  while (Wire.available())
    Data[index++]=Wire.read();
}

// Write a byte (Data) in device (Address) at register (Register)
void I2CwriteByte(uint8_t Address, uint8_t Register, uint8_t Data)
{
  // Set register address
  Wire.beginTransmission(Address);
  Wire.write(Register);
  Wire.write(Data);
  Wire.endTransmission();
}

void callback()
{
  intFlag=true;
}

void onConnect(WebSocket &socket)
{
  Serial.println("onConnect called");
}

// It will be called by the server when a data frame is received.
void onData(WebSocket &socket, char* dataString, byte frameLength)
{
  #ifdef DEBUG
   Serial.print("Got data: ");
   Serial.write((unsigned char*)dataString, frameLength);
   Serial.println();
  #endif

  // Just echo back data for fun.
  socket.send(dataString, strlen(dataString));
}

void onDisconnect(WebSocket &socket) {
  Serial.println("onDisconnect called");
}

void getFileName(char *name)
{
  DateTime now = rtc.now();
  sprintf(name, "%d", now.year());
  int temp= now.month();
  if(temp > 9)
  {
    sprintf(name+4, "%d", temp);
  }
  else
  {
    name[4]= '0';
    sprintf(name+5, "%d", temp);
  }
  temp= now.day();
  if(temp > 9)
  {
    sprintf(name+6, "%d", temp);
  }
  else
  {
    name[6]= '0';
    sprintf(name+7, "%d", temp);
  }
  temp= now.hour();
  if(temp > 9)
  {
    sprintf(name+8, "%d", temp);
  }
  else
  {
    name[8]= '0';
    sprintf(name+9, "%d", temp);
  }
  temp= now.minute();
  if(temp > 9)
  {
    sprintf(name+10, "%d", temp);
  }
  else
  {
    name[10]= '0';
    sprintf(name+11, "%d", temp);
  }
  temp= now.second();
  if(temp > 9)
  {
    sprintf(name+12, "%d", temp);
  }
  else
  {
    name[12]= '0';
    sprintf(name+13, "%d", temp);
  }
  name[14]= '.';
  name[15]= 't';
  name[16]= 'x';
  name[17]= 't';
  Serial.println(name);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void setup()
{
  Wire.begin();
  #ifdef DEBUG
    Serial.begin(115200);
  #endif
  //while(!Serial);

  rtc.begin(DateTime(F(__DATE__), F(__TIME__)));

  Fishino.setApMAC(mac);

  // initialize SPI:
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);

  // reset and test wifi module
  Serial << F("Resetting Fishino...");
  while(!Fishino.reset())
  {
    Serial << ".";
    delay(500);
  }
  Serial << F("OK\r\n");

  // set PHY mode 11G
  Fishino.setPhyMode(PHY_MODE_11G);

  // setup SOFT AP mode
  // imposta la modalitè SOFTAP
  Serial << F("Setting mode SOFTAP_MODE\r\n");
  Fishino.setMode(SOFTAP_MODE);

  // stop AP DHCP server
  Serial << F("Stopping DHCP server\r\n");
  Fishino.softApStopDHCPServer();

  // setup access point parameters
  Serial << F("Setting AP IP info\r\n");
  Fishino.setApIPInfo(ip, ip, IPAddress(255, 255, 255, 0));

  Serial << F("Setting AP WiFi parameters\r\n");
  Fishino.softApConfig(F(MY_SSID), F(MY_PASS), 1, false);

  // restart DHCP server
  Serial << F("Starting DHCP server\r\n");
  Fishino.softApStartDHCPServer();

  // print current IP address
  Serial << F("IP Address :") << ip << "\r\n";

  wsServer.registerConnectCallback(&onConnect);
  wsServer.registerDataCallback(&onData);
  wsServer.registerDisconnectCallback(&onDisconnect);
  wsServer.begin();

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect_SD)) {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");

  exponent = FFT.Exponent(samples);

  // Set accelerometers low pass filter at 60Hz
  I2CwriteByte(MPU9250_ADDRESS,29,0x32);

  // Configure accelerometers range
  I2CwriteByte(MPU9250_ADDRESS,28,ACC_FULL_SCALE_4_G);

  Timer23.setPeriodMs(5);             //Periodo di campionamento => frequenza di campionamento= 200Hz
  Timer23.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
  Timer23.start();

  // Store initial time
  ti=millis();

  data_base= (char**)malloc(10*sizeof(char*));
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
  //server in ascolto
  wsServer.listen();

  //attesa dati accelerometro
  while (!intFlag);

  intFlag=false;

  // Read accelerometer
  uint8_t Buf[14];
  I2Cread(MPU9250_ADDRESS,0x3B,14,Buf);

  // Accelerometer
  vRealx[i] = -(Buf[0]<<8 | Buf[1]);
  vImagx[i] = 0;
  vRealy[i] = -(Buf[2]<<8 | Buf[3]);
  vImagy[i] = 0;
  vRealz[i] = Buf[4]<<8 | Buf[5];
  vImagz[i] = 0;

  if(i == samples-1)
  {
    for(int j=0; j<samples; j++)
    {
      vReala[j] = sqrt(sq(vRealx[j]) + sq(vRealy[j]) + sq(vRealz[j]));
      vImaga[j] = 0;
    }

    //data x
    PrintVectorjs(vRealx, vImagx, samples, SCL_TIME, x, ti);
    FFT.Windowing(vRealx, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vRealx, vImagx, samples, exponent, FFT_FORWARD);
    FFT.ComplexToMagnitude(vRealx, vImagx, samples);
    PrintVectorjs(vRealx, vImagx, (samples/2), SCL_FREQUENCY, x, ti);
      //double x = FFT.MajorPeak(vRealx, samples, sampling);

    //data y
    PrintVectorjs(vRealy, vImagy, samples, SCL_TIME, y, ti);
    FFT.Windowing(vRealy, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vRealy, vImagy, samples, exponent, FFT_FORWARD);
    FFT.ComplexToMagnitude(vRealy, vImagy, samples);
    PrintVectorjs(vRealy, vImagy, (samples/2), SCL_FREQUENCY, y, ti);
      //double y = FFT.MajorPeak(vRealy, samples, sampling);

    //data z
    PrintVectorjs(vRealz, vImagz, samples, SCL_TIME, z, ti);
    FFT.Windowing(vRealz, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vRealz, vImagz, samples, exponent, FFT_FORWARD);
    FFT.ComplexToMagnitude(vRealz, vImagz, samples);
    PrintVectorjs(vRealz, vImagz, (samples/2), SCL_FREQUENCY, z, ti);
      //double z = FFT.MajorPeak(vRealz, samples, sampling);

    //data all
    PrintVectorjs(vReala, vImaga, samples, SCL_TIME, a, ti);
    FFT.Windowing(vReala, samples, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vReala, vImaga, samples, exponent, FFT_FORWARD);
    FFT.ComplexToMagnitude(vReala, vImaga, samples);
    PrintVectorjs(vReala, vImaga, (samples/2), SCL_FREQUENCY, a, ti);
      //double a = FFT.MajorPeak(vReala, samples, sampling);

    Serial.println(data);
    char data_server[data.length()+1];
    data.toCharArray(data_server, data.length()+1);
    data="";

    //verifico se ci sono client connessi
    if (wsServer.connectionCount() > 0)
    {
      wsServer.send(data_server, sizeof(data_server));
      Serial.println("dati inviati");
    }

    data_base[j]= (char*)malloc(sizeof(data_server));
    memmove (data_base[j], data_server, sizeof(data_server));

    if( j == SIZE-1 )
    {
      getFileName(nome_file);
      // open the file on SD
      File dataFile = SD.open(nome_file+6, FILE_WRITE);

      // if the file is available, write to it:
      if (dataFile)
      {
        for(int i=0; i<SIZE; i++)
        {
          dataFile.println(data_base[i]);
          free(data_base[i]);
        }

        dataFile.close();
        // print to the serial port too:
        Serial.println("scrittura ok");
      }
      // if the file isn't open, pop up an error:
      else
      {
        Serial.println("error opening file");
      }
      j = 0;
      free(data_base);
      data_base= (char**)malloc(10 * sizeof(char*));
    }
    else j++;
    i = 0;
  }
  else i++;
}

void PrintVectorjs(double *vDataR, double *vDataI, uint8_t bufferSize, uint8_t scaleType, int asseType, long int tempo)
{
    double abscissa;
    char buffer[30];

    switch (asseType)
    {
      case x:
        if(scaleType == SCL_TIME){
          data+= "{\"millis\":";
          data+= itoa(millis()-tempo, buffer, 10);
          memset(buffer, 0, 30);
          data+= ",\"x\":[";
        }
        else  data+= ",";
      break;
      case y:
        if(scaleType == SCL_TIME){
          data+= "],\"y\":[";
        }
        else  data+= ",";
      break;
      case z:
        if(scaleType == SCL_TIME){
          data+= "],\"z\":[";
        }
        else  data+= ",";
      break;
      case a:
        if(scaleType == SCL_TIME){
          data+= "],\"all\":[";
        }
        else  data+= ",";
      break;
    }

    switch (scaleType)
    {
      case SCL_INDEX:
        data+= "{\"components\":[{\"real\": [";
        for (int i = 0; i < bufferSize-1; i++)
        {
              sprintf(buffer, "%f", vDataR[i]);
              data+= buffer;
              memset(buffer, 0, 30);
              data+= ",";
        }
        sprintf(buffer, "%f", vDataR[bufferSize-1]);
        data+= buffer;
        memset(buffer, 0, 30);
        data+= "]},{\"imm\": [";
        for (int i = 0; i < bufferSize-1; i++)
        {
              sprintf(buffer, "%f", vDataI[i]);
              data+= buffer;
              memset(buffer, 0, 30);
              data+= ",";
        }
        sprintf(buffer, "%f", vDataI[bufferSize-1]);
        data+= buffer;
        memset(buffer, 0, 30);
        data+= "]}]}";
      break;
      case SCL_TIME:
        data+= "{\"signal\":[{\"time\": [";
        for (int i = 0; i < bufferSize-1; i++)
        {
              abscissa = (i / sampling);
              sprintf(buffer, "%f", abscissa);
              data+= buffer;
              memset(buffer, 0, 30);
              data+= ",";
        }
        abscissa = (i / sampling);
        sprintf(buffer, "%f", abscissa);
        data+= buffer;
        memset(buffer, 0, 30);
        data+= "]},{\"real\": [";
        for (int i = 0; i < bufferSize-1; i++)
        {
              sprintf(buffer, "%f", vDataR[i]);
              data+= buffer;
              memset(buffer, 0, 30);
              data+= ",";
        }
        sprintf(buffer, "%f", vDataR[bufferSize-1]);
        data+= buffer;
        memset(buffer, 0, 30);
        data+= "]}]}";
      break;
      case SCL_FREQUENCY:
        data+= "{\"spectrum\":[{\"f\": [";
        for (int i = 0; i < bufferSize-1; i++)
        {
              abscissa = ((i * sampling) / samples);
              vDataI[i]= abscissa;
              sprintf(buffer, "%f", abscissa);
              data+= buffer;
              memset(buffer, 0, 30);
              data+= ",";
        }
        abscissa = ((i * sampling) / samples);               //STAMPA UN 1 IN PIU
        vDataI[i]= abscissa;
        sprintf(buffer, "%f", abscissa);
        data+= buffer;
        memset(buffer, 0, 30);
        data+= "]},{\"e\": [";
        for (int i = 0; i < bufferSize-1; i++)
        {
              sprintf(buffer, "%f", vDataR[i]);
              data+= buffer;
              memset(buffer, 0, 30);
              data+= ",";
        }
        sprintf(buffer, "%f", vDataR[bufferSize-1]);
        data+= buffer;
        memset(buffer, 0, 30);
        data+= "]}]}";
        if(asseType == a){
          data+= "]}";
        }
      break;
    }
}

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


Added simple sketch based on decay, changed generator to take into account settling (initial drifting) of humidity sensor

#include <Time.h>

const int relaisPin =  11;
const int sensorPin = A0;    // select the input pin for the potentiometer
const int MINHUMIDITY = 0;
const int MAXHUMIDITY = 1023;
const int milliseconds_sleep = 5000;
const int avg_decay = 0.00001;
const int deviation_decay = 0.01;
int sensorValue = 0;  // variable to store the value coming from the sensor
int thresholdLow = 0;
int thresholdHigh = 0;
int avg = 0;
int deviation = 20;
int humidity = 0;
int startup_seconds = 900; // sensor needs to settle for 15 minutes

int get_humidity() {
  sensorValue = analogRead(sensorPin);

  // sensor value is high when humidity is low, this is
  // counterintuitive (it's a dryness sensor!), so we
  // reverse it:
  return MAXHUMIDITY - sensorValue;
}

void setup() {
  // initialize the 11 pin as an output:
  Serial.begin(9600);
  pinMode(relaisPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  digitalWrite(relaisPin, HIGH);
  avg = get_humidity();
}

void loop() {
  humidity = get_humidity();

  if (startup_seconds > 0) {
    // during startup, sensor needs to settle, so average is allowed to change fast
    avg = (avg + humidity) / 2;
    startup_seconds -= milliseconds_sleep / 1000;
  } else {
    // decay the old value, combine with the new (reverse decay)
    avg = avg * (1.0 - avg_decay) + humidity * avg_decay;
  }
  int cur_deviation = max(deviation, humidity - avg);
  deviation = deviation * (1.0 - deviation_decay) + cur_deviation * deviation_decay;
  thresholdLow = avg + deviation / 3;
  thresholdHigh = avg + 2 * deviation / 3;

  // print out the values for debugging/plotting
  Serial.print("humidity = ");
  Serial.print(humidity);
  Serial.print(", tlow = ");
  Serial.print(thresholdLow);
  Serial.print(", thi = ");
  Serial.print(thresholdHigh);
  Serial.print(", dmin = ");
  Serial.print(avg);
  Serial.print(", dmax = ");
  Serial.println(avg + deviation);

  // switch the relays!
  if (sensorValue < thresholdLow) {
    // HIGH means setting the relay to NC
    digitalWrite(relaisPin, HIGH);
  } else if (sensorValue > thresholdHigh) {
    // LOW means setting the relay to NO
    digitalWrite(relaisPin, LOW);
  }
  delay(milliseconds_sleep);
}

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


Update Snake.ino

Update Snake.ino

Deleted some comments

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


add leg system

add leg system

// Walking Plant
// is a robotic prosthesis that amplify plant's survival instincts and
// add social emotions when interacting with people.
// firmware 0.0.1
// ref: http://www.adafruit.com/products/1404
// This sketch is a learning system for a single leg mechanism (M1 toe, M2 ankle, M3)

#include <Servo.h>
#include <EEPROM.h>

#define CALIB_MAX_M1 512
#define CALIB_MIN_M1 100

#define CALIB_MAX_M2 512
#define CALIB_MIN_M2 100

#define CALIB_MAX_M3 512
#define CALIB_MIN_M3 100

#define SAMPLE_DELAY 25 // in ms, 50ms seems good

uint8_t recordButtonPin = 12;
uint8_t playButtonPin = 7;
uint8_t ledPin = 13;

uint8_t servoPinM1 = 9;
uint8_t feedbackPinM1 = A0;

uint8_t servoPinM2 = 10;
uint8_t feedbackPinM2 = A1;

uint8_t servoPinM3 = 11;
uint8_t feedbackPinM3 = A2;

Servo m1Servo;
Servo m2Servo;
Servo m3Servo;

/*
// Calibration values
int minDegrees;
int maxDegrees;
int minFeedback;
int maxFeedback;
int tolerance = 2; // max feedback measurement error

*/
/*
  This function establishes the feedback values for 2 positions of the servo.
  With this information, we can interpolate feedback values for intermediate positions
*/
/*
void calibrate(Servo servo, int analogPin, int minPos, int maxPos)
{
  // Move to the minimum position and record the feedback value
  servo.write(minPos);
  minDegrees = minPos;
  delay(2000); // make sure it has time to get there and settle
  minFeedback = analogRead(analogPin);

  // Move to the maximum position and record the feedback value
  servo.write(maxPos);
  maxDegrees = maxPos;
  delay(2000); // make sure it has time to get there and settle
  maxFeedback = analogRead(analogPin);
}
*/

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

  // record button
  pinMode(recordButtonPin, INPUT);
  digitalWrite(recordButtonPin, HIGH);

  // play button
  pinMode(playButtonPin, INPUT);
  digitalWrite(playButtonPin, HIGH);

  // LED
  pinMode(ledPin, OUTPUT);

  // feedback pins
  pinMode(feedbackPinM1, INPUT);
  pinMode(feedbackPinM2, INPUT);
  pinMode(feedbackPinM3, INPUT);

  Serial.println("Servo RecordPlay");

  // need to do calibration
  //m1Servo.attach(servoM1Pin);
  //calibrate(m1Servo, feedbackM1Pin, 20, 160);  // calibrate for the 20-160 degree range
  //m1Servo.detach();
}

// main loop
void loop() {

   // record new sequence
   if (! digitalRead(recordButtonPin)) {
     delay(10);
     // wait for released
     while (! digitalRead(recordButtonPin));
     delay(20);
     // OK released!
     recordServo();
   }

   // play recorded sequence
    if (! digitalRead(playButtonPin)) {
     delay(10);
     // wait for released
     while (! digitalRead(playButtonPin));
     delay(20);
     // OK released!
     playServo();
   }
}

void playServo() {
  uint16_t addr = 0;
  Serial.println("Playing");

  m1Servo.attach(servoPinM1);
  while (digitalRead(playButtonPin)) {
    uint8_t x = EEPROM.read(addr);
    if ((addr % 3) == 0){
      Serial.print("Read M1: "); Serial.print(x);
      if (x == 255) break;
      // map to 0-180 degrees
      x = map(x, 0, 254, 0, 180);
      Serial.print(" -> "); Serial.println(x);
      m1Servo.write(x);
    }
    delay(SAMPLE_DELAY);

    addr++;
    if (addr == 512) break;
  }
  Serial.println("Done");
  m1Servo.detach();
  delay(250);
}

// record from analog inputs
void recordServo() {
  uint16_t addr = 0;

  // turn on LED
  Serial.println("Recording");
  digitalWrite(ledPin, HIGH);

  // check if button pressed (as stop recording)
  while (digitalRead(recordButtonPin)) {
     uint16_t a = analogRead(feedbackPinM1);
     if ((addr % 3) == 0){
       Serial.print("Read M1 analog: "); Serial.print(a);
       if (a < CALIB_MIN_M1) a = CALIB_MIN_M1;
       if (a > CALIB_MAX_M1) a = CALIB_MAX_M1;
       a = map(a, CALIB_MIN_M1, CALIB_MAX_M1, 0, 254);
       Serial.print(" -> "); Serial.println(a);
       EEPROM.write(addr, a);
     }
     addr++;
     if (addr == 512) break;
     delay(SAMPLE_DELAY);
  }
  if (addr != 512) EEPROM.write(addr, 255);

  digitalWrite(ledPin, LOW);

  Serial.println("Done");
  delay(250);

  // note: think about a way to store the motion data externally
  //       make a buffer where it can be loaded dynamically from host computer (Raspi)
}

/*
void Seek(Servo servo, int analogPin, int pos)
{
  // Start the move...
  servo.write(pos);

  // Calculate the target feedback value for the final position
  int target = map(pos, minDegrees, maxDegrees, minFeedback, maxFeedback);

  // Wait until it reaches the target
  while(abs(analogRead(analogPin) - target) > tolerance){} // wait...
}

int getPos(int analogPin)
{
  return map(analogRead(analogPin), minFeedback, maxFeedback, minDegrees, maxDegrees);
}
*/

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


Updated to fit current configuration

Updated to fit current configuration

#define NO_PRINT 0
#define PRINT_SPEED 1

//mXeY - silnik X, pin enkodera Y
#define m1e1 23
#define m1e2 25
#define m2e1 22
#define m2e2 24
#define m3e1 13
#define m3e2 27
#define m4e1 14
#define m4e2 29

//mXkY - silnik X, pin kierunku Y
#define m1k1 23
#define m1k2 22
#define m2k1 13
#define m2k2 12
#define m3k1 27
#define m3k2 26
#define m4k1 7
#define m4k2 5

//mXPWM - PWM silnika X
#define m1PWM 2
#define m2PWM 11
#define m3PWM 4
#define m4PWM 6
// to be added
// #define PRINT_POWER 2
// #define PRINT_ERROR 3

typedef struct silnik
{
  //liczby to numery pinów
    int pwm;
    int kierunek1;
    int kierunek2;
    int enkoder1;
    int enkoder2;
    int pwmSetting;
    boolean dir_correction;
};

// Structure schema: (pwm, inA, inB, encoder inA, encoder inB, isRight?)
silnik motor1{12, 22, 23, m1e1, m1e2, 1};
silnik motor2{3, 24, 25, m1e1, m1e2, 0};
silnik motor3{4, 26, 27, m1e1, m1e2, 1};
silnik motor4{5, 28, 29, m1e1, m1e2, 0};
silnik motor5{7, 6, 8, m1e1, m1e2, 1};
silnik motor6{10, 9, 11, m1e1, m1e2, 0};

void initMotor(struct silnik motor)
{
  pinMode(motor.enkoder1, INPUT);
  pinMode(motor.enkoder2, INPUT);

  pinMode(motor.kierunek1, OUTPUT);
  pinMode(motor.kierunek2, OUTPUT);

  pinMode(motor.pwm, OUTPUT);

  motor.pwmSetting = 0;
}

void SetSpeed(struct silnik motor, int wypelnienie)
{
  if(wypelnienie==0)
  {
    digitalWrite(motor.kierunek1, HIGH);
    digitalWrite(motor.kierunek2, HIGH);
  }
  else if (!motor.dir_correction)
  {
  if(wypelnienie>0)
  {
    analogWrite(motor.pwm, wypelnienie);
    digitalWrite(motor.kierunek1, HIGH);
    digitalWrite(motor.kierunek2, LOW);
  }

  else if(wypelnienie<0)
  {
    analogWrite(motor.pwm, -wypelnienie);
    digitalWrite(motor.kierunek1, LOW);
    digitalWrite(motor.kierunek2, HIGH);
  }

  }else
  {
  if(wypelnienie>0)
  {
    analogWrite(motor.pwm, wypelnienie);
    digitalWrite(motor.kierunek2, HIGH);
    digitalWrite(motor.kierunek1, LOW);
  }

  else if(wypelnienie<0)
  {
    analogWrite(motor.pwm, -wypelnienie);
    digitalWrite(motor.kierunek2, LOW);
    digitalWrite(motor.kierunek1, HIGH);
  }

  }
}

unsigned long czas, timeBuffer;
String inputString = "";
volatile boolean newMessageReceived = false;
//Pulses Per Revolution, Revolutions Per Revolution
int PPR, RPR;
volatile int u[6] = {0, 0, 0, 0, 0, 0};
int v1=0, e1=0, v2=0, e2=0, v3=0, e3=0, v4=0, e4=0;
int PowerOnMotor1 = 0, PowerOnMotor2 = 0, PowerOnMotor3 = 0, PowerOnMotor4 = 0;
int PWMSpeed[6] = {0, 0, 0, 0, 0, 0};
boolean slopeRise1 = 1, slopeFall1 = 0, slopeRise2 = 1, slopeFall2 = 0, slopeRise3 = 1, slopeFall3 = 0, slopeRise4 = 1, slopeFall4 = 0;
byte timeCounter = 0;
unsigned long startingTime = 0;
int slopeCounter1 = 0, slopeCounter2 = 0, slopeCounter3 = 0, slopeCounter4 = 0;
byte Kp = 0;
byte ConstantPrint = NO_PRINT;
boolean SmartDrive = 1;
int mios = 1000; //Maksymalna Ilość Obrotów Silnika

void setup()
{
  Serial.begin(115200);
  Serial.println("Pololu & Arduino Motor Driver by MtK");
  inputString.reserve(200);
  /*md1i2.init();
  md3i4.init();
  md1i2.setM1Speed(0);
  md1i2.setM2Speed(0);
  md3i4.setM1Speed(0);
  md3i4.setM2Speed(0);*/
  initMotor(motor1);
  initMotor(motor2);
  initMotor(motor3);
  initMotor(motor4);
  initMotor(motor5);
  initMotor(motor6);

  PPR = 6;
  RPR = 10;

  Kp = 2;
}

void loop()
{
  if (newMessageReceived)
    handleNewMessage();

  if (SmartDrive)
  {
    slopeCounter1 = 0;
    slopeCounter2 = 0;
    slopeCounter3 = 0;
    slopeCounter4 = 0;
    startingTime = micros();
    for(unsigned i = 0; i<5000; i++)
    {
      if (digitalRead(m1e1) && slopeRise1)
      {
          if(digitalRead(m1e2))
              slopeCounter1--;
          else
              slopeCounter1++;
          slopeRise1 = 0;
          slopeFall1 = 1;
      }

      if (!digitalRead(m1e1) && slopeFall1)
      {
          if(digitalRead(m1e2))
              slopeCounter1++;
          else
              slopeCounter1--;
          slopeRise1 = 1;
          slopeFall1 = 0;
      }
  //----------------------------------------------------------
      if (digitalRead(m2e1) && slopeRise2)
      {
          if(digitalRead(m2e2))
              slopeCounter2--;
          else
              slopeCounter2++;
          slopeRise2 = 0;
          slopeFall2 = 1;
      }

      if (!digitalRead(m2e1) && slopeFall2)
      {
          if(digitalRead(m2e2))
              slopeCounter2++;
          else
              slopeCounter2--;
          slopeRise2 = 1;
          slopeFall2 = 0;
      }
  //----------------------------------------------------------
      if (digitalRead(m3e1) && slopeRise3)
      {
          if(digitalRead(m3e2))
              slopeCounter3--;
          else
              slopeCounter3++;
          slopeRise3 = 0;
          slopeFall3 = 1;
      }

      if (!digitalRead(m3e1) && slopeFall3)
      {
          if(digitalRead(m3e2))
              slopeCounter3++;
          else
              slopeCounter3--;
          slopeRise3 = 1;
          slopeFall3 = 0;
      }
  //----------------------------------------------------------
      if (digitalRead(m4e1) && slopeRise4)
      {
          if(digitalRead(m4e2))
              slopeCounter4--;
          else
              slopeCounter4++;
          slopeRise4 = 0;
          slopeFall4 = 1;
      }

      if (!digitalRead(m4e1) && slopeFall4)
      {
          if(digitalRead(m4e2))
              slopeCounter4++;
          else
              slopeCounter4--;
          slopeRise4 = 1;
          slopeFall4 = 0;
      }
    }

    czas = micros() - startingTime;
  //  Serial.print("#Enkoders, ");
  //  Serial.print(slopeCounter1);
  //  Serial.print(", ");
  //  Serial.print(slopeCounter2);
  //  Serial.print(", ");
  //  Serial.print(slopeCounter3);
  //  Serial.print(", ");
  //  Serial.print(slopeCounter4);
  //  Serial.print(", ");
  //  Serial.println(); // oddzielenie pustą linią dla zwiększenia czytelności
    v1 = slopeCounter1*((60000000)/(RPR*PPR*(long)czas));
    v2 = slopeCounter2*((60000000)/(RPR*PPR*(long)czas));
    v3 = slopeCounter3*((60000000)/(RPR*PPR*(long)czas));
    v4 = slopeCounter4*((60000000)/(RPR*PPR*(long)czas));

    e1 = u[0]-v1;
    e2 = u[1]-v2;
    e3 = u[2]-v3;
    e4 = u[3]-v4;

    PowerOnMotor1 += Kp*e1;
    PowerOnMotor2 += Kp*e2;
    PowerOnMotor3 += Kp*e3;
    PowerOnMotor4 += Kp*e4;

    if(PowerOnMotor1 > 40000)
      PowerOnMotor1 = 40000;
    else if(PowerOnMotor1< -40000)
      PowerOnMotor1 = -40000;

      if(PowerOnMotor2 > 40000)
      PowerOnMotor2 = 40000;
    else if(PowerOnMotor2 < -40000)
      PowerOnMotor2 = -40000;

      if(PowerOnMotor3 > 40000)
      PowerOnMotor3 = 40000;
    else if(PowerOnMotor3 < -40000)
      PowerOnMotor3 = -40000;

      if(PowerOnMotor4 > 40000)
      PowerOnMotor4 = 40000;
    else if(PowerOnMotor4 < -40000)
      PowerOnMotor4 = -40000;

//    if (u1 == 0)
//      SetSpeed(motor1, 0);
//    else
//      SetSpeed(motor1, PowerOnMotor1/100);
//
//    if (u2 == 0)
//      SetSpeed(motor2, 0);
//    else
//      SetSpeed(motor2, PowerOnMotor2/100);
//
//    if (u3 == 0)
//      SetSpeed(motor3, 0);
//    else
//      SetSpeed(motor3, PowerOnMotor3/100);
//
//    if (u4 == 0)
//      SetSpeed(motor4, 0);
//    else
//      SetSpeed(motor4, PowerOnMotor4/100);

      SetSpeed(motor1, u[0]);
      SetSpeed(motor2, u[1]);
      SetSpeed(motor3, u[2]);
      SetSpeed(motor4, u[3]);
      SetSpeed(motor5, u[4]);
      SetSpeed(motor6, u[5]);

      delay(2000);
      for(int i=0; i<6; i++)
      {
      Serial.print(u[i]);
      Serial.print("   ");
      }
      Serial.println("zeroing...");
      u[0]=0;
      u[1]=0;
      u[2]=0;
      u[3]=0;
      u[4]=0;
      u[5]=0;

  }
  else
  {
    PowerOnMotor1 = 0;
    PowerOnMotor2 = 0;
    PowerOnMotor3 = 0;
    PowerOnMotor4 = 0;

    SetSpeed(motor1, PWMSpeed[0]);
    SetSpeed(motor2, PWMSpeed[1]);
    SetSpeed(motor3, PWMSpeed[2]);
    SetSpeed(motor4, PWMSpeed[3]);
    SetSpeed(motor5, PWMSpeed[4]);
    SetSpeed(motor6, PWMSpeed[5]);

  }

  if(ConstantPrint == PRINT_SPEED)
  {
    Serial.println(v1);
    Serial.println(v2);
    Serial.println(v3);
    Serial.println(v4);
  }
}

void serialEvent() {
  while (Serial.available())
  {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
      // if the incoming character is a newline, set a flag
      // so the main loop can do something about it:
      if (inChar == '\n')
        newMessageReceived = true;
  }
}

void handleNewMessage()
{
  int spaceBar = inputString.indexOf(' ');
  if (spaceBar != -1)
  {
    String buffer = "";
    buffer.reserve(10);
    String buffer2 = "";
    buffer2.reserve(10);
    String bufferMotor = "";
    bufferMotor.reserve(10);
    for (int i=0; i<spaceBar; i++)
      buffer += inputString.charAt(i);

//    spaceBar = inputString.indexOf(' ');
    for (int i=spaceBar+1; i<(inputString.length()-1); i++)
      buffer2 += inputString.charAt(i);

    if (buffer == "Set" || buffer == "SetSpeed")
    {
      spaceBar = buffer2.indexOf(' ');
      for (int i=spaceBar+1; i<(buffer2.length()); i++)
        bufferMotor += buffer2.charAt(i);

      Serial.println("Set command detected!");
      if(bufferMotor=="motor1"){
      u[0]= buffer2.toInt();
      if (u[0]>mios)
          u[0] = mios;
      else if (u[0]<-mios)
          u[0]= -mios;

      e1 = u[0]-v1;
      }
      else if(bufferMotor=="motor2"){
      u[1]= buffer2.toInt();
      if (u[1]>mios)
          u[1]= mios;
      else if (u[1]<-mios)
          u[1]= -mios;

      e2 = u[1]-v2;
      }
      else if(bufferMotor=="motor3"){
       u[2]= buffer2.toInt();
      if (u[2]>mios)
          u[2]= mios;
      else if (u[2]<-mios)
          u[2] = -mios;

      e3 = u[2]-v3;
      }
      else if(bufferMotor=="motor4"){
       u[3]= buffer2.toInt();
      if (u[3]>mios)
          u[3]= mios;
      else if (u[3]<-mios)
          u[3]= -mios;

      e4 = u[3]-v4;
      }
      else if(bufferMotor=="motor5"){
       u[4]= buffer2.toInt();
      if (u[4]>mios)
          u[4]= mios;
      else if (u[3]<-mios)
          u[4]= -mios;
      }
      else if(bufferMotor=="motor6"){
       u[5]= buffer2.toInt();
      if (u[5]>mios)
          u[5]= mios;
      else if (u[5]<-mios)
          u[5]= -mios;
      }
      else if(bufferMotor="all")
      {
        int uForAll = buffer2.toInt();
        if (uForAll > mios)
          uForAll = mios;
        else if (uForAll < -mios)
          uForAll = -mios;

        for(uint8_t i = 0; i<6; i++)
          u[i] = uForAll;

      }

      SmartDrive = 1;
    }
    else if (buffer == "SetKp")
    {
      Kp = buffer2.toInt();
    }
//    else if (buffer == "SetPWM")
//    {
//      if(bufferMotor=="motor1")
//      PWMSpeed1 = 4*buffer2.toInt();
//      else if(bufferMotor=="motor2")
//      PWMSpeed2 = 4*buffer2.toInt();
//      else if(bufferMotor=="motor3")
//      PWMSpeed3 = 4*buffer2.toInt();
//      else if(bufferMotor=="motor4")
//      PWMSpeed4 = 4*buffer2.toInt();
//      SmartDrive = 0;
//    }
    else if (buffer == "Print")
    {
      if(buffer2 == "Speed")
      {
         Serial.println(v1);
         Serial.println(v2);
         Serial.println(v3);
         Serial.println(v4);
         Serial.println();
      }

      else if(buffer2 == "Error")
      {
        Serial.println(e1);
        Serial.println(e2);
        Serial.println(e3);
        Serial.println(e4);
        Serial.println();
      }

      else if(buffer2 == "Power")
      {
        Serial.println(PowerOnMotor1/400);
        Serial.println(PowerOnMotor2/400);
        Serial.println(PowerOnMotor3/400);
        Serial.println(PowerOnMotor4/400);
        Serial.println();
      }

      else if(buffer2 == "ConstSpeed")
          ConstantPrint = PRINT_SPEED;
      else if(buffer2 == "ConstDisable")
          ConstantPrint = NO_PRINT;
    }
    else if(buffer == "Kill")
    {
      SetSpeed(motor1, 0);
      SetSpeed(motor2, 0);
      SetSpeed(motor3, 0);
      SetSpeed(motor4, 0);
      SmartDrive = 0;
    }
  }
  else
    Serial.println("Message ERROR\n\rInvalid command!\n\r");

  newMessageReceived = false;
  inputString = "";
}

#define NO_PRINT 0
#define PRINT_SPEED 1

//mXeY - silnik X, pin enkodera Y
#define m1e1 23
#define m1e2 25
#define m2e1 22
#define m2e2 24
#define m3e1 13
#define m3e2 27
#define m4e1 14
#define m4e2 29

//mXkY - silnik X, pin kierunku Y
#define m1k1 23
#define m1k2 22
#define m2k1 13
#define m2k2 12
#define m3k1 27
#define m3k2 26
#define m4k1 7
#define m4k2 5

//mXPWM - PWM silnika X
#define m1PWM 2
#define m2PWM 11
#define m3PWM 4
#define m4PWM 6
// to be added
// #define PRINT_POWER 2
// #define PRINT_ERROR 3

typedef struct silnik
{
  //liczby to numery pinów
    int pwm;
    int kierunek1;
    int kierunek2;
    int enkoder1;
    int enkoder2;
    int pwmSetting;
    boolean dir_correction;
};

// Structure schema: (pwm, inA, inB, encoder inA, encoder inB, isRight?)
silnik motor1{m1PWM, m1k1, m1k2, m1e1, m1e2, 0};
silnik motor2{m2PWM, m2k1, m2k2, m2e1, m2e2, 1};
silnik motor3{m3PWM, m3k1, m3k2, m3e1, m3e2, 0};
silnik motor4{m4PWM, m4k1, m4k2, m4e1, m4e2, 1};
silnik motor5{m4PWM, m4k1, m4k2, m4e1, m4e2, 1};
silnik motor6{m4PWM, m4k1, m4k2, m4e1, m4e2, 1};

void initMotor(struct silnik motor)
{
  pinMode(motor.enkoder1, INPUT);
  pinMode(motor.enkoder2, INPUT);

  pinMode(motor.kierunek1, OUTPUT);
  pinMode(motor.kierunek2, OUTPUT);

  pinMode(motor.pwm, OUTPUT);

  motor.pwmSetting = 0;
}

void SetSpeed(struct silnik motor, int wypelnienie)
{
  analogWrite(motor.pwm, wypelnienie);
  if(wypelnienie==0)
  {
    digitalWrite(motor.kierunek1, HIGH);
    digitalWrite(motor.kierunek2, HIGH);
  }
  else if (!motor.dir_correction)
  {
  if(wypelnienie>0)
  {
    digitalWrite(motor.kierunek1, HIGH);
    digitalWrite(motor.kierunek2, LOW);
  }

  else if(wypelnienie<0)
  {
    digitalWrite(motor.kierunek1, LOW);
    digitalWrite(motor.kierunek2, HIGH);
  }

  }else
  {
  if(wypelnienie>0)
  {
    digitalWrite(motor.kierunek2, HIGH);
    digitalWrite(motor.kierunek1, LOW);
  }

  else if(wypelnienie<0)
  {
    digitalWrite(motor.kierunek2, LOW);
    digitalWrite(motor.kierunek1, HIGH);
  }

  }
}

unsigned long czas, timeBuffer;
String inputString = "";
volatile boolean newMessageReceived = false;
//Pulses Per Revolution, Revolutions Per Revolution
int PPR, RPR;
int u[6] = {0, 0, 0, 0, 0, 0};
int v1=0, e1=0, v2=0, e2=0, v3=0, e3=0, v4=0, e4=0;
int PowerOnMotor1 = 0, PowerOnMotor2 = 0, PowerOnMotor3 = 0, PowerOnMotor4 = 0;
int PWMSpeed[6] = {0, 0, 0, 0, 0, 0};
boolean slopeRise1 = 1, slopeFall1 = 0, slopeRise2 = 1, slopeFall2 = 0, slopeRise3 = 1, slopeFall3 = 0, slopeRise4 = 1, slopeFall4 = 0;
byte timeCounter = 0;
unsigned long startingTime = 0;
int slopeCounter1 = 0, slopeCounter2 = 0, slopeCounter3 = 0, slopeCounter4 = 0;
byte Kp = 0;
byte ConstantPrint = NO_PRINT;
boolean SmartDrive = 0;
int mios = 1000; //Maksymalna Ilość Obrotów Silnika

void setup()
{
  Serial.begin(115200);
  Serial.println("Pololu & Arduino Motor Driver by MtK");
  inputString.reserve(200);
  /*md1i2.init();
  md3i4.init();
  md1i2.setM1Speed(0);
  md1i2.setM2Speed(0);
  md3i4.setM1Speed(0);
  md3i4.setM2Speed(0);*/
  initMotor(motor1);
  initMotor(motor2);
  initMotor(motor3);
  initMotor(motor4);
  initMotor(motor5);
  initMotor(motor6);

  PPR = 6;
  RPR = 10;

  Kp = 2;
}

void loop()
{
  if (newMessageReceived)
    handleNewMessage();

  if (SmartDrive)
  {
    slopeCounter1 = 0;
    slopeCounter2 = 0;
    slopeCounter3 = 0;
    slopeCounter4 = 0;
    startingTime = micros();
    for(unsigned i = 0; i<5000; i++)
    {
      if (digitalRead(m1e1) && slopeRise1)
      {
          if(digitalRead(m1e2))
              slopeCounter1--;
          else
              slopeCounter1++;
          slopeRise1 = 0;
          slopeFall1 = 1;
      }

      if (!digitalRead(m1e1) && slopeFall1)
      {
          if(digitalRead(m1e2))
              slopeCounter1++;
          else
              slopeCounter1--;
          slopeRise1 = 1;
          slopeFall1 = 0;
      }
  //----------------------------------------------------------
      if (digitalRead(m2e1) && slopeRise2)
      {
          if(digitalRead(m2e2))
              slopeCounter2--;
          else
              slopeCounter2++;
          slopeRise2 = 0;
          slopeFall2 = 1;
      }

      if (!digitalRead(m2e1) && slopeFall2)
      {
          if(digitalRead(m2e2))
              slopeCounter2++;
          else
              slopeCounter2--;
          slopeRise2 = 1;
          slopeFall2 = 0;
      }
  //----------------------------------------------------------
      if (digitalRead(m3e1) && slopeRise3)
      {
          if(digitalRead(m3e2))
              slopeCounter3--;
          else
              slopeCounter3++;
          slopeRise3 = 0;
          slopeFall3 = 1;
      }

      if (!digitalRead(m3e1) && slopeFall3)
      {
          if(digitalRead(m3e2))
              slopeCounter3++;
          else
              slopeCounter3--;
          slopeRise3 = 1;
          slopeFall3 = 0;
      }
  //----------------------------------------------------------
      if (digitalRead(m4e1) && slopeRise4)
      {
          if(digitalRead(m4e2))
              slopeCounter4--;
          else
              slopeCounter4++;
          slopeRise4 = 0;
          slopeFall4 = 1;
      }

      if (!digitalRead(m4e1) && slopeFall4)
      {
          if(digitalRead(m4e2))
              slopeCounter4++;
          else
              slopeCounter4--;
          slopeRise4 = 1;
          slopeFall4 = 0;
      }
    }

    czas = micros() - startingTime;
  //  Serial.print("#Enkoders, ");
  //  Serial.print(slopeCounter1);
  //  Serial.print(", ");
  //  Serial.print(slopeCounter2);
  //  Serial.print(", ");
  //  Serial.print(slopeCounter3);
  //  Serial.print(", ");
  //  Serial.print(slopeCounter4);
  //  Serial.print(", ");
  //  Serial.println(); // oddzielenie pustą linią dla zwiększenia czytelności
    v1 = slopeCounter1*((60000000)/(RPR*PPR*(long)czas));
    v2 = slopeCounter2*((60000000)/(RPR*PPR*(long)czas));
    v3 = slopeCounter3*((60000000)/(RPR*PPR*(long)czas));
    v4 = slopeCounter4*((60000000)/(RPR*PPR*(long)czas));

    e1 = u[0]-v1;
    e2 = u[1]-v2;
    e3 = u[2]-v3;
    e4 = u[3]-v4;

    PowerOnMotor1 += Kp*e1;
    PowerOnMotor2 += Kp*e2;
    PowerOnMotor3 += Kp*e3;
    PowerOnMotor4 += Kp*e4;

    if(PowerOnMotor1 > 40000)
      PowerOnMotor1 = 40000;
    else if(PowerOnMotor1< -40000)
      PowerOnMotor1 = -40000;

      if(PowerOnMotor2 > 40000)
      PowerOnMotor2 = 40000;
    else if(PowerOnMotor2 < -40000)
      PowerOnMotor2 = -40000;

      if(PowerOnMotor3 > 40000)
      PowerOnMotor3 = 40000;
    else if(PowerOnMotor3 < -40000)
      PowerOnMotor3 = -40000;

      if(PowerOnMotor4 > 40000)
      PowerOnMotor4 = 40000;
    else if(PowerOnMotor4 < -40000)
      PowerOnMotor4 = -40000;

//    if (u1 == 0)
//      SetSpeed(motor1, 0);
//    else
//      SetSpeed(motor1, PowerOnMotor1/100);
//
//    if (u2 == 0)
//      SetSpeed(motor2, 0);
//    else
//      SetSpeed(motor2, PowerOnMotor2/100);
//
//    if (u3 == 0)
//      SetSpeed(motor3, 0);
//    else
//      SetSpeed(motor3, PowerOnMotor3/100);
//
//    if (u4 == 0)
//      SetSpeed(motor4, 0);
//    else
//      SetSpeed(motor4, PowerOnMotor4/100);

      SetSpeed(motor1, u[0]);
      SetSpeed(motor2, u[1]);
      SetSpeed(motor3, u[2]);
      SetSpeed(motor4, u[3]);
      SetSpeed(motor5, u[4]);
      SetSpeed(motor6, u[5]);

      delay(2000);
      u[0]=0;
      u[1]=0;
      u[2]=0;
      u[3]=0;

  }
  else
  {
    PowerOnMotor1 = 0;
    PowerOnMotor2 = 0;
    PowerOnMotor3 = 0;
    PowerOnMotor4 = 0;

    SetSpeed(motor1, PWMSpeed[0]);
    SetSpeed(motor2, PWMSpeed[1]);
    SetSpeed(motor3, PWMSpeed[2]);
    SetSpeed(motor4, PWMSpeed[3]);
    SetSpeed(motor5, PWMSpeed[4]);
    SetSpeed(motor6, PWMSpeed[5]);

  }

  if(ConstantPrint == PRINT_SPEED)
  {
    Serial.println(v1);
    Serial.println(v2);
    Serial.println(v3);
    Serial.println(v4);
  }
}

void serialEvent() {
  while (Serial.available())
  {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
      // if the incoming character is a newline, set a flag
      // so the main loop can do something about it:
      if (inChar == '\n')
        newMessageReceived = true;
  }
}

void handleNewMessage()
{
  int spaceBar = inputString.indexOf(' ');
  if (spaceBar != -1)
  {
    String buffer = "";
    buffer.reserve(10);
    String buffer2 = "";
    buffer2.reserve(10);
    String bufferMotor = "";
    bufferMotor.reserve(10);
    for (int i=0; i<spaceBar; i++)
      buffer += inputString.charAt(i);

//    spaceBar = inputString.indexOf(' ');
    for (int i=spaceBar+1; i<(inputString.length()-1); i++)
      buffer2 += inputString.charAt(i);

    if (buffer == "Set" || buffer == "SetSpeed")
    {
      spaceBar = buffer2.indexOf(' ');
      for (int i=spaceBar+1; i<(buffer2.length()); i++)
        bufferMotor += buffer2.charAt(i);

      //Serial.println("Set command detected!");
      if(bufferMotor=="motor1"){
      u[0]= buffer2.toInt();
      if (u[0]>mios)
          u[0] = mios;
      else if (u[0]<-mios)
          u[0]= -mios;

      e1 = u[0]-v1;
      }
      else if(bufferMotor=="motor2"){
      u[1]= buffer2.toInt();
      if (u[1]>mios)
          u[1]= mios;
      else if (u[1]<-mios)
          u[1]= -mios;

      e2 = u[1]-v2;
      }
      else if(bufferMotor=="motor3"){
       u[2]= buffer2.toInt();
      if (u[2]>mios)
          u[2]= mios;
      else if (u[2]<-mios)
          u[2] = -mios;

      e3 = u[2]-v3;
      }
      else if(bufferMotor=="motor4"){
       u[3]= buffer2.toInt();
      if (u[3]>mios)
          u[3]= mios;
      else if (u[3]<-mios)
          u[3]= -mios;

      e4 = u[3]-v4;
      }
      else if(bufferMotor=="motor5"){
       u[4]= buffer2.toInt();
      if (u[4]>mios)
          u[4]= mios;
      else if (u[3]<-mios)
          u[4]= -mios;
      }
      else if(bufferMotor=="motor5"){
       u[5]= buffer2.toInt();
      if (u[5]>mios)
          u[5]= mios;
      else if (u[5]<-mios)
          u[5]= -mios;
      }
      else if(bufferMotor="all")
      {
        int uForAll = buffer2.toInt();
        if (uForAll > mios)
          uForAll = mios;
        else if (uForAll < -mios)
          uForAll = -mios;

        for(uint8_t i = 0; i<6; i++)
          u[i] = uForAll;

      }

      SmartDrive = 1;
    }
    else if (buffer == "SetKp")
    {
      Kp = buffer2.toInt();
    }
//    else if (buffer == "SetPWM")
//    {
//      if(bufferMotor=="motor1")
//      PWMSpeed1 = 4*buffer2.toInt();
//      else if(bufferMotor=="motor2")
//      PWMSpeed2 = 4*buffer2.toInt();
//      else if(bufferMotor=="motor3")
//      PWMSpeed3 = 4*buffer2.toInt();
//      else if(bufferMotor=="motor4")
//      PWMSpeed4 = 4*buffer2.toInt();
//      SmartDrive = 0;
//    }
    else if (buffer == "Print")
    {
      if(buffer2 == "Speed")
      {
         Serial.println(v1);
         Serial.println(v2);
         Serial.println(v3);
         Serial.println(v4);
         Serial.println();
      }

      else if(buffer2 == "Error")
      {
        Serial.println(e1);
        Serial.println(e2);
        Serial.println(e3);
        Serial.println(e4);
        Serial.println();
      }

      else if(buffer2 == "Power")
      {
        Serial.println(PowerOnMotor1/400);
        Serial.println(PowerOnMotor2/400);
        Serial.println(PowerOnMotor3/400);
        Serial.println(PowerOnMotor4/400);
        Serial.println();
      }

      else if(buffer2 == "ConstSpeed")
          ConstantPrint = PRINT_SPEED;
      else if(buffer2 == "ConstDisable")
          ConstantPrint = NO_PRINT;
    }
    else if(buffer == "Kill")
    {
      SetSpeed(motor1, 0);
      SetSpeed(motor2, 0);
      SetSpeed(motor3, 0);
      SetSpeed(motor4, 0);
      SmartDrive = 0;
    }
  }
  else
    Serial.println("Message ERROR\n\rInvalid command!\n\r");

  newMessageReceived = false;
  inputString = "";
}


actual latest file from 20january

actual latest file from 20january

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/upperman/Wireless-Led-Display.git/'


Initial commit

Initial commit

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

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


AD7173.ino refactor + added setup coding output

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