lay foundation for more sensor drivers

lay foundation for more sensor drivers

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/wsnook/farm.git/'


add wifi control

add wifi control


Added files via upload

Added files via upload

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

--- 002TargetDownCenter/DianaParteInferior.ino
+++ 002TargetDownCenter/DianaParteInferior.ino
@@ -0,0 +1,225 @@
+//Comunicacion i2c
+//1-manager
+//2 diana inferior izqda 3 diana inferior central 4 diana inferior dcha
+//5 diana superior medio 6 diana superior alta
+
+// Receptor - Seria la diana de la feria
+#include <IRremote.h>
+#include <Servo.h>
+#include <Wire.h>
+
+const int ledPin =  13;
+int RECV_PIN = 11;
+Servo myservo;
+int pos = 15;
+boolean Playing;
+IRrecv irrecv(RECV_PIN);
+char MessageReceived;
+unsigned long timer = millis();
+unsigned long time_between_target = 7;
+int randNumber = 0;
+int UpDegrees = 70;  //Grados a los que la diana esta vertical
+int DownDegrees = 10;  //Grados a los que la diana esta abajo
+int Shoots = 0; //Guardaremos el numero de diana y en función de ella modificaremos la dificultad
+boolean TargetUp;
+const int delayForSound = 100;
+
+String texto;
+decode_results results;
+
+void setup()
+{
+  Serial.begin(9600);
+  irrecv.enableIRIn(); // Start the receiver
+  myservo.attach(9);
+  //Serial.println ("Comenzamos...");
+  myservo.write(DownDegrees);
+  delay(15);
+  Playing = false;
+  pinMode(ledPin, OUTPUT);
+  Wire.begin(3);                // join i2c bus with address #2
+  Wire.onReceive(receiveEvent); // register event
+  //Serial.println (millis());ç
+  //Manager.begin(9600);
+
+}
+
+void (* resetFunc) (void) = 0;
+
+
+void loop() {
+  //Esperamos la señal de que comience la partida -1(49) - Acabar la partida 0 (48) - 2 modo demo (50) - 3 tiro acertado (51)
+
+
+  if (Playing)
+  {
+
+
+
+    if ((timer < millis()) && (!TargetUp))
+    { //levantamos la diana transcurrido un tiempo aleatorio desde el ultimo blanco
+      Wire.beginTransmission(1); // transmit to device #1
+      Wire.write("go001");              // sends one byte
+      Wire.endTransmission();    // stop transmitting
+      delay (delayForSound);
+      for (pos = DownDegrees; pos <= UpDegrees; pos += 1) // goes from 0 degrees to 180 degrees
+      { // in steps of 1 degree
+        myservo.write(pos);              // tell servo to go to position in variable 'pos'
+        delay(5);                       // waits 5ms for the servo to reach the position
+      }
+      TargetUp = true;
+
+      //bajaremos la diana en 1-5 segundos depende de la dificultad
+
+      switch (Shoots) {
+        case  2:
+          time_between_target = 5;
+          //Serial.println (time_between_target);
+          break;
+        case  3:
+          time_between_target = 4;
+          //Serial.println (time_between_target);
+          break;
+
+        case  5:
+          time_between_target = 3;
+          //Serial.println (time_between_target);
+          break;
+
+        case  7:
+          time_between_target = 1;
+          //Serial.println (time_between_target);
+          break;
+      }
+    }
+
+    if (timer + (time_between_target * 1000) < millis()) //Si ha pasado el tiempo marcado desde el ultimo tiro, bajamos la diana
+    {
+      //      Serial.println (timer);
+      //      Serial.println (time_between_target * 1000);
+      //      Serial.println (timer + (time_between_target * 1000) );
+      //      Serial.println (millis());
+      //      Serial.println ("Aqui2");
+      Wire.beginTransmission(1); // transmit to device #1
+      Wire.write("nok001");              // sends one byte
+      Wire.endTransmission();    // stop transmitting
+      for (pos = UpDegrees; pos >= DownDegrees; pos -= 1)
+      {
+        myservo.write(pos);
+        delay(5);
+      }
+      TargetUp = false;
+      randNumber = random(2, time_between_target);
+      //Serial.println (randNumber);
+      timer = randNumber * 1000 + millis();
+      randomSeed(analogRead(0));
+      irrecv.resume(); // Receive the next value
+      //      Serial.println (timer);
+      //      Serial.println (millis());
+      //      Serial.println ("Aqui3");
+
+    }
+
+
+
+    if (irrecv.decode(&results) && TargetUp) {
+      //Serial.println(results.value, DEC);
+      irrecv.resume(); // Receive the next value
+      if (results.value == 2704)  //valor que dispara el emisor de infrarrojos (apagado de tele sony)
+      {
+        //Serial.print ("Blanco: ");
+        //Manager.listen();
+        Wire.beginTransmission(1); // transmit to device #1
+        Wire.write("ok001");              // sends one byte
+        Wire.endTransmission();    // stop transmitting
+        myservo.write(UpDegrees - 30);
+        delay (1500);
+        Shoots = Shoots + 1;
+        randNumber = random(2, time_between_target);
+        //Serial.println (randNumber);
+        timer = randNumber * 1000 + millis();
+        randomSeed(analogRead(0));
+        //Serial.println (timer);
+        //Serial.println (millis());
+        for (pos = UpDegrees - 30; pos >= DownDegrees; pos -= 1) // goes from 180 degrees to 0 degrees
+        {
+          myservo.write(pos);              // tell servo to go to position in variable 'pos'
+          delay(5);                       // waits 15ms for the servo to reach the position
+        }
+        TargetUp = false;
+        irrecv.resume();
+        //Serial.println (pos);
+        //delay(300);
+      }
+    }
+
+  }
+
+
+}
+
+// function that executes whenever data is received from master
+// this function is registered as an event, see setup()
+void receiveEvent(int howMany) {
+  while ( Wire.available()) { // loop through all but the last
+    char c = Wire.read(); // receive byte as a character
+    texto = texto + c;
+    Serial.print(c);         // print the character
+  }
+
+  if (texto == "rst")
+  {
+    resetFunc();
+  }
+  if (texto == "go")
+  {
+    Playing = true;
+    Serial.println ("Comienza la partida!!");
+    randomSeed(analogRead(0));
+    for (pos = DownDegrees; pos <= UpDegrees; pos += 1) // goes from 0 degrees to 180 degrees
+    { // in steps of 1 degree
+      myservo.write(pos);              // tell servo to go to position in variable 'pos'
+      delay(5);                       // waits 15ms for the servo to reach the position
+      time_between_target = 7;
+      Shoots = 0;
+      digitalWrite(ledPin, HIGH);
+
+    }
+    TargetUp = true;
+    timer = millis();
+  }
+  if (texto == "end")
+  {
+    Playing = false;
+    Serial.println ("Fin de la partida!!");
+    for (pos = UpDegrees; pos >= DownDegrees; pos -= 1) // goes from 180 degrees to 0 degrees
+    {
+      myservo.write(pos);              // tell servo to go to position in variable 'pos'
+      delay(5);                       // waits 5ms for the servo to reach the position
+    }
+    TargetUp = false;
+    Shoots = 0;
+    digitalWrite(ledPin, LOW);
+  }
+  if (texto == "gup")
+  {
+
+    myservo.write(UpDegrees);
+  }
+  if (texto == "gdo")
+  {
+
+    myservo.write(DownDegrees);
+  }
+  if (texto == "gme")
+  {
+
+    myservo.write(UpDegrees / 2);
+  }
+
+
+
+  texto = "";
+
+
+}


Added Initial Commit

Added Initial Commit

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

--- arduino/temperature.ino
+++ arduino/temperature.ino
@@ -0,0 +1,19 @@
+#include "C:\Intel\arduino-1.6.5\libraries\rgb_lcd.h"
+
+rgb_lcd lcd;
+
+
+const int colorG = 0;
+const int colorR = 0;
+const int colorB = 255;
+
+void setup() {
+  // put your setup code here, to run once:
+  lcd.begin(16, 2);
+  lcd.setRGB(colorR, colorG, colorB);
+    lcd.print("Temperature is");
+}
+
+void loop() {
+
+}


New example sketch to demonstrate maximum rate transmission over TCP

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

--- examples/max_tx/max_tx.ino
+++ examples/max_tx/max_tx.ino
@@ -0,0 +1,109 @@
+/*
+ * File                 basic_tx.ino
+ *
+ * Synopsis             Simple example sketch to demonstrate transmission of data
+ *                      at the highest possible rate
+ *
+ * Author               Chris Bearman
+ *
+ * Version              1.0
+ */
+#include <XbeeWifi.h>
+
+// These are the pins that we are using to connect to the Xbee
+#define XBEE_RESET 15
+#define XBEE_ATN 2
+#define XBEE_SELECT SS
+#define XBEE_DOUT 23
+
+// These are the configuration parameters we're going to use
+#define CONFIG_ENCMODE XBEE_SEC_ENCTYPE_WPA2     // Network type is WPA2 encrypted
+#define CONFIG_SSID "Example"                    // SSID
+#define CONFIG_KEY "whatever"                    // Password
+
+// Create an xbee object to handle things for us
+XbeeWifi xbee;
+
+// Setup routine
+
+// Size and buffer to hold our test data
+#define TEST_FRAME_SIZE 1024
+char testFrame[TEST_FRAME_SIZE];
+
+void setup()
+{
+  // Serial at 57600
+  Serial.begin(57600);
+
+  // Initialize the xbee
+  bool result = xbee.init(XBEE_SELECT, XBEE_ATN, XBEE_RESET, XBEE_DOUT);
+
+  if (result) {
+    // Initialization okay so far, send setup parameters - if anything fails, result goes false
+    result &= xbee.at_cmd_byte(XBEE_AT_NET_TYPE, XBEE_NET_TYPE_IBSS_INFRASTRUCTURE);
+    result &= xbee.at_cmd_str(XBEE_AT_NET_SSID, CONFIG_SSID);
+    result &= xbee.at_cmd_byte(XBEE_AT_NET_ADDRMODE, XBEE_NET_ADDRMODE_DHCP);
+    result &= xbee.at_cmd_byte(XBEE_AT_SEC_ENCTYPE, CONFIG_ENCMODE);
+    if (CONFIG_ENCMODE != XBEE_SEC_ENCTYPE_NONE) {
+      result &= xbee.at_cmd_str(XBEE_AT_SEC_KEY, CONFIG_KEY);
+    }
+  }
+
+  if (!result) {
+    // Something failed
+    Serial.println("XBee Init Failed");
+    while (true) { /* Loop forever - game over */}
+  } else {
+    Serial.println("XBee found and configured");
+  }
+
+  // Set up data in test frame
+  for (int i = 0 ; i < TEST_FRAME_SIZE; i++) {
+    testFrame[i] = 65 + (i % 26);  //(A thru Z, repeating)
+  }
+
+}
+
+// To help split lines
+int split = 0;
+
+// Main run loop
+// Transmit "Hello World" on UDP, to 192.168.1.150 every 1 minute (using port 12345)
+void loop()
+{
+  // Process the XBEE
+  xbee.process();
+
+  if (xbee.last_status != XBEE_MODEM_STATUS_JOINED) {
+    Serial.println("Not yet up and running");
+    delay(1000);
+  } else {
+    // Create an s_txoptions object to describe the port, protocol and behaviors
+    s_txoptions txopts;
+    txopts.dest_port=12345;
+    txopts.source_port=12345;
+    txopts.leave_open=true;
+    txopts.protocol = XBEE_NET_IPPROTO_TCP;  // Change to UDP if desired
+
+    // Create a binary IP address representation
+    char ip[] = { 192, 168, 1, 150 };
+
+    // Transmit the frame
+    // You could turn off frame confirmation (add false as fifth option) but you'll overwhelm the device and loose
+    // most data unless you can tweak your transmits to exactly the best intervals...
+    if (xbee.transmit((uint8_t *)ip, &txopts, (uint8_t *)testFrame, TEST_FRAME_SIZE)) {
+      // Send "o" to serial for sent Okay
+      Serial.print("o");
+    } else {
+      // "X" if send failed
+      Serial.print("X");
+    }
+
+    // Start a new line every sixty or so characters
+    if ((++split % 60) == 0) {
+      Serial.println("");
+    }
+  }
+}
+
+


second .ino start of actual implementation.

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

--- Twisted_Python_Server_Serial/workingPythonSerialMotorControl_v2/workingPythonSerialMotorControl_v2/workingPythonSerialMotorControl_v2.ino
+++ Twisted_Python_Server_Serial/workingPythonSerialMotorControl_v2/workingPythonSerialMotorControl_v2/workingPythonSerialMotorControl_v2.ino
@@ -0,0 +1,48 @@
+#include <Smartcar.h>
+
+Car car;
+
+boolean commandComplete = false;  // whether the string is complete
+int speed;
+int angle;
+
+void setup() {
+  car.begin(); //initialize the car using the encoders and the gyro
+  Serial.begin(9600);
+
+}
+
+void loop() {
+
+  if (commandComplete) {
+
+    car.setSpeed(speed);
+    car.setAngle(angle);
+
+
+
+    commandComplete = false;
+  }
+
+}
+
+/*
+  SerialEvent occurs whenever a new data comes in the
+ hardware serial RX.  This routine is run between each
+ time loop() runs, so using delay inside loop can delay
+ response.  Multiple bytes of data may be available.
+ */
+void serialEvent() {
+  int i = 0;
+  while (Serial.available()) {
+    i++;
+    byte bytearray[7] = (byte)Serial.read();
+    Serial.println();
+
+
+
+    if (bytearray[i] == '\n') {
+      commandComplete = true;
+    }
+  }
+}


moved LCD_Scope_example to examples folder

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

--- examples/LCD_Scope_example/LCD_Scope_example.ino
+++ examples/LCD_Scope_example/LCD_Scope_example.ino
@@ -0,0 +1,44 @@
+// simple (real-time) sinewave refresh and draw
+
+// test LCD screen dimensions with 2 pots connected on A0 and A1 (x, y)
+
+#include <UTFT.h>
+
+int px=0, x=1;
+float py=0, y=0;
+float sinewave;
+float inc = 0.1;
+
+UTFT lcd(CTE32HR,38,39,40,41);
+
+void setup(){
+  Serial.begin(9600);
+  lcd.InitLCD(LANDSCAPE);
+  lcd.clrScr();
+}
+
+void loop(){
+  if(Serial.available() > 0){
+    inc = Serial.parseFloat();
+    Serial.println(inc);
+  }
+
+  // draw sine behind
+  lcd.setColor(VGA_RED);
+  sinewave+= inc;
+  if(sinewave>6.28) sinewave = 0.f;
+  py = y;
+  y = 160-(sin(sinewave) * 80.f);
+
+  x++;
+  if(x > 479) x = 0;
+  px = x-1;
+  lcd.drawLine(px, py, x, y);
+
+  //clear vertical line ahead
+  lcd.setColor(VGA_BLACK);
+  if(x<1) lcd.drawLine(0, 0, 0, 319);
+  lcd.drawLine(x+1, 0, x+1, 319);
+
+  delay(5);
+}


measure conversion speed for all settings

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

--- examples/conversionSpeed/conversionSpeed.ino
+++ examples/conversionSpeed/conversionSpeed.ino
@@ -0,0 +1,128 @@
+/* Example for analogContinuousRead
+*  It measures continuously the voltage on pin A9,
+*  Write v and press enter on the serial console to get the value
+*  Write c and press enter on the serial console to check that the conversion is taking place,
+*  Write t to check if the voltage agrees with the comparison in the setup()
+*  Write s to stop the conversion, you can restart it writing r.
+*/
+
+#include <ADC.h>
+#include <ADC_util.h>
+
+const int readPin = A2; // ADC0 or ADC1
+
+volatile uint32_t value = 0;
+#if defined(ADC_TEENSY_4)
+const uint32_t NUM_SAMPLES = 10000;
+#else
+const uint32_t NUM_SAMPLES = 1000;
+#endif
+uint32_t num_samples = NUM_SAMPLES;
+elapsedMicros timeElapsed;
+volatile uint32_t num_iter = 0;
+
+ADC *adc = new ADC(); // adc object
+
+void setup() {
+
+    pinMode(LED_BUILTIN, OUTPUT);
+    pinMode(readPin, INPUT_PULLUP);
+
+    Serial.begin(9600);
+    delay(100);
+
+    // Single-shot conversions. The fastest way to do conversions is with continuous mode (see below)
+    Serial.println("Single-shot conversion speeds.");
+    for(auto average : averages_list) {
+      adc->setAveraging(average, ADC_0); // set number of averages
+      for (auto resolution : resolutions_list) {
+        adc->setResolution(resolution, ADC_0); // set bits of resolution
+        for (auto conv_speed : conversion_speed_list) {
+            adc->setConversionSpeed(conv_speed, ADC_0); // change the conversion speed
+            for (auto samp_speed: sampling_speed_list) {
+                adc->setSamplingSpeed(samp_speed, ADC_0); // change the sampling speed
+
+                adc->adc0->wait_for_cal();
+
+                num_samples = (int)NUM_SAMPLES/average;
+
+                timeElapsed = 0;
+                value = 0;
+                for(uint32_t i=0; i<num_samples; i++) {
+                    value += adc->adc0->analogRead(readPin);
+                }
+                double time_us = (float)timeElapsed/num_samples;
+                Serial.print("Average: "); Serial.print(average);
+                Serial.print(", Resolution: "); Serial.print(resolution);
+                Serial.print(", Conversion speed: "); Serial.print(getConversionEnumStr(conv_speed));
+                Serial.print(", Sampling speed: "); Serial.print(getSamplingEnumStr(samp_speed));
+                Serial.print(". Time: "); Serial.print(time_us); Serial.print(" us.");
+                Serial.print(" Value: "); Serial.println(value/num_samples*1.0/adc->adc0->getMaxValue(), 6);
+              }
+            }
+        }
+    }
+
+
+    // Continuous mode
+    Serial.println("Continuous mode conversion speeds.");
+    adc->enableInterrupts(adc0_isr, ADC_0);
+    for(auto average : averages_list) {
+      adc->setAveraging(average, ADC_0); // set number of averages
+      for (auto resolution : resolutions_list) {
+        adc->setResolution(resolution, ADC_0); // set bits of resolution
+        for (auto conv_speed : conversion_speed_list) {
+            adc->setConversionSpeed(conv_speed, ADC_0); // change the conversion speed
+            for (auto samp_speed: sampling_speed_list) {
+                adc->setSamplingSpeed(samp_speed, ADC_0); // change the sampling speed
+
+                adc->adc0->wait_for_cal();
+
+                num_samples = NUM_SAMPLES/average;
+
+                value = 0;
+                num_iter = 0;
+                timeElapsed = 0;
+                adc->startContinuous(readPin, ADC_0);
+                while (num_iter<num_samples) {}
+                double time_us = (float)timeElapsed/num_samples;
+                adc->stopContinuous(ADC_0);
+                Serial.print("Average: "); Serial.print(average);
+                Serial.print(", Resolution: "); Serial.print(resolution);
+                Serial.print(", Conversion speed: "); Serial.print(getConversionEnumStr(conv_speed));
+                Serial.print(", Sampling speed: "); Serial.print(getSamplingEnumStr(samp_speed));
+                Serial.print(". Time: "); Serial.print(time_us); Serial.print(" us.");
+                Serial.print(" Value: "); Serial.println(value/num_samples*1.0/adc->adc0->getMaxValue(), 6);
+              }
+            }
+        }
+    }
+}
+
+
+void loop() {
+    // Print errors, if any.
+    if(adc->adc0->fail_flag != ADC_ERROR::CLEAR) {
+      Serial.print("ADC0: "); Serial.println(getStringADCError(adc->adc0->fail_flag));
+    }
+    #if ADC_NUM_ADCS > 1
+    if(adc->adc1->fail_flag != ADC_ERROR::CLEAR) {
+      Serial.print("ADC1: "); Serial.println(getStringADCError(adc->adc1->fail_flag));
+    }
+    #endif
+
+    digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
+
+    delay(100);
+
+}
+
+void adc0_isr(void) {
+    if(num_iter<num_samples) {
+      value += (uint16_t)adc->adc0->analogReadContinuous();
+      num_iter++;
+    } else { // clear interrupt
+      adc->adc0->analogReadContinuous();
+    }
+    //digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN));
+}


Add arduino code.

Add arduino code.

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

--- arduino/arduino_md03_v_4_0.ino
+++ arduino/arduino_md03_v_4_0.ino
@@ -0,0 +1,179 @@
+/***************************************************
+           ArcEyes MD03 I2C sandbox
+             by David Wilman
+   MD03 over I2C code by By James Henderson 2012
+****************************************************/
+
+#include <Wire.h>
+#include <LCD.h>
+#include <LiquidCrystal_I2C.h>
+
+ //int LCD pins on I2C bus
+ #define I2C_ADDR 0x27
+ #define BACKLIGHT_PIN 3
+ #define En_pin  2
+ #define Rw_pin  1
+ #define Rs_pin  0
+ #define D4_pin  4
+ #define D5_pin  5
+ #define D6_pin  6
+ #define D7_pin  7
+ LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
+
+#define address_1           0x58                     // Address of MD03 1
+#define address_2           0x59                     // Address of MD03 2
+#define address_3           0x5A                     // Address of MD03 3
+#define SOFTREG             0x07                    // Byte to read software
+#define CMDBYTE             0x00                    // Command byte
+#define SPEEDBYTE           0x02                    // Byte to write to speed register
+#define TEMPREG             0x04                    // Byte to read temprature
+#define CURRENTREG          0x05                    // Byte to read motor current
+
+const int potPin1 = A0;
+const int potPin2 = A1;
+const int potPin3 = A2;
+const int rlyPin1 = 7; // Relay Pin for break
+const int rlyPin2 = 8; // Relay Pin for break
+const int rlyPin3 = 9; // Relay Pin for break
+byte direct1 = 1; // Stores what direction the motor should run in
+byte direct2 = 1; // Stores what direction the motor should run in
+byte direct3 = 1; // Stores what direction the motor should run in
+//int temp = 0;
+int temp1 = 0; // store the temp read from MD03
+int temp2 = 0; // store the temp read from MD03
+int temp3 = 0; // store the temp read from MD03
+//float current = 0; // store the current read from MD03
+float current1 = 0; // store the current read from MD03
+float current2 = 0; // store the current read from MD03
+float current3 = 0; // store the current read from MD03
+//float speedControl = 0; //store the current speed
+float speedControl1 = 0; //store the current speed
+float speedControl2 = 0; //store the current speed
+float speedControl3 = 0; //store the current speed
+long previousMillis = 0;  // store the time LCD was last updated
+long interval = 50; // time setween lcd updates
+
+
+//serial
+String inputString = "";         // a string to hold incoming data
+boolean stringComplete = false;  // whether the string is complete
+
+
+
+void setup(){
+  Wire.begin(); //start I2C bus
+  delay(100); //wait for bus to stabalise
+  pinMode(rlyPin1,OUTPUT); // Setup pins
+  pinMode(rlyPin2,OUTPUT); // Setup pins
+  pinMode(rlyPin3,OUTPUT); // Setup pins
+  lcd.begin (16,2); // 2 rows x 16 char
+  // Switch on the backlight
+  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
+  lcd.setBacklight(HIGH);
+  lcd.clear();
+  lcd.setCursor(0,0);
+  lcd.print("ArcEyes MD03 I2C");
+  lcd.setCursor(0,1);
+  lcd.print("SandBox");
+  delay(30);
+  //lcd.clear();
+
+
+  //serial
+
+    Serial.begin(9600);
+  // reserve 200 bytes for the inputString:
+  inputString.reserve(200);
+}
+
+void loop(){
+  direct1 = manualSpeedControl(address_1, potPin1, rlyPin1, direct1, speedControl1);
+  direct2 = manualSpeedControl(address_2, potPin2, rlyPin2, direct2, speedControl2);
+  direct3 = manualSpeedControl(address_3, potPin3, rlyPin3, direct3, speedControl3);
+
+    // print the string when a newline arrives:
+  if (stringComplete) {
+    Serial.println(inputString);
+    // clear the string:
+    inputString = "";
+    stringComplete = false;
+  }
+
+
+}
+
+
+byte manualSpeedControl(int address, byte potPin, int rlyPin, byte direct, int speedControl){
+    int potVal = analogRead(potPin);
+    if(potVal < 450){               //Sets reverse speed from Pot1
+      digitalWrite(rlyPin, LOW);
+      speedControl = map(potVal, 450, 0, 0, 250);
+      direct = 1;
+    }
+    else if(potVal < 573){          // sets zero speed from Pot1
+      digitalWrite(rlyPin, HIGH);
+      speedControl = 0;
+    }
+    else if (potVal >= 574){        // sets forward speed from Pot1
+      digitalWrite(rlyPin, LOW);
+      speedControl = map(potVal, 574, 1023, 0, 250);
+      direct = 2;
+    }
+    sendData(address, SPEEDBYTE, speedControl);
+    sendData(address, CMDBYTE, direct);
+    int temp = getData(address, TEMPREG);            // Gets temperature
+    delay(50);
+    int current = map(getData(address, CURRENTREG), 0, 186, 0 ,20000);      // Gets motor current, scale to give output in mA
+    current = (current/1000) - 0.32; //convert to A
+    delay(50);
+    return direct;
+}
+
+byte getData(int address, byte reg){                   // function for getting data from MD03
+  Wire.beginTransmission(address);
+  Wire.write(reg);
+  Wire.endTransmission();
+
+  byte data = 0;
+  //for (int i; i<100; i++){
+    Wire.requestFrom(address, 1);         // Requests byte from MD03
+    while(Wire.available() < 1);          // Waits for byte to become availble
+    data = Wire.read();
+    //}
+
+  return(data);
+}
+
+void sendData(int address, byte reg, byte val){         // Function for sending data to MD03
+  Wire.beginTransmission(address);         // Send data to MD03
+    Wire.write(reg);
+    Wire.write(val);
+  Wire.endTransmission();
+}
+
+/*
+  SerialEvent occurs whenever a new data comes in the
+ hardware serial RX.  This routine is run between each
+ time loop() runs, so using delay inside loop can delay
+ response.  Multiple bytes of data may be available.
+ */
+void serialEvent() {
+  while (Serial.available()) {
+    // get the new byte:
+    char inChar = (char)Serial.read();
+    lcd.clear();
+    lcd.setCursor(0,0);
+    lcd.print(inChar);
+    // add it to the inputString:
+    inputString += inChar;
+    // if the incoming character is a newline, set a flag
+    // so the main loop can do something about it:
+    if (inChar == '\n') {
+      stringComplete = true;
+    }
+  }
+  lcd.clear();
+  lcd.setCursor(0,0);
+  lcd.print(inputString);
+
+}


fifth

fifth

--- dreifachblinker.ino
+++ dreifachblinker.ino
@@ -0,0 +1,59 @@
+const int ledPin1 = 8;
+const int ledPin2 = 10;
+const int ledPin3 = 12;
+
+int ledState1 = LOW;
+int ledState2 = LOW;
+int ledState3 = LOW;
+
+unsigned long previousMillis1 = 0;
+unsigned long previousMillis2 = 0;
+unsigned long previousMillis3 = 0;
+
+int led1int = 500;
+int led2int = 1000;
+int led3int = 1500;
+
+void setup() {
+  pinMode(ledPin1, OUTPUT);
+  pinMode(ledPin2, OUTPUT);
+  pinMode(ledPin3, OUTPUT);
+  pinMode(taster, INPUT);
+}
+
+  void loop() {
+    unsigned long currentMillis = millis();
+    if (currentMillis - previousMillis1 >= led1int) {
+    previousMillis1 = currentMillis;
+
+      if (ledState1 == LOW) {
+      ledState1 = HIGH;
+      } else {
+      ledState1 = LOW;
+      }
+}
+
+        if (currentMillis - previousMillis2 >= led2int) {
+        previousMillis2 = currentMillis;
+
+          if (ledState2 == LOW) {
+          ledState2 = HIGH;
+          } else {
+          ledState2 = LOW;
+          }
+}
+
+      if (currentMillis - previousMillis3 >= led3int) {
+      previousMillis3 = currentMillis;
+
+      if (ledState3 == LOW) {
+      ledState3 = HIGH;
+      } else {
+      ledState3 = LOW;
+      }
+}
+
+  digitalWrite(ledPin1, ledState1);
+  digitalWrite(ledPin2, ledState2);
+  digitalWrite(ledPin3, ledState3);
+  }


Create Blink.ino

Create Blink.ino

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

--- examples/Blink/Blink.ino
+++ examples/Blink/Blink.ino
@@ -0,0 +1,12 @@
+#include "microbit_Screen.h"
+
+void setup() {
+  SCREEN.begin();      // initialize LED screen
+}
+
+void loop() {
+  SCREEN.plot(2, 2);   // turn the LED (2,2) on
+  delay(1000);         // wait for a second
+  SCREEN.unplot(2, 2); // turn the LED (2,2) off
+  delay(1000);         // wait for a second
+}


Sleep Demo Added

Sleep Demo Added

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

--- examples/Sleep/Sleep.ino
+++ examples/Sleep/Sleep.ino
@@ -0,0 +1,103 @@
+int RED = A2;
+int YELLOW = A3;
+int GREEN = 13;
+int BUTTON = 2;
+
+#include <avr/sleep.h>          // library for sleep
+#include <avr/power.h>          // library for power control
+
+int currentState = 0;
+
+void setup() {
+  // put your setup code here, to run once:
+  pinMode(RED,OUTPUT);
+  pinMode(GREEN,OUTPUT);
+  pinMode(YELLOW,OUTPUT);
+  pinMode(BUTTON,INPUT_PULLUP);
+  digitalWrite(RED, LOW);
+  digitalWrite(GREEN, LOW);
+  digitalWrite(YELLOW, LOW);
+
+  pinMode(BUTTON, INPUT);
+  // https://www.arduino.cc/en/Reference/AttachInterrupt
+  attachInterrupt(digitalPinToInterrupt(BUTTON), newState, FALLING);
+
+  showLights();
+}
+
+
+
+void showLights() {
+  switch (currentState) {
+    case 0:
+      digitalWrite(RED,HIGH);
+      digitalWrite(YELLOW,LOW);
+      digitalWrite(GREEN, LOW);
+      break;
+    case 1:
+      digitalWrite(RED,HIGH);
+      digitalWrite(YELLOW,HIGH);
+      digitalWrite(GREEN, LOW);
+      break;
+    case 2:
+      digitalWrite(RED,LOW);
+      digitalWrite(YELLOW,LOW);
+      digitalWrite(GREEN, HIGH);
+      break;
+    case 3:
+      digitalWrite(RED,LOW);
+      digitalWrite(YELLOW,HIGH);
+      digitalWrite(GREEN, LOW);
+      break;
+  }
+}
+
+void newState() {
+  switch (currentState) {
+    case 0:
+      currentState = 1;
+      break;
+    case 1:
+      currentState = 2;
+      break;
+    case 2:
+      currentState = 3;
+      break;
+    case 3:
+      currentState = 0;
+      break;
+  }
+  showLights();
+}
+
+// Put the Arduino to deep sleep. Only an interrupt can wake it up.
+void sleep()
+{
+
+  // Set sleep to full power down.  Only external interrupts or
+  // the watchdog timer can wake the CPU!
+  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+
+  // Turn off the ADC while asleep.
+  power_adc_disable();
+
+  // Enable sleep and enter sleep mode.
+  sleep_mode();
+
+  // CPU is now asleep and program execution completely halts!
+  // Once awake, execution will resume at this point if the
+  // watchdog is configured for resume rather than restart
+
+  // When awake, disable sleep mode
+  sleep_disable();
+
+  // put everything on again
+  power_all_enable();
+
+}
+
+
+void loop() {
+  showLights();
+  sleep();
+}


Create neato.ino

Create neato.ino

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

--- neato.ino
+++ neato.ino
@@ -0,0 +1,234 @@
+
+
+
+double angle=0;
+int r=115;
+int rMin=15;
+int x2;
+int y2;
+int cY;
+int cX;
+unsigned int distance;
+unsigned int distance_array[360];
+unsigned char distanceLow=0;
+unsigned char distanceHigh=0;
+unsigned char flag1=0;
+unsigned char flag2=0;
+
+const int DesiredRPM=300;  // Setting Desired RPM Here.
+const int MotorPWMPin=8;
+
+
+int inByte = 0;         // incoming serial byte
+unsigned char Data_status=0;
+unsigned char Data_4deg_index=0;
+unsigned char Data_loop_index=0;
+unsigned char SpeedRPHhighbyte=0; //
+unsigned char SpeedRPHLowbyte=0;
+
+int SpeedRPH=0;
+const unsigned char PWM4dutyMax=255;
+const unsigned char PWM4dutyMin=100;
+//const unsigned char PWM4dutyMin=178;
+unsigned char PWM4duty=PWM4dutyMin;  // have to set a default value make motor start spining
+
+ void setup() {
+    pinMode(MotorPWMPin, OUTPUT);
+
+    analogWrite(MotorPWMPin, PWM4dutyMin);
+    Serial.begin(115200);  // USB serial
+    Serial3.begin(115200);  // XV-11 LDS data
+
+
+  // prints title with ending line break
+  Serial.println("Arduino Neato XV-11 Motor control board v0.1 by Cheng-Lung Lee");  // thanks!
+
+  // Pick your magic number and drive your motor , 178 is 178/255*5V=3.49V
+    analogWrite(MotorPWMPin, PWM4duty);
+
+
+
+    char CharMsg[4];
+    itoa(r,CharMsg,10);
+
+}
+
+void loop() {
+    // if we get a valid byte from LDS, read it and send it to USB-serial
+  if (Serial3.available() > 0) {
+    // get incoming byte:
+    inByte = Serial3.read();
+    //Serial.write(inByte);
+    decodeData(inByte);
+  }
+
+}
+
+void decodeData(unsigned char inByte){
+
+  switch (Data_status){
+
+  case 0: // no header
+    if (inByte==0xFA){
+      Data_status=1;
+      Data_loop_index=1;
+    }
+  break;
+
+  case 1: // Find 2nd FA
+    if (Data_loop_index==22){
+      if (inByte==0xFA){
+        Data_status=2;
+        Data_loop_index=1;
+      }else // if not FA search again
+       Data_status=0;
+    }else{
+      Data_loop_index++;
+    }
+    break;
+
+  case 2: // Read data out
+
+    if (Data_loop_index==22){
+      if (inByte==0xFA){
+        Data_loop_index=1;
+      }
+      else // if not FA search again
+      Data_status=0;
+    }else{
+      readData(inByte);
+      Data_loop_index++;
+    }
+    break;
+  }
+
+}
+void readData(unsigned char inByte){
+
+  switch (Data_loop_index){
+
+    case 1: // 4 degree index
+    Data_4deg_index=inByte-0xA0;
+//      Serial.print(Data_4deg_index, HEX);
+
+
+    break;
+
+    case 2: // Speed in RPH low byte
+    SpeedRPHLowbyte=inByte;
+    break;
+
+    case 3: // Speed in RPH high byte
+    SpeedRPHhighbyte=inByte;
+    SpeedRPH=(SpeedRPHhighbyte<<8)|SpeedRPHLowbyte;
+
+    SpeedControl(DesiredRPM);
+
+
+    break;
+
+
+    case 4:
+    case 8:
+    case 12:
+    case 16:
+    distanceLow=inByte;
+    break;
+
+    case 5:
+    case 9:
+    case 13:
+    case 17:
+    distanceHigh=inByte & B00111111; //mask 14 and 15 bits
+    //distanceHigh=inByte & B11111100; //mask 14 and 15 bits
+
+    flag1=inByte & B10000000;
+    flag2=inByte & B01000000;
+
+    distance=(distanceHigh<<8)|distanceLow;
+
+
+
+     if (true){
+
+      int dataIndex;
+      switch (Data_loop_index){
+       case 5:
+         dataIndex=0;
+       break;
+       case 9:
+         dataIndex=1;
+       break;
+       case 13:
+         dataIndex=2;
+       break;
+       case 17:
+         dataIndex=3;
+       break;
+      }
+
+      int angleIndex=Data_4deg_index*4 + dataIndex;
+
+  if (flag1==0 && flag2==0){
+
+        distance_array[angleIndex]=distance;
+
+      }else{
+        distance_array[angleIndex]=0;
+      }
+
+
+
+
+
+  if (dataIndex==3 && Data_4deg_index==89) drawMap();
+
+   }
+   break;
+
+
+    default: // others do checksum
+
+    break;
+
+
+  }
+
+
+
+
+}
+
+
+// Very simple speed control
+void SpeedControl ( int RPMinput)
+{
+// if (Data_4deg_index%30==0) {  // I only do 3 updat I feel it is good enough for now
+ if (Data_4deg_index%40==0) {  // I only do 3 updat I feel it is good enough for now
+  if (SpeedRPH<RPMinput*60)
+     if (PWM4duty<PWM4dutyMax) PWM4duty++; // limit the max PWM make sure it don't overflow and make LDS stop working
+  if (SpeedRPH>RPMinput*60)
+     if(PWM4duty>PWM4dutyMin) PWM4duty--;  //Have to limit the lowest pwm keep motor running
+  }
+  analogWrite(MotorPWMPin, PWM4duty ); // update value
+}
+
+
+void drawMap(){
+  for (int i=0;i<360;i++){
+    int distMax=6000;
+    int d=distance_array[i];
+    distance_array[i]=0;
+    if (d==0 || d>distMax)continue;
+
+
+    int r2=map(d, 0, distMax, 0, 115);
+
+
+    Serial.print(i);
+    Serial.print(" D:");
+    Serial.println(r2);
+    //to radians
+    double rad_angle= i * 3.1415 / 180;
+  }
+}


Delete blink_test.ino

Delete blink_test.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/pylonman/simple_gpio_class.git/'


ciclosonar.ino

ciclosonar.ino

Codigo do arduino

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

--- ciclosonar.ino
+++ ciclosonar.ino
@@ -0,0 +1,245 @@
+/*
+PROGRAMA CICLOSSONAR
+Versão 0.2
+Pedro Luiz Santos e Daniel Valença
+Data de modificacao: 2015.01.08
+*/
+
+/*
+MARCO LEGAL:
+É definida a distância conforme o Código Brasileiro de Trânsito
+em seu artigo 201, como 1,5m o mínimo para ultrapassagem de um
+ciclista pelo motorista. No artigo XXX é definido que deve-se
+diminuir a velocidade ao ultrapassar os ciclistas para uma
+compatível com a seguraça.
+
+OBJETIVOS:
+O projeto Ciclossonar tem como objetivo medir a distância
+que os motoristas passam ao ultrapassar os ciclistas e com
+isso fomentar políticas públicas que reduzam acidentes e
+estimulem um trânsito seguro e humano.
+
+OBJETIVOS ESPECÍFICOS:
+1 - Medir a distância em cada ponto da bicicleta
+2 - Medir a velocidade do ciclista
+3 - Medir a velocidade relativa do motorista com o ciclista
+4 - Medir a velocidade do motorista
+5 - Medir o tamanho do veículo que realiza ultrapassagem
+6 - Quantificar a quantidade de finos que o ciclista recebe:
+6.1 - Ao passar em ruas mais ou menos movimentadas
+6.2 - Por andar no canto ou mais ao centro da faixa
+6.3 - Conforme seu sexo
+6.4 - Conforme sua roupa e acessórios
+6.5 - Conforme sua bicicleta
+7 - Medir o que influencia mais da distância ou da velocidade
+no conforto do ciclista ao pedalar, conforme sua experiência
+
+*/
+
+/*
+ETAPAS NECESSÀRIAS NO CÓDIGO DO ARDUÍNO
+0.1  - Medir distância com sonar 1                        - OK
+0.11 - Medir distância com sonar 2                        - OK
+0.12 - Medir distância média                              - OK
+0.2  - Gravar no Cartão SD                                - OK
+0.21 - Bluetooth enviar dados para o celular              - OK
+0.3  - Adicionar "botão do pânico"                        - OK - Tem erros de compilação que foram corrigidos em 3.1
+0.31 - Buzzer ao apertar o botão                          - OK
+0.4  - Medir velocidade da bicicleta                      -
+0.5  - Receber dados do celular                           -
+0.51 - Receber dados GPS do celular                       -
+0.52 - Receber configuração pelo celular                  -
+0.5  - Controle de falsos positivos                       - Talvez o controle e configurações pelo celular
+0.51 - A bicicleta passa o carrou ou o contrário          - Talvez o controle e configurações pelo celular
+0.6  - Colocar o botão do pânico para ter mais funções    - Talvez o controle e configurações pelo celular
+0.61 - Colocar o buzzer para avisar sobre o funcionamento -
+0.8  - Medir a velocidade dos carros                      - Talvez deixar para software externo
+0.9  - Medir o comprimento dos carros                     - Talvez deixar para sofware externo
+0.91 - Diferenciar se carro, moto ou caminhão             - Talvez deixar para software externo
+1.0  - Lançar o protótipo
+*/
+
+/* BIBLIOTECAS INCLUÍDAS */
+#include <SD.h> // Biblioteca de leitura do cartão SD
+#include <NewPing.h> // Biblioteca de ???
+
+// DEFINIÇÕES
+// DOS PINOS
+//#define BLUETOOTH_TX_PIN 0 // Pino transmissão bluetooth
+//#define BLUETOOTH_RX_PIN 1 // Pino transmissão bluetooth
+#define BUZZER_PIN 3       // Pino do buzzer
+#define USER_BUTTON_PIN 4  // Pino do botão do pânico
+#define HALL_SENSOR_PIN 5  // Pino do sensor hall
+#define SONAR1_TRIG_PIN 6  // Pino do trigger do sonar 1
+#define SONAR1_ECHO_PIN 7  // Pino do echo do sonar 1
+#define SONAR2_TRIG_PIN 8  // Pino do trigger do sonar 2
+#define SONAR2_ECHO_PIN 9  // Pino do echo do sonar 2
+#define SDCARD_PIN 10
+// OUTRAS DEFINIÕES
+#define MAX_DISTANCE 50   // Definição da distância máxima de medição dos Sonares
+
+// CRIAÇÃO DOS SONARES
+NewPing sonar1(SONAR1_TRIG_PIN, SONAR1_ECHO_PIN, MAX_DISTANCE);
+NewPing sonar2(SONAR2_TRIG_PIN, SONAR2_ECHO_PIN, MAX_DISTANCE);
+
+// VARIÁVEIS GLOBAIS
+// Variaveis de configuração
+File myFile;                          // Objeto do arquivo para salvar os dados
+char nomeDoArquivo[] = "log.txt";     // Arquivo onde serão salvas os dados
+const int distanciaSensores = 1;      // Distancia que foi instalado os sensores
+const int frequenciaDeLeitura = 200;  // 200Hz
+const float raioDaRoda = 700;         // Raio da roda onde está o sensor hall
+//Variaveis de uso global
+unsigned long tempoAtual;             // Contagem do tempo
+unsigned long tempoInicial;           // Tempo inicial do Arduino
+int contaRevolucoes;                  // Conta quantas revolucoes em um periodo de tempo
+unsigned long tempoRevolucoes;
+float velocidadeAtual;
+
+// FUNÇÕES
+void inicializaSD();
+void imprimeSaida(unsigned long paraImpressao[], int totalVariaveis);
+boolean verificaUltrapassagem();
+float medeVelocidadeDoCiclista();
+
+// CONFIGURAÇÃO DO ARDUÍNO
+void setup(){
+
+  tempoInicial = millis();
+  tempoRevolucoes = millis();
+  velocidadeAtual = 0;
+
+  // Razão de transmissão dos dados Seriais
+  Serial.begin(9600);
+
+  // Configura as portas
+  pinMode(BUZZER_PIN, OUTPUT);     // Inicializa a porta do buzzer
+  pinMode(USER_BUTTON_PIN, INPUT); // Inicializa a porta do botão do pânico
+  pinMode(HALL_SENSOR_PIN, INPUT); // Inicializa a porta do sensor Hall
+  pinMode(SDCARD_PIN, OUTPUT);   // Inicicaliza a porta do SD CARD
+
+  inicializaSD(nomeDoArquivo);
+}
+
+// ROTINA DE LOOP
+void loop(){
+
+  int distanciaSonar1 = sonar1.ping_cm();
+  int distanciaSonar2 = sonar2.ping_cm();
+  boolean botaoPanico = !digitalRead(USER_BUTTON_PIN);
+  boolean revolucao = digitalRead(HALL_SENSOR_PIN);
+  if (revolucao) {
+    velocidadeAtual = medeVelocidadeDoCiclista();
+  }
+  tempoAtual = millis() - tempoInicial; // Acrescenta um ao tempo
+
+  // O tempo de ativação dos sonares serve para:
+  // - definir quem está ultrapassando quem
+  // - reduzir a quantidade de falsos positivos
+  // - definir velocidade do carro
+  // - definir comprimento do carro
+  unsigned long tempoAtivacaoSonar1 = 0;
+  unsigned long tempoAtivacaoSonar2 = 0;
+  if (distanciaSonar1 > 0) {
+    tempoAtivacaoSonar1 = tempoAtual;
+  }
+  if (distanciaSonar2 > 0) {
+    tempoAtivacaoSonar2 = tempoAtual;
+  }
+
+  // Verifica se o carro ultrapassou o ciclista ou o inverso
+  boolean dadoValido = true;
+
+  if (dadoValido || botaoPanico) {
+    if (botaoPanico) {
+      digitalWrite(BUZZER_PIN, HIGH);
+    } else {
+      digitalWrite(BUZZER_PIN, LOW);
+    }
+    const int totalVariaveis = 7;
+    unsigned long paraImpressao[totalVariaveis] = {
+                                                   botaoPanico,
+                                                   tempoAtual/1000,
+                                                   distanciaSonar1,
+                                                   distanciaSonar2,
+                                                   tempoAtivacaoSonar1/1000,
+                                                   tempoAtivacaoSonar2/1000,
+                                                   velocidadeAtual
+                                                   };
+
+    if (distanciaSonar1 > 0 || distanciaSonar2 > 0) {
+      imprimeSaida(paraImpressao, totalVariaveis);
+    }
+  }
+}
+
+// Verfica se a bicicleta ultrapassou o carro ou o oposto
+// Verifica erros de falsos positivos esporádicos
+boolean verificaUltrapassagem () {
+  // Sensores distanciados de 1m
+  // Um carro que está a 20m/s (72km/h)
+  // Passa pelos dois sensores em 1/20s
+  // Dez leituras nesse tempo, talvez seja suficiente - leituras a 1/200 s
+
+}
+
+float medeVelocidadeDoCiclista() {
+  float velocidade;
+  contaRevolucoes++;
+  Serial.println(contaRevolucoes);
+  if (millis() - tempoRevolucoes < 2000.0) {
+    if (contaRevolucoes > 20) {
+      tempoRevolucoes = millis();
+      contaRevolucoes = 0;
+      Serial.println((millis() - tempoRevolucoes)*contaRevolucoes*raioDaRoda*2*3.1415/60);
+      return (millis() - tempoRevolucoes)*contaRevolucoes*raioDaRoda*2*3.1415/60;
+    } else {
+      return velocidadeAtual;
+    }
+  } else {
+    return 0;
+  }
+}
+
+//FUNÇÃO IMPRIME TODAS AS SAÍDAS DO PROGRAMA NO SD E NO SERIAL
+void imprimeSaida(unsigned long paraImpressao[], int totalVariaveis) {
+  // Abre arquivos para impressão
+  //myFile = SD.open(nomeDoArquivo, FILE_WRITE);
+  for (int i = 0; i < totalVariaveis; i++) {
+    //myFile.print(paraImpressao[i]);
+    //myFile.print(",");
+    Serial.print(paraImpressao[i]);
+    if (i < totalVariaveis - 1) {
+      Serial.print(",");
+    }
+   }
+   // Adiciona nova linha
+   //myFile.println("");
+   Serial.println("");
+   // Fecha o arquivo para impressão
+   //myFile.close();
+}
+
+void inicializaSD(char arquivo[]) {
+  // Rotina de inicialização do cartão SD
+  Serial.println("Inicializando o cartao SD");
+  if (!SD.begin(10)){
+    Serial.println("A inicializacao falhou");
+    return;    // Se falha, sai da rotina de configuração
+  } else {
+    Serial.println("Cartao SD Inicializado");
+    if (SD.exists(arquivo)) {
+      Serial.print("O arquivo ");
+      Serial.print(arquivo);
+      Serial.print("existe");
+    } else {
+    Serial.print("O arquivo ");
+    Serial.print(arquivo);
+    Serial.print("não existe");
+    }
+  Serial.print("Criando arquivo ");
+  Serial.println(arquivo); // Não deveria criar apenas se inexistente?
+  myFile = SD.open(arquivo, FILE_WRITE);
+  myFile.close();
+  }
+}


adding a blink file

adding a blink file

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

--- blink.ino
+++ blink.ino
@@ -0,0 +1,26 @@
+/*
+  DigitalReadSerial with on-board Pushbutton
+  Reads a digital input on pin 5, prints the result to the serial monitor
+
+  This example code is in the public domain.
+*/
+
+// digital pin 5 has a pushbutton attached to it. Give it a name:
+int pushButton = PUSH2;
+
+// the setup routine runs once when you press reset:
+void setup() {
+  // initialize serial communication at 9600 bits per second:
+  Serial.begin(9600);
+  // make the on-board pushbutton's pin an input pullup:
+  pinMode(pushButton, INPUT_PULLUP);
+}
+
+// the loop routine runs over and over again forever:
+void loop() {
+  // read the input pin:
+  int buttonState = digitalRead(pushButton);
+  // print out the state of the button:
+  Serial.println(buttonState);
+  delay(100);        // delay in between reads for stability
+}


Serial Echo

Serial Echo

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

--- Arduino/SerialEcho/SerialEcho.ino
+++ Arduino/SerialEcho/SerialEcho.ino
@@ -0,0 +1,25 @@
+void setup() {
+  Serial.begin(115200);
+  pinMode(LED_BUILTIN, OUTPUT);
+}
+
+// the loop function runs over and over again forever
+void loop() {
+
+  //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
+  //delay(1000);
+}
+
+void serialEvent() {
+  while (Serial.available()) {
+    // get the new byte:
+    //char inChar = (char)Serial.read();
+    int v = Serial.read();
+    //v = v+1;
+    char vChar = (char) v;
+    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
+    Serial.println(vChar);
+  }
+
+}
+


Update mrs-airfoil-code.ino

Update mrs-airfoil-code.ino

error: pathspec 'Lab' did not match any file(s) known to git
error: pathspec '4' did not match any file(s) known to git
error: pathspec 'Shells/mrs-airfoil-code.ino' did not match any file(s) known to git


Kapitola: Počítanie čiar

Kapitola: Počítanie čiar

error: pathspec 'Programy/09_Počítanie' did not match any file(s) known to git
error: pathspec 'čiar.ino' did not match any file(s) known to git


v3.1.4 - example #25 added

v3.1.4 - example #25 added

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

--- examples/Scheduler_example25_SCHEDULER_CHAIN/Scheduler_example25_SCHEDULER_CHAIN.ino
+++ examples/Scheduler_example25_SCHEDULER_CHAIN/Scheduler_example25_SCHEDULER_CHAIN.ino
@@ -0,0 +1,127 @@
+/*
+    TaskScheduler Example #25
+
+    Create 10 random Tasks. Prints the entire chain.
+    Then executes chain once printing the remaining chain from currently active task
+    Deletes all tasks afterwards
+*/
+
+// #define _TASK_TIMECRITICAL      // Enable monitoring scheduling overruns
+#define _TASK_SLEEP_ON_IDLE_RUN // Enable 1 ms SLEEP_IDLE powerdowns between tasks if no callback methods were invoked during the pass
+// #define _TASK_STATUS_REQUEST    // Compile with support for StatusRequest functionality - triggering tasks on status change events in addition to time only
+#define _TASK_WDT_IDS           // Compile with support for wdt control points and task ids
+// #define _TASK_LTS_POINTER       // Compile with support for local task storage pointer
+// #define _TASK_PRIORITY          // Support for layered scheduling priority
+// #define _TASK_MICRO_RES         // Support for microsecond resolution
+// #define _TASK_STD_FUNCTION      // Support for std::function (ESP8266 and ESP32 ONLY)
+// #define _TASK_DEBUG             // Make all methods and variables public for debug purposes
+// #define _TASK_INLINE            // Make all methods "inline" - needed to support some multi-tab, multi-file implementations
+// #define _TASK_TIMEOUT           // Support for overall task timeout
+// #define _TASK_OO_CALLBACKS      // Support for dynamic callback method binding
+// #define _TASK_DEFINE_MILLIS     // Force forward declaration of millis() and micros() "C" style
+#define _TASK_EXPOSE_CHAIN      // Methods to access tasks in the task chain
+
+#include <TaskScheduler.h>
+#include <QueueArray.h>
+
+// Debug and Test options
+#define _DEBUG_
+//#define _TEST_
+
+#ifdef _DEBUG_
+#define _PP(a) Serial.print(a);
+#define _PL(a) Serial.println(a);
+#else
+#define _PP(a)
+#define _PL(a)
+#endif
+
+
+// Scheduler
+Scheduler ts;
+
+void taskCallback();
+void cleanUp();
+
+Task tManager(6000, TASK_ONCE, &cleanUp, &ts, false);
+/*
+  Scheduling defines:
+  TASK_MILLISECOND
+  TASK_SECOND
+  TASK_MINUTE
+  TASK_HOUR
+  TASK_IMMEDIATE
+  TASK_FOREVER
+  TASK_ONCE
+  TASK_NOTIMEOUT
+*/
+
+int noOfTasks = 10;
+QueueArray <Task*> toDelete;
+
+void setup() {
+  // put your setup code here, to run once:
+#if defined(_DEBUG_) || defined(_TEST_)
+  Serial.begin(115200);
+  delay(2000);
+  _PL("Scheduler Example: Expose Scheduler Task Chain"); _PL();
+#endif
+
+  _PL("Generating a random chain of tasks");
+  for (int i = 0; i < noOfTasks; i++) {
+    long p = random(100, 5001); // from 100 ms to 5 seconds
+    long j = random(1, 11); // from 1 to 10 iterations)
+    Task *t = new Task(p, j, &taskCallback, &ts, false);
+    _PP(F("Generated a new task:\t")); _PP(t->getId()); _PP(F("\tInt, Iter = \t"));
+    _PP(p); Serial.print(", "); _PL(j);
+    if ( random(1, 100) > 50 ) {
+      t->enable();
+    }
+    else {
+      t->enableDelayed();
+    }
+    toDelete.push(t);
+  }
+  _PL();
+  _PL("Printing the entire chain");
+  Task* f = ts.getFirstTask();
+  Task* l = ts.getLastTask();
+  while (f) {
+    _PP("Task #"); _PL(f->getId());
+    f = f->getNextTask();
+  }
+  _PL();
+  tManager.enableDelayed();
+}
+
+
+void loop() {
+  ts.execute();
+}
+
+
+void taskCallback() {
+  _PP(millis());
+  _PP(": taskCallback() of task #");
+  Task* t = ts.getCurrentTask();
+  t->disable();
+  _PL(t->getId());
+  Task* l = ts.getLastTask();
+  while (t) {
+    _PP("#"); _PP(t->getId());
+    if (t->getNextTask() != NULL) _PP("->");
+    t = t->getNextTask();
+  }
+  _PL(); _PL();
+}
+
+void cleanUp() {
+    _PL("Deleting tasks:");
+  do {
+    Task* t = toDelete.pop();
+    _PP("Deleting task #"); _PL(t->getId());
+    delete t;
+  } while (!toDelete.isEmpty());
+
+  for (;;) ;
+}


Added arduino sketch to repository.

Added arduino sketch to repository.

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

--- arduino/Robot_Arduino_Code/Robot_Arduino_Code.ino
+++ arduino/Robot_Arduino_Code/Robot_Arduino_Code.ino
@@ -0,0 +1,138 @@
+#include <Adafruit_NeoPixel.h>
+#include <Wire.h>
+#define PIN 6
+
+// Parameter 1 = number of pixels in strip
+// Parameter 2 = 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)
+Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
+
+//Based heavily off of 3574's LED Arduino code, modified and appended by 2635
+
+void setup()
+{
+  strip.begin();
+  strip.show();
+  Wire.being(4);
+  Wire.onReceive(receiveEvent);
+}
+
+int showPattern = -1;
+uint32_t colorRed = strip.Color(255,0,0);
+
+void loop()
+{
+  showPattern = 0;
+  switch(showPattern)
+  {
+   case 0: rainbowCycle(5); showPattern = -1; break;
+   case 1: colorWipe(colorRed, 10); showPattern = -1; break;
+   case 2: marchRedWhiteBlue(); showPattern = -1; break;
+  default:    solidColor(strip.Color(0, 0, 0));
+  strip.show(); showPattern = -1; break;
+  }
+
+}
+
+
+//Wipe a color LED by LED through the strip, then clear it. Wait is delay between LED setting.
+void colorWipe(uint32_t c, uint8_t wait) {
+  for(uint16_t i=0; i<strip.numPixels(); i++) {
+    strip.setPixelColor(i, c);
+    strip.show();
+    delay(wait);
+  }
+
+  for(uint16_t i=0; i<strip.numPixels(); i++)
+    {
+      strip.setPixelColor(i, strip.Color(0,0,0));
+      strip.show();
+      delay(wait);
+    }
+}
+
+
+void marchRedWhiteBlue()
+{
+  uint32_t colors[] = { strip.Color(255,0,0), strip.Color(0,0,255), strip.Color(155,155,155) };
+  // Turn everything black
+  solidColor(strip.Color(0, 0, 0));
+
+  int frame = 0;
+
+  while( frame < 50 ) {
+    for (int index = 0;index<strip.numPixels();index++)
+    {
+      //strip.setPixelColor((index  + (frame % 15)) % 60, colors[ ((index)/5 + frame) % 3 ]);
+      strip.setPixelColor((index + frame) % 60 , colors[ ((index)/5) % 3 ]);
+    }
+    strip.show();
+    delay(50);
+    frame++;
+  }
+
+}
+
+// Slightly different, this makes the rainbow equally distributed throughout
+void rainbowCycle(uint8_t wait) {
+  uint16_t i, j;
+
+  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
+    for(i=0; i< strip.numPixels(); i++) {
+      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
+    }
+    strip.show();
+    delay(wait);
+  }
+}
+
+
+
+//UTIL METHODS. Call them if you want. See if I care.
+
+void solidColor(uint32_t c){
+    for(uint16_t i=0; i<strip.numPixels(); i++) {
+      strip.setPixelColor(i, c);
+
+    }
+}
+
+void receiveEvent(int howMany)
+{
+  static uint8_t ct = 0;
+  int x = Wire.read();
+  showPattern = x;
+}
+
+// Input a value 0 to 255 to get a color value.
+// The colours are a transition r - g - b - back to r.
+uint32_t Wheel(byte WheelPos) {
+  if(WheelPos < 85) {
+   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
+  } else if(WheelPos < 170) {
+   WheelPos -= 85;
+   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
+  } else {
+   WheelPos -= 170;
+   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
+  }
+}
+
+// Run the length of the strip one light at a time
+void colorSwipe(uint32_t color, uint8_t wait) {
+  for(int i = 0; i <= strip.numPixels(); i++) {
+    // going out of bounds does not break things, so checks removed for readability
+    // clean up behind it
+    strip.setPixelColor(i-1, 0);
+    //if (i < strip.numPixels())
+    strip.setPixelColor(i, color);
+    strip.show();
+    delay(wait);
+  }
+}
+
+


Switch keyboard with resistor ladder

Switch keyboard with resistor ladder

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

--- Project_7/Project_7.ino
+++ Project_7/Project_7.ino
@@ -0,0 +1,25 @@
+int notes[] = {262, 294, 330, 349};
+
+void setup() {
+  Serial.begin(9600);
+}
+
+void loop() {
+  int keyVal = analogRead(A0);
+  Serial.println(keyVal);
+  if (keyVal == 1023) {
+    tone(8, notes[0]);
+  }
+  else if (keyVal >= 950 && keyVal <= 1010) {
+    tone(8, notes[1]);
+  }
+  else if (keyVal >= 505 && keyVal <= 515) {
+    tone(8, notes[2]);
+  }
+  else if (keyVal >= 5 && keyVal <= 10) {
+    tone(8, notes[3]);
+  }
+  else {
+    noTone(8);
+  }
+}


Sample sketch for signal edge-edge measurement.

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

--- input_capture_period.ino
+++ input_capture_period.ino
@@ -0,0 +1,116 @@
+/*
+ * Distributed under the 2-clause BSD licence (See LICENCE.TXT file at the
+ * repository root).
+ *
+ * Copyright (c) 2017 Tilo Nitzsche.  All rights reserved.
+ *
+ * https://github.com/tni/teensy-samples
+ */
+
+#include <WProgram.h>
+#include <DMAChannel.h>
+#include <array>
+
+// This code works with Kinetis K (Teensy 3.x)
+// Measure period between 2 rising edges of signal. (Or alternately, measure pulse width.)
+// Pin 21 is configured as output and connected to pin 3. It is used
+// to generate a test signal.
+
+const uint8_t out_pin = 21;
+const uint8_t capture_pin = 3;
+
+
+#define GPIO_BITBAND_ADDR(reg, bit) (((uint32_t)&(reg) - 0x40000000) * 32 + (bit) * 4 + 0x42000000)
+#define GPIO_BITBAND_PTR(reg, bit) ((volatile uint32_t *)GPIO_BITBAND_ADDR((reg), (bit)))
+#define OUT_PIN_BITBAND_REG GPIO_BITBAND_PTR(CORE_PIN21_PORTREG, CORE_PIN21_BIT)
+
+// The Arduino preprocessor is buggy and screws up template functions outside namespaces.
+namespace {
+template<size_t N> __attribute__((always_inline)) void generateNopsHelper() {
+    generateNopsHelper<N-1>();
+    asm volatile ("nop");
+}
+template<> __attribute__((always_inline)) void generateNopsHelper<0>() {}
+
+template<size_t N> __attribute__((always_inline)) FASTRUN void generateNops() {
+    generateNopsHelper<N>();
+}
+
+template<size_t high_time, size_t low_time>
+__attribute__((noinline)) FASTRUN void generateDoublePulse() {
+    // force 0 and 1 to be loaded in registers, so that we can get precise pulses
+    uint32_t v_low = 0;
+    uint32_t v_high = 1;
+    volatile uint32_t dummy = v_low; dummy = v_high;
+    asm volatile ("" ::: "memory");
+    (void) *OUT_PIN_BITBAND_REG; // load OUT_PIN_BITBAND_REG into register
+    noInterrupts();
+    *OUT_PIN_BITBAND_REG = v_high;
+    generateNops<high_time>();
+    *OUT_PIN_BITBAND_REG = v_low;
+    generateNops<low_time>();
+    *OUT_PIN_BITBAND_REG = v_high;
+    generateNops<high_time>();
+    *OUT_PIN_BITBAND_REG = v_low;
+    generateNops<low_time>();
+    interrupts();
+}
+
+} // namespace
+
+
+auto& serial = Serial;
+
+void setup() {
+    // setup FTM1 in free running mode, counting from 0 - 0xFFFF
+    FTM1_SC = 0;
+    FTM1_CNT = 0;
+    FTM1_MOD = 0xFFFF;
+    // pin 3 config to FTM mode; pin 3 is connected to FTM1 channel 0
+    CORE_PIN3_CONFIG = PORT_PCR_MUX(3);
+    // set FTM1 clock source to system clock; FTM_SC_PS(0): divide clock by 1
+    FTM1_SC = (FTM_SC_CLKS(1) | FTM_SC_PS(0));
+
+    // need to unprotect FTM1_COMBINE register
+    FTM1_MODE = FTM_MODE_WPDIS;
+    // set FTM1 CH0 to dual edge capture, paired channels
+    FTM1_COMBINE = FTM_COMBINE_DECAP0 | FTM_COMBINE_DECAPEN0;
+    FTM1_MODE = FTM_MODE_WPDIS | FTM_MODE_FTMEN;
+
+    // measure period between 2 rising edges
+    // channel 0, capture rising edge; FTM_CSC_MSA --> continous capture mode
+    FTM1_C0SC = FTM_CSC_ELSA | FTM_CSC_MSA;
+    // channel 1, capture rising edge; FTM_CSC_MSA --> continous capture mode
+    FTM1_C1SC = FTM_CSC_ELSA | FTM_CSC_MSA | FTM_CSC_MSA;
+
+    // to measure pulse width, use the following config for FTM1_C1SC:
+    // channel 1, capture falling edge and trigger DMA, FTM_CSC_MSA --> continous capture mode
+    //FTM1_C1SC = FTM_CSC_CHIE | FTM_CSC_DMA| FTM_CSC_ELSB | FTM_CSC_MSA;
+
+    pinMode(out_pin, OUTPUT);
+
+    serial.begin(115200);
+    delay(2000);
+}
+
+static uint32_t iteration_cnt = 0;
+
+void loop() {
+    if(iteration_cnt % 2 == 0) generateDoublePulse<20, 80>();
+    else generateDoublePulse<40, 160>();
+
+    // The two FTM value registers are synchronized. FTM1_C0V must be read before
+    // FTM1_C1V. The FTM1_C1V read will reflect the correct capture that happened
+    // immeditely after the FTM1_C0V capture.
+    // (FTM1_C0V, FTM1_C1V) are continously updated with the current captured edge
+    // pair by the FTM timer and reflect the most current measurement.
+    uint16_t first_edge_time = FTM1_C0V;
+    uint16_t second_edge_time = FTM1_C1V;
+
+    serial.printf("Iteration: %u\n", iteration_cnt);
+    serial.printf("first_edge_time: %u second_edge_time: %u\n", first_edge_time, second_edge_time);
+    serial.printf("Period: %i\n\n", uint16_t(second_edge_time - first_edge_time));
+
+    iteration_cnt++;
+    delay(1000);
+}


Create count.ino

Create count.ino

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


Just getting started.

Just getting started.

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/spoollord/MyOurWeather.git/'


Analog read example.

Analog read example.

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

--- Week4/AnalogRead/AnalogRead.ino
+++ Week4/AnalogRead/AnalogRead.ino
@@ -0,0 +1,25 @@
+
+const int potPin = A0;
+
+int value = 0;
+
+void setup()
+{
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  //int potValue = analogRead(potPin);
+
+  Serial.println(value);
+
+  value++;
+
+  if(value > 255) value = 0;
+
+//  Serial.println(potValue);
+
+  delay(100);
+}
+


Update pt_remote controlled car.ino

Update pt_remote controlled car.ino

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


Create robot.ino

Create robot.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/jzbass25/BasicParticleRobot.git/'


Comment changes

Comment changes

--- software/XTendPayloadTeensy/XTendPayloadTeensy.ino
+++ software/XTendPayloadTeensy/XTendPayloadTeensy.ino
@@ -1,6 +1,6 @@
 /*
- * SERIAL1: GPS and LOGGER
- * SERIAL2: RF IN/OUT
+ * Serial1: GPS and LOGGER
+ * Serial2: RF IN/OUT
  */
 #define GPSLEN 100 //max length of GPS output to be sent
 char pkt_buffer[200];
@@ -28,7 +28,7 @@
   pinMode(5,INPUT_PULLUP);
 }
 void loop(){
-  // Copy any completed sentence to 2nd buffer
+  // Copy any completed sentence to the buffer, set up for next sentence.
   if ( sentenceRdy ) {
     for ( int i = 0 ; i < GPSLEN ; i++ ) {
         sentenceBuf2[i] = sentenceBuf[i];
@@ -92,12 +92,9 @@
 }

 void sendData() {
-  //print out sentenceBuf, all of it - KN
+  //print out sentence, all of it - KN
   int i = 0;

-//  if ( sentenceBuf[0] == 0 || msgIn == "" ) {
-//    Serial.println("");
-//  }
   if ( sentenceRdy ) {
     while( sentenceBuf[i+1] != 0 ) {
         Serial2.write( sentenceBuf[i] );
@@ -105,7 +102,7 @@
         i++;
     }
     sentenceRdy = false;
-  } else { // Latest data not ready yet, use 2nd buffer
+  } else { // Buffer data is being updated. Use current sentence
     Serial1.print( "BUF" );
     while( sentenceBuf2[i+1] != 0 ) {
         Serial2.write( sentenceBuf[i] );
@@ -125,6 +122,6 @@
   help = 0;
 }
 void printAndSend(String whatToSend){ //sends message to both logger and rf module
-  Serial2.print(whatToSend);
-  Serial1.print(whatToSend);
+  Serial2.print( whatToSend ); // RF module
+  Serial1.print( whatToSend ); // Logger
 }


Removed Extra Println

Removed Extra Println

error: pathspec 'BitBangingMpu6050/Right' did not match any file(s) known to git
error: pathspec 'Hand' did not match any file(s) known to git
error: pathspec 'Arduino' did not match any file(s) known to git
error: pathspec 'Code.ino' did not match any file(s) known to git


fona test

fona test

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

--- FONAtest/FONAtest.ino
+++ FONAtest/FONAtest.ino
@@ -0,0 +1,889 @@
+/***************************************************
+  This is an example for our Adafruit FONA Cellular Module
+
+  Designed specifically to work with the Adafruit FONA
+  ----> http://www.adafruit.com/products/1946
+  ----> http://www.adafruit.com/products/1963
+  ----> http://www.adafruit.com/products/2468
+  ----> http://www.adafruit.com/products/2542
+
+  These cellular modules use TTL Serial to communicate, 2 pins are
+  required to interface
+  Adafruit invests time and resources providing this open source code,
+  please support Adafruit and open-source hardware by purchasing
+  products from Adafruit!
+
+  Written by Limor Fried/Ladyada for Adafruit Industries.
+  BSD license, all text above must be included in any redistribution
+ ****************************************************/
+
+#define		APN 		"internet.vodafone.net"
+
+/*
+THIS CODE IS STILL IN PROGRESS!
+
+Open up the serial console on the Arduino at 115200 baud to interact with FONA
+
+Note that if you need to set a GPRS APN, username, and password scroll down to
+the commented section below at the end of the setup() function.
+*/
+#include "Adafruit_FONA.h"
+
+#define FONA_RX 2
+#define FONA_TX 3
+#define FONA_RST 4
+
+// this is a large buffer for replies
+char replybuffer[255];
+
+// We default to using software serial. If you want to use hardware serial
+// (because softserial isnt supported) comment out the following three lines
+// and uncomment the HardwareSerial line
+#include <SoftwareSerial.h>
+SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
+SoftwareSerial *fonaSerial = &fonaSS;
+
+// Hardware serial is also possible!
+//  HardwareSerial *fonaSerial = &Serial1;
+
+// Use this for FONA 800 and 808s
+Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
+// Use this one for FONA 3G
+//Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST);
+
+uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
+
+uint8_t type;
+
+void setup() {
+  while (!Serial);
+
+  Serial.begin(115200);
+  Serial.println(F("FONA basic test"));
+  Serial.println(F("Initializing....(May take 3 seconds)"));
+
+  fonaSerial->begin(4800);
+  if (! fona.begin(*fonaSerial)) {
+    Serial.println(F("Couldn't find FONA"));
+    while (1);
+  }
+  type = fona.type();
+  Serial.println(F("FONA is OK"));
+  Serial.print(F("Found "));
+  switch (type) {
+    case FONA800L:
+      Serial.println(F("FONA 800L")); break;
+    case FONA800H:
+      Serial.println(F("FONA 800H")); break;
+    case FONA808_V1:
+      Serial.println(F("FONA 808 (v1)")); break;
+    case FONA808_V2:
+      Serial.println(F("FONA 808 (v2)")); break;
+    case FONA3G_A:
+      Serial.println(F("FONA 3G (American)")); break;
+    case FONA3G_E:
+      Serial.println(F("FONA 3G (European)")); break;
+    default:
+      Serial.println(F("???")); break;
+  }
+
+  // Print module IMEI number.
+  char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
+  uint8_t imeiLen = fona.getIMEI(imei);
+  if (imeiLen > 0) {
+    Serial.print("Module IMEI: "); Serial.println(imei);
+  }
+
+  // Optionally configure a GPRS APN, username, and password.
+  // You might need to do this to access your network's GPRS/data
+  // network.  Contact your provider for the exact APN, username,
+  // and password values.  Username and password are optional and
+  // can be removed, but APN is required.
+  //fona.setGPRSNetworkSettings(F("your APN"), F("your username"), F("your password"));
+  fona.setGPRSNetworkSettings(F(APN));
+
+  // Optionally configure HTTP gets to follow redirects over SSL.
+  // Default is not to follow SSL redirects, however if you uncomment
+  // the following line then redirects over SSL will be followed.
+  //fona.setHTTPSRedirect(true);
+
+  printMenu();
+}
+
+void printMenu(void) {
+  Serial.println(F("-------------------------------------"));
+  Serial.println(F("[?] Print this menu"));
+  Serial.println(F("[a] read the ADC 2.8V max (FONA800 & 808)"));
+  Serial.println(F("[b] read the Battery V and % charged"));
+  Serial.println(F("[C] read the SIM CCID"));
+  Serial.println(F("[U] Unlock SIM with PIN code"));
+  Serial.println(F("[i] read RSSI"));
+  Serial.println(F("[n] get Network status"));
+  Serial.println(F("[v] set audio Volume"));
+  Serial.println(F("[V] get Volume"));
+  Serial.println(F("[H] set Headphone audio (FONA800 & 808)"));
+  Serial.println(F("[e] set External audio (FONA800 & 808)"));
+  Serial.println(F("[T] play audio Tone"));
+  Serial.println(F("[P] PWM/Buzzer out (FONA800 & 808)"));
+
+  // FM (SIM800 only!)
+  Serial.println(F("[f] tune FM radio (FONA800)"));
+  Serial.println(F("[F] turn off FM (FONA800)"));
+  Serial.println(F("[m] set FM volume (FONA800)"));
+  Serial.println(F("[M] get FM volume (FONA800)"));
+  Serial.println(F("[q] get FM station signal level (FONA800)"));
+
+  // Phone
+  Serial.println(F("[c] make phone Call"));
+  Serial.println(F("[A] get call status"));
+  Serial.println(F("[h] Hang up phone"));
+  Serial.println(F("[p] Pick up phone"));
+
+  // SMS
+  Serial.println(F("[N] Number of SMSs"));
+  Serial.println(F("[r] Read SMS #"));
+  Serial.println(F("[R] Read All SMS"));
+  Serial.println(F("[d] Delete SMS #"));
+  Serial.println(F("[s] Send SMS"));
+  Serial.println(F("[u] Send USSD"));
+
+  // Time
+  Serial.println(F("[y] Enable network time sync (FONA 800 & 808)"));
+  Serial.println(F("[Y] Enable NTP time sync (GPRS FONA 800 & 808)"));
+  Serial.println(F("[t] Get network time"));
+
+  // GPRS
+  Serial.println(F("[G] Enable GPRS"));
+  Serial.println(F("[g] Disable GPRS"));
+  Serial.println(F("[l] Query GSMLOC (GPRS)"));
+  Serial.println(F("[w] Read webpage (GPRS)"));
+  Serial.println(F("[W] Post to website (GPRS)"));
+
+  // GPS
+  if ((type == FONA3G_A) || (type == FONA3G_E) || (type == FONA808_V1) || (type == FONA808_V2)) {
+    Serial.println(F("[O] Turn GPS on (FONA 808 & 3G)"));
+    Serial.println(F("[o] Turn GPS off (FONA 808 & 3G)"));
+    Serial.println(F("[L] Query GPS location (FONA 808 & 3G)"));
+    if (type == FONA808_V1) {
+      Serial.println(F("[x] GPS fix status (FONA808 v1 only)"));
+    }
+    Serial.println(F("[E] Raw NMEA out (FONA808)"));
+  }
+
+  Serial.println(F("[S] create Serial passthru tunnel"));
+  Serial.println(F("-------------------------------------"));
+  Serial.println(F(""));
+
+}
+void loop() {
+  Serial.print(F("FONA> "));
+  while (! Serial.available() ) {
+    if (fona.available()) {
+      Serial.write(fona.read());
+    }
+  }
+
+  char command = Serial.read();
+  Serial.println(command);
+
+
+  switch (command) {
+    case '?': {
+        printMenu();
+        break;
+      }
+
+    case 'a': {
+        // read the ADC
+        uint16_t adc;
+        if (! fona.getADCVoltage(&adc)) {
+          Serial.println(F("Failed to read ADC"));
+        } else {
+          Serial.print(F("ADC = ")); Serial.print(adc); Serial.println(F(" mV"));
+        }
+        break;
+      }
+
+    case 'b': {
+        // read the battery voltage and percentage
+        uint16_t vbat;
+        if (! fona.getBattVoltage(&vbat)) {
+          Serial.println(F("Failed to read Batt"));
+        } else {
+          Serial.print(F("VBat = ")); Serial.print(vbat); Serial.println(F(" mV"));
+        }
+
+
+        if (! fona.getBattPercent(&vbat)) {
+          Serial.println(F("Failed to read Batt"));
+        } else {
+          Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%"));
+        }
+
+        break;
+      }
+
+    case 'U': {
+        // Unlock the SIM with a PIN code
+        char PIN[5];
+        flushSerial();
+        Serial.println(F("Enter 4-digit PIN"));
+        readline(PIN, 3);
+        Serial.println(PIN);
+        Serial.print(F("Unlocking SIM card: "));
+        if (! fona.unlockSIM(PIN)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+
+    case 'C': {
+        // read the CCID
+        fona.getSIMCCID(replybuffer);  // make sure replybuffer is at least 21 bytes!
+        Serial.print(F("SIM CCID = ")); Serial.println(replybuffer);
+        break;
+      }
+
+    case 'i': {
+        // read the RSSI
+        uint8_t n = fona.getRSSI();
+        int8_t r;
+
+        Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": ");
+        if (n == 0) r = -115;
+        if (n == 1) r = -111;
+        if (n == 31) r = -52;
+        if ((n >= 2) && (n <= 30)) {
+          r = map(n, 2, 30, -110, -54);
+        }
+        Serial.print(r); Serial.println(F(" dBm"));
+
+        break;
+      }
+
+    case 'n': {
+        // read the network/cellular status
+        uint8_t n = fona.getNetworkStatus();
+        Serial.print(F("Network status "));
+        Serial.print(n);
+        Serial.print(F(": "));
+        if (n == 0) Serial.println(F("Not registered"));
+        if (n == 1) Serial.println(F("Registered (home)"));
+        if (n == 2) Serial.println(F("Not registered (searching)"));
+        if (n == 3) Serial.println(F("Denied"));
+        if (n == 4) Serial.println(F("Unknown"));
+        if (n == 5) Serial.println(F("Registered roaming"));
+        break;
+      }
+
+    /*** Audio ***/
+    case 'v': {
+        // set volume
+        flushSerial();
+        if ( (type == FONA3G_A) || (type == FONA3G_E) ) {
+          Serial.print(F("Set Vol [0-8] "));
+        } else {
+          Serial.print(F("Set Vol % [0-100] "));
+        }
+        uint8_t vol = readnumber();
+        Serial.println();
+        if (! fona.setVolume(vol)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+
+    case 'V': {
+        uint8_t v = fona.getVolume();
+        Serial.print(v);
+        if ( (type == FONA3G_A) || (type == FONA3G_E) ) {
+          Serial.println(" / 8");
+        } else {
+          Serial.println("%");
+        }
+        break;
+      }
+
+    case 'H': {
+        // Set Headphone output
+        if (! fona.setAudio(FONA_HEADSETAUDIO)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        fona.setMicVolume(FONA_HEADSETAUDIO, 15);
+        break;
+      }
+    case 'e': {
+        // Set External output
+        if (! fona.setAudio(FONA_EXTAUDIO)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+
+        fona.setMicVolume(FONA_EXTAUDIO, 10);
+        break;
+      }
+
+    case 'T': {
+        // play tone
+        flushSerial();
+        Serial.print(F("Play tone #"));
+        uint8_t kittone = readnumber();
+        Serial.println();
+        // play for 1 second (1000 ms)
+        if (! fona.playToolkitTone(kittone, 1000)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+
+    /*** FM Radio ***/
+
+    case 'f': {
+        // get freq
+        flushSerial();
+        Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): "));
+        uint16_t station = readnumber();
+        Serial.println();
+        // FM radio ON using headset
+        if (fona.FMradio(true, FONA_HEADSETAUDIO)) {
+          Serial.println(F("Opened"));
+        }
+        if (! fona.tuneFMradio(station)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("Tuned"));
+        }
+        break;
+      }
+    case 'F': {
+        // FM radio off
+        if (! fona.FMradio(false)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+    case 'm': {
+        // Set FM volume.
+        flushSerial();
+        Serial.print(F("Set FM Vol [0-6]:"));
+        uint8_t vol = readnumber();
+        Serial.println();
+        if (!fona.setFMVolume(vol)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+    case 'M': {
+        // Get FM volume.
+        uint8_t fmvol = fona.getFMVolume();
+        if (fmvol < 0) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.print(F("FM volume: "));
+          Serial.println(fmvol, DEC);
+        }
+        break;
+      }
+    case 'q': {
+        // Get FM station signal level (in decibels).
+        flushSerial();
+        Serial.print(F("FM Freq (eg 1011 == 101.1 MHz): "));
+        uint16_t station = readnumber();
+        Serial.println();
+        int8_t level = fona.getFMSignalLevel(station);
+        if (level < 0) {
+          Serial.println(F("Failed! Make sure FM radio is on (tuned to station)."));
+        } else {
+          Serial.print(F("Signal level (dB): "));
+          Serial.println(level, DEC);
+        }
+        break;
+      }
+
+    /*** PWM ***/
+
+    case 'P': {
+        // PWM Buzzer output @ 2KHz max
+        flushSerial();
+        Serial.print(F("PWM Freq, 0 = Off, (1-2000): "));
+        uint16_t freq = readnumber();
+        Serial.println();
+        if (! fona.setPWM(freq)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+
+    /*** Call ***/
+    case 'c': {
+        // call a phone!
+        char number[30];
+        flushSerial();
+        Serial.print(F("Call #"));
+        readline(number, 30);
+        Serial.println();
+        Serial.print(F("Calling ")); Serial.println(number);
+        if (!fona.callPhone(number)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("Sent!"));
+        }
+
+        break;
+      }
+    case 'A': {
+        // get call status
+        int8_t callstat = fona.getCallStatus();
+        switch (callstat) {
+          case 0: Serial.println(F("Ready")); break;
+          case 1: Serial.println(F("Could not get status")); break;
+          case 3: Serial.println(F("Ringing (incoming)")); break;
+          case 4: Serial.println(F("Ringing/in progress (outgoing)")); break;
+          default: Serial.println(F("Unknown")); break;
+        }
+        break;
+      }
+
+    case 'h': {
+        // hang up!
+        if (! fona.hangUp()) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+
+    case 'p': {
+        // pick up!
+        if (! fona.pickUp()) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("OK!"));
+        }
+        break;
+      }
+
+    /*** SMS ***/
+
+    case 'N': {
+        // read the number of SMS's!
+        int8_t smsnum = fona.getNumSMS();
+        if (smsnum < 0) {
+          Serial.println(F("Could not read # SMS"));
+        } else {
+          Serial.print(smsnum);
+          Serial.println(F(" SMS's on SIM card!"));
+        }
+        break;
+      }
+    case 'r': {
+        // read an SMS
+        flushSerial();
+        Serial.print(F("Read #"));
+        uint8_t smsn = readnumber();
+        Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);
+
+        // Retrieve SMS sender address/phone number.
+        if (! fona.getSMSSender(smsn, replybuffer, 250)) {
+          Serial.println("Failed!");
+          break;
+        }
+        Serial.print(F("FROM: ")); Serial.println(replybuffer);
+
+        // Retrieve SMS value.
+        uint16_t smslen;
+        if (! fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len!
+          Serial.println("Failed!");
+          break;
+        }
+        Serial.print(F("***** SMS #")); Serial.print(smsn);
+        Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));
+        Serial.println(replybuffer);
+        Serial.println(F("*****"));
+
+        break;
+      }
+    case 'R': {
+        // read all SMS
+        int8_t smsnum = fona.getNumSMS();
+        uint16_t smslen;
+        int8_t smsn;
+
+        if ( (type == FONA3G_A) || (type == FONA3G_E) ) {
+          smsn = 0; // zero indexed
+          smsnum--;
+        } else {
+          smsn = 1;  // 1 indexed
+        }
+
+        for ( ; smsn <= smsnum; smsn++) {
+          Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);
+          if (!fona.readSMS(smsn, replybuffer, 250, &smslen)) {  // pass in buffer and max len!
+            Serial.println(F("Failed!"));
+            break;
+          }
+          // if the length is zero, its a special case where the index number is higher
+          // so increase the max we'll look at!
+          if (smslen == 0) {
+            Serial.println(F("[empty slot]"));
+            smsnum++;
+            continue;
+          }
+
+          Serial.print(F("***** SMS #")); Serial.print(smsn);
+          Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));
+          Serial.println(replybuffer);
+          Serial.println(F("*****"));
+        }
+        break;
+      }
+
+    case 'd': {
+        // delete an SMS
+        flushSerial();
+        Serial.print(F("Delete #"));
+        uint8_t smsn = readnumber();
+
+        Serial.print(F("\n\rDeleting SMS #")); Serial.println(smsn);
+        if (fona.deleteSMS(smsn)) {
+          Serial.println(F("OK!"));
+        } else {
+          Serial.println(F("Couldn't delete"));
+        }
+        break;
+      }
+
+    case 's': {
+        // send an SMS!
+        char sendto[21], message[141];
+        flushSerial();
+        Serial.print(F("Send to #"));
+        readline(sendto, 20);
+        Serial.println(sendto);
+        Serial.print(F("Type out one-line message (140 char): "));
+        readline(message, 140);
+        Serial.println(message);
+        if (!fona.sendSMS(sendto, message)) {
+          Serial.println(F("Failed"));
+        } else {
+          Serial.println(F("Sent!"));
+        }
+
+        break;
+      }
+
+    case 'u': {
+      // send a USSD!
+      char message[141];
+      flushSerial();
+      Serial.print(F("Type out one-line message (140 char): "));
+      readline(message, 140);
+      Serial.println(message);
+
+      uint16_t ussdlen;
+      if (!fona.sendUSSD(message, replybuffer, 250, &ussdlen)) { // pass in buffer and max len!
+        Serial.println(F("Failed"));
+      } else {
+        Serial.println(F("Sent!"));
+        Serial.print(F("***** USSD Reply"));
+        Serial.print(" ("); Serial.print(ussdlen); Serial.println(F(") bytes *****"));
+        Serial.println(replybuffer);
+        Serial.println(F("*****"));
+      }
+    }
+
+    /*** Time ***/
+
+    case 'y': {
+        // enable network time sync
+        if (!fona.enableNetworkTimeSync(true))
+          Serial.println(F("Failed to enable"));
+        break;
+      }
+
+    case 'Y': {
+        // enable NTP time sync
+        if (!fona.enableNTPTimeSync(true, F("pool.ntp.org")))
+          Serial.println(F("Failed to enable"));
+        break;
+      }
+
+    case 't': {
+        // read the time
+        char buffer[23];
+
+        fona.getTime(buffer, 23);  // make sure replybuffer is at least 23 bytes!
+        Serial.print(F("Time = ")); Serial.println(buffer);
+        break;
+      }
+
+
+    /*********************************** GPS (SIM808 only) */
+
+    case 'o': {
+        // turn GPS off
+        if (!fona.enableGPS(false))
+          Serial.println(F("Failed to turn off"));
+        break;
+      }
+    case 'O': {
+        // turn GPS on
+        if (!fona.enableGPS(true))
+          Serial.println(F("Failed to turn on"));
+        break;
+      }
+    case 'x': {
+        int8_t stat;
+        // check GPS fix
+        stat = fona.GPSstatus();
+        if (stat < 0)
+          Serial.println(F("Failed to query"));
+        if (stat == 0) Serial.println(F("GPS off"));
+        if (stat == 1) Serial.println(F("No fix"));
+        if (stat == 2) Serial.println(F("2D fix"));
+        if (stat == 3) Serial.println(F("3D fix"));
+        break;
+      }
+
+    case 'L': {
+        // check for GPS location
+        char gpsdata[120];
+        fona.getGPS(0, gpsdata, 120);
+        if (type == FONA808_V1)
+          Serial.println(F("Reply in format: mode,longitude,latitude,altitude,utctime(yyyymmddHHMMSS),ttff,satellites,speed,course"));
+        else
+          Serial.println(F("Reply in format: mode,fixstatus,utctime(yyyymmddHHMMSS),latitude,longitude,altitude,speed,course,fixmode,reserved1,HDOP,PDOP,VDOP,reserved2,view_satellites,used_satellites,reserved3,C/N0max,HPA,VPA"));
+        Serial.println(gpsdata);
+
+        break;
+      }
+
+    case 'E': {
+        flushSerial();
+        if (type == FONA808_V1) {
+          Serial.print(F("GPS NMEA output sentences (0 = off, 34 = RMC+GGA, 255 = all)"));
+        } else {
+          Serial.print(F("On (1) or Off (0)? "));
+        }
+        uint8_t nmeaout = readnumber();
+
+        // turn on NMEA output
+        fona.enableGPSNMEA(nmeaout);
+
+        break;
+      }
+
+    /*********************************** GPRS */
+
+    case 'g': {
+        // turn GPRS off
+        if (!fona.enableGPRS(false))
+          Serial.println(F("Failed to turn off"));
+        break;
+      }
+    case 'G': {
+        // turn GPRS on
+        if (!fona.enableGPRS(true))
+          Serial.println(F("Failed to turn on"));
+        break;
+      }
+    case 'l': {
+        // check for GSMLOC (requires GPRS)
+        uint16_t returncode;
+
+        if (!fona.getGSMLoc(&returncode, replybuffer, 250))
+          Serial.println(F("Failed!"));
+        if (returncode == 0) {
+          Serial.println(replybuffer);
+        } else {
+          Serial.print(F("Fail code #")); Serial.println(returncode);
+        }
+
+        break;
+      }
+    case 'w': {
+        // read website URL
+        uint16_t statuscode;
+        int16_t length;
+        char url[80];
+
+        flushSerial();
+        Serial.println(F("NOTE: in beta! Use small webpages to read!"));
+        Serial.println(F("URL to read (e.g. www.adafruit.com/testwifi/index.html):"));
+        Serial.print(F("http://")); readline(url, 79);
+        Serial.println(url);
+
+        Serial.println(F("****"));
+        if (!fona.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) {
+          Serial.println("Failed!");
+          break;
+        }
+        while (length > 0) {
+          while (fona.available()) {
+            char c = fona.read();
+
+            // Serial.write is too slow, we'll write directly to Serial register!
+#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
+            loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
+            UDR0 = c;
+#else
+            Serial.write(c);
+#endif
+            length--;
+            if (! length) break;
+          }
+        }
+        Serial.println(F("\n****"));
+        fona.HTTP_GET_end();
+        break;
+      }
+
+    case 'W': {
+        // Post data to website
+        uint16_t statuscode;
+        int16_t length;
+        char url[80];
+        char data[80];
+
+        flushSerial();
+        Serial.println(F("NOTE: in beta! Use simple websites to post!"));
+        Serial.println(F("URL to post (e.g. httpbin.org/post):"));
+        Serial.print(F("http://")); readline(url, 79);
+        Serial.println(url);
+        Serial.println(F("Data to post (e.g. \"foo\" or \"{\"simple\":\"json\"}\"):"));
+        readline(data, 79);
+        Serial.println(data);
+
+        Serial.println(F("****"));
+        if (!fona.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
+          Serial.println("Failed!");
+          break;
+        }
+        while (length > 0) {
+          while (fona.available()) {
+            char c = fona.read();
+
+#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
+            loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
+            UDR0 = c;
+#else
+            Serial.write(c);
+#endif
+
+            length--;
+            if (! length) break;
+          }
+        }
+        Serial.println(F("\n****"));
+        fona.HTTP_POST_end();
+        break;
+      }
+    /*****************************************/
+
+    case 'S': {
+        Serial.println(F("Creating SERIAL TUBE"));
+        while (1) {
+          while (Serial.available()) {
+            delay(1);
+            fona.write(Serial.read());
+          }
+          if (fona.available()) {
+            Serial.write(fona.read());
+          }
+        }
+        break;
+      }
+
+    default: {
+        Serial.println(F("Unknown command"));
+        printMenu();
+        break;
+      }
+  }
+  // flush input
+  flushSerial();
+  while (fona.available()) {
+    Serial.write(fona.read());
+  }
+
+}
+
+void flushSerial() {
+  while (Serial.available())
+    Serial.read();
+}
+
+char readBlocking() {
+  while (!Serial.available());
+  return Serial.read();
+}
+uint16_t readnumber() {
+  uint16_t x = 0;
+  char c;
+  while (! isdigit(c = readBlocking())) {
+    //Serial.print(c);
+  }
+  Serial.print(c);
+  x = c - '0';
+  while (isdigit(c = readBlocking())) {
+    Serial.print(c);
+    x *= 10;
+    x += c - '0';
+  }
+  return x;
+}
+
+uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {
+  uint16_t buffidx = 0;
+  boolean timeoutvalid = true;
+  if (timeout == 0) timeoutvalid = false;
+
+  while (true) {
+    if (buffidx > maxbuff) {
+      //Serial.println(F("SPACE"));
+      break;
+    }
+
+    while (Serial.available()) {
+      char c =  Serial.read();
+
+      //Serial.print(c, HEX); Serial.print("#"); Serial.println(c);
+
+      if (c == '\r') continue;
+      if (c == 0xA) {
+        if (buffidx == 0)   // the first 0x0A is ignored
+          continue;
+
+        timeout = 0;         // the second 0x0A is the end of the line
+        timeoutvalid = true;
+        break;
+      }
+      buff[buffidx] = c;
+      buffidx++;
+    }
+
+    if (timeoutvalid && timeout == 0) {
+      //Serial.println(F("TIMEOUT"));
+      break;
+    }
+    delay(1);
+  }
+  buff[buffidx] = 0;  // null term
+  return buffidx;
+}


Code integration started

Code integration started

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

--- caregiver/caregiver.ino
+++ caregiver/caregiver.ino
@@ -0,0 +1,148 @@
+#include <Wire.h>
+#include <Adafruit_Sensor.h>
+#include <Adafruit_HMC5883_U.h>
+
+// any pins can be used
+#define SCK 10
+#define MOSI 9
+#define SS 8
+#define BLACK 0
+#define WHITE 1
+
+/* Assign a unique ID to this sensor at the same time */
+Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);
+
+Adafruit_SharpMem display(SCK, MOSI, SS);
+
+int newData = 1;
+
+char alz_name[] = "George";
+char alz_add_1[] = "1000 Olin Way";
+char alz_add_2[] = "Needham, MA";
+
+float pi = 3.14159265358979;
+float dx;
+float dy;
+int angle = 0;
+int care_dir_face = 50; // direction caregiver is facing, in degrees
+int care_alz_dir = 350; // NSEW direction caregiver needs to travel to reach patient
+int adj_care_alz_dir = 330; // angle from caregiver to patient, where 0 == direction caregiver is facing
+
+void drawAndRefresh() {
+  if (newData) {
+    newData = 0;
+
+    // draw text
+    display.clearDisplay();
+    display.setTextSize(1);
+    display.setTextColor(BLACK);
+    display.setCursor(2,2);
+    display.println(alz_name);
+    display.setCursor(2,12);
+    display.println("has wandered to");
+    display.setCursor(2,22);
+    display.println(alz_add_1);
+    display.setCursor(2,32);
+    display.println(alz_add_2);
+
+    // draw arrow
+    // TODO
+  }
+  display.refresh();
+}
+
+void setup(void)
+{
+  Serial.begin(9600);
+  Serial1.begin(9600);
+
+  /* Initialise the sensor */
+  if(!mag.begin())
+  {
+    /* There was a problem detecting the HMC5883 ... check your connections */
+    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
+    while(1);
+  }
+}
+
+float getHeading() {
+  /* Get a new sensor event */
+  sensors_event_t event;
+  mag.getEvent(&event);
+
+  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
+  Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print("  ");
+  Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print("  ");
+  Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print("  ");Serial.println("uT");
+
+  // Hold the module so that Z is pointing 'up' and you can measure the heading with x&y
+  // Calculate heading when the magnetometer is level, then correct for signs of axis.
+  float heading = atan2(event.magnetic.y, event.magnetic.x);
+
+  // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
+  // Find yours here: http://www.magnetic-declination.com/
+  // Mine is: -13* 2' W, which is ~13 Degrees, or (which we need) 0.22 radians
+  // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
+  float declinationAngle = 0.22;
+  heading += declinationAngle;
+
+  // Correct for when signs are reversed.
+  if(heading < 0)
+    heading += 2*PI;
+
+  // Check for wrap due to addition of declination.
+  if(heading > 2*PI)
+    heading -= 2*PI;
+
+  // Convert radians to degrees for readability.
+  float headingDegrees = heading * 180/M_PI;
+
+  return(headingDegrees);
+}
+
+void loop(void)
+{
+  // clear GPS serial buffer to get new data
+  while(Serial1.available()) {
+    Serial1.readln();
+  }
+  delay(10);
+
+  // get GPS location
+  char GPS[100];
+  while (Serial1.available()) {
+    char incoming[100];
+    Serial1.readBytesUntil('\n',incoming,100);
+    if(strncmp(incoming,"$GPRMC",6)==0) {
+      strcpy(GPS,incoming);
+      break;
+    }
+  }
+
+  // get magnetic heading
+  int heading = (int)getHeading();
+
+  // send location and heading to server
+  Serial.print("Heading,")
+  Serial.println(heading);
+  Serial.print("GPS,");
+  Serial.println(GPS);
+
+  // wait for the server to send back data, then read it
+  while(!Serial.available()) {}
+  char address[100];
+  char reldir[4];
+
+  // read address
+  int bytes = Serial.readBytesUntil('|',address,100);
+  address[bytes] = '\0'; // remove the trailing | character
+
+  // read direction
+  bytes = Serial.readBytes(reldir,3); // TODO: make sure we're sending 3 bytes
+
+  // update and refresh screen
+  // TODO
+
+  // wait 500ms and repeat
+  delay(500);
+}


dirty cketch

dirty cketch

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/bitsybits/bitsybits-core.git/'


Arduino Clock Code

Arduino Clock Code

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