Integrated bucket wheel driver code into Ros

/* BucketWheelActuationDriver
Authors: Derek Schumacher, Fatima Dominguez, Jaimiey Sears
Begins by assuming the bucket wheel is at its lowest point (100%)
The user can specify a percentage to actuate to (0-100%)
The circuit uses HSI power screws and Microstep Driver- M6128 :
DIP Switch: [111001] (1 = down, 0 = up)
[current: 1.25; Microstep = 1 (Full-step)]
Send an 's' or 'S' to e-stop screw movement
The wiring scheme for the HSI power screws:
Red (A+)
Red/White (A-)
Green (B+)
Green/white (B-)
PUL+ (pin 9)
DIR+ (pin 8)
PUL- and DIR- grounded
ENA+ connected to ground
ENA- connected to pin 10 (+5V when turning, otherwise 0V)
*/

#include <ros.h>
#include <std_msgs/Int16.h>

#define ERROR_OUT_OF_RANGE -1

int DIRECTION_PIN = 8;
int PULSE_PIN = 9;
int ENABLE = 10;

//31914 steps translates to roughly (under) 100% top to bottom
#define FULL_STEPS 31914
//int stepCount = 0;
int desiredPercent = 0;

//double onePercent = FULL_STEPS/100.0;
//int desiredStep = 0;
int DELAY = 10;

//double currentPercent = 100;
int currentSteps = FULL_STEPS;

//variable which disables all motor movement when set to TRUE.
boolean e_stop = false;

// This node handle represents this arduino
ros::NodeHandle bucketWheelDriverNode;

void newManualCommandCallback(const std_msgs::Int16& newManualCommand)
{
  int steps = newManualCommand.data;
  actuate(steps);
}
ros::Subscriber<std_msgs/Int16> commandSubscriber("BucketWheelCommand", &newManualCommandCallback);

void setup() {
  bucketWheelDriverNode.initNode();
  bucketWheelDriverNode.subscribe(commandSubscriber);

  pinMode(DIRECTION_PIN, OUTPUT);
  pinMode(PULSE_PIN, OUTPUT);
  pinMode(ENABLE, OUTPUT);
  //  digitalWrite(ENABLE, HIGH); //the motor should not make loud screeching
  Serial.begin(9600);
  Serial.println("Send position to go to (percent):");
  printPosition();
}//setup

void loop() {

  if (Serial.available())
  {
    int readValue = Serial.parseInt();
    moveToPercent(readValue);

  }
  e_stop = false;

  //Sync with ROS
  bucketWheelDriverNode.spinOnce(); // Check for subscriber update/update timestamp

}//loop

//moves the wheel the down the number of steps specified
//negative steps will be interpred as moving the wheel up.
void actuate(int steps) {
  //enable the controller
  digitalWrite(ENABLE, LOW);

  int dir = 0;
  //select which direction to go
  if (steps > 0) {
    digitalWrite(DIRECTION_PIN, LOW);
    dir = 1;
  }
  else {
    digitalWrite(DIRECTION_PIN, HIGH);
    dir = -1;
  }

  for(int i = 0; i < abs(steps); i++) {
    //leave if we say so
    interrupt();
    if (e_stop) break;

    //send pulse to controller
    delayMicroseconds(DELAY);
    digitalWrite(PULSE_PIN, HIGH);
    delayMicroseconds(DELAY);
    digitalWrite(PULSE_PIN, LOW);

    //update and print position as we move
    currentSteps += dir;
    if (i%500 == 0) printPosition();

    //wait for 100 ms
    delayMicroseconds(1000000);
  }
  //report final position
  printPosition();

  digitalWrite(ENABLE, HIGH);
}

//used to read any commands that have been recieved
void interrupt() {
  if (Serial.available()) {
    char command = Serial.read();
    switch (command) {
      case 's':
        e_stop = true;
        break;
      case 'S':
        e_stop = true;
        break;
    }
  }
}

//short subroutine to print the current actuation position of the bucketwheel
void printPosition() {
  Serial.print("Current Position:\t");
  Serial.print(toPercent(currentSteps), DEC);
  Serial.println("%");
}

//moves to the given percent from the current position
int moveToPercent(int percent){
  //error check
  if (percent > 100 || percent < 0) return ERROR_OUT_OF_RANGE;

  //calculate number of steps and move.
  int stepsToMove = int(-(toPercent(currentSteps) - percent)/100.0 * FULL_STEPS);
  Serial.print("Moving to ");
  Serial.print(percent, DEC);
  Serial.print("% from ");
  Serial.print(toPercent(currentSteps), DEC);
  Serial.println("%");
  actuate(stepsToMove);
}

//takes a position in steps and converts it to a percentage
double toPercent(int steps) {
  return steps*100.0/FULL_STEPS;
}

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


original commit

original commit

#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>

#include <SPI.h>
#include <OneWire.h>

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire  ds(23);  // on pin 10 (a 4.7K resistor is necessary)

int requestID = 1;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0x5c, 0x7d, 0x0c };

char packetBuffer[512];

PROGMEM prog_char *loopPacket1 = "{\"path\":\"/api/v1/thing/reporting\",\"requestID\":\"";
PROGMEM prog_char *loopPacket2 = "\",\"things\": {\"/device/climate/1wire/temperature\": {\"prototype\": {\"device\": {\"name\": \"DS1820\",\"maker\": \"Dallas Semiconductor\"},\"name\": \"true\",\"status\": [\"present\",\"absent\",\"recent\"],\"properties\": {\"temperature\": \"celsius\"}},\"instances\": [{\"name\": \"";
PROGMEM prog_char *loopPacket3 = "\",\"status\": \"present\",\"unit\": {\"serial\": \"";
PROGMEM prog_char *loopPacket4 = "\",\"udn\": \"1wire:";
PROGMEM prog_char *loopPacket5 = "\"},\"info\": {\"temperature\":";
PROGMEM prog_char *loopPacket6 = "}}]}}}";

EthernetUDP udp;
IPAddress ip(224,192,32,20);
unsigned int port = 22601;

void setup() {
  Serial.begin(9600);
  Serial.println("Starting...");
  while(!Serial) { }

  Serial.println("Waiting for DHCP address.");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Error: Failed to configure Ethernet using DHCP");
    while(1) {  }
  }

  udp.beginMulti(ip,port);

}

  byte data[12];
  byte addr[8];

void loop() {
    requestID = requestID + 1;

    char buffer[12];
  byte i;
  byte present = 0;
  byte type_s;
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS18S20");  // or old DS1820
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    default:
      Serial.println("Device is not a DS18x20 family device.");
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1);        // start conversion, with parasite power on at the end

  delay(1000);     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE);         // Read Scratchpad

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  fahrenheit = celsius * 1.8 + 32.0;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

    strcpy(packetBuffer,(char*)pgm_read_word(&loopPacket1) );
    strcat(packetBuffer, itoa( requestID, buffer, 10) );
    strcat(packetBuffer,(char*)pgm_read_word(&loopPacket2) );
    if (addr[7] == 0x10) strcat(packetBuffer, "ds1820");
    else if (addr[7] == 0x28) strcat(packetBuffer, "ds18b20");
    else if (addr[7] == 0x22) strcat(packetBuffer, "ds1822");
    else strcat(packetBuffer, "ds????");
    strcat(packetBuffer,(char*)pgm_read_word(&loopPacket3) );
    for (byte thisByte = 0; thisByte < 7; thisByte++) {
      sprintf(buffer, "%02x", addr[thisByte] );
      strcat(packetBuffer, buffer);
    }
    strcat(packetBuffer,(char*)pgm_read_word(&loopPacket4) );
    for (byte thisByte = 0; thisByte < 7; thisByte++) {
      sprintf(buffer, "%02x", addr[thisByte] );
      strcat(packetBuffer, buffer);
    }
    strcat(packetBuffer,(char*)pgm_read_word(&loopPacket5) );
    sprintf(packetBuffer + strlen(packetBuffer), "%4.2f", celsius);
    strcat(packetBuffer,(char*)pgm_read_word(&loopPacket6) );

    Serial.println(packetBuffer);
    udp.beginPacket(udp.remoteIP(), udp.remotePort());
    udp.write(packetBuffer);
    udp.endPacket();

  delay(2000);
}

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


Added methods

Added methods

Added methods for writing to LCD screen, reading from ADS1115

/* DATALOGGER FOR SENIOR CAPSTONE AND SCIENCE FAIR
 * By Luke Padgett, Plano Academy High School, 2016-17.
 *
 * This datalogger reads voltages automatically from a Vernier
 * conductivity probe, transforms those analog voltage readings
 * into digital signals via an ADS1115 ADC, sends those voltages to an
 * Arduino Uno, which transforms those voltage values into ppm (parts
 * per million) values, and finally sends those values to a datalogging
 * module to be recorded in .csv files, depending on the test cycle ID.
 * This datalogger also controls a peristaltic pump, though that
 * functionality may be removed if one desires after downloading these files.
 *
 * All code in these files is written by Luke Padgett unless specified otherwise
 * in the header(s) of a file, such as the Adafruit_ADS1015.h file.
 */

 /*
  * Pin specifications:
  * SS for LCD: 2
  * SS for SD Card Reader/Writer ("R/W"): 10
  * MOSI Pin: 11
  * MISO Pin: 12
  * Clock Pin: 13
  * SDA and SCL are used for the ADS1115.
  * Peristaltic Pump (PP) Pin: 5. Note: PWN is required for speed adjustment.
  */

//The Wire library allows communication with I2C / TWI devices.
#include <Wire.h> //V1.0

//The ADS1015 library facilitates reading from the ADS1115.
#include <Adafruit_ADS1015.h> //V1.1

//The LiquidCrystal library, by Juan Hernandez (juanh0238) facilitates usage of the
//LCD screen using a shift register via SPI.
#include <LiquidCrystal.h>

//The SPI library enables SPI interface bus.
#include <SPI.h>

//Set pins for MISO/MOSI/SS/PP
const int lcdSS = 2; //SS for LCD
LiquidCrystal lcd(2);
const int sdSS = 10; //SS for SD card R/W
const int MOSIpin = 11; //MOSI pin
const int MISOpin = 12; //MISO pin
const int clk = 13; //Clock pin
const int PP = 5; //Peristaltic pump pin

Adafruit_ADS1115 ads1115;
Adafruit_ADS1115 ads(0x48); //Sets base address

int16_t cVoltage; //16 bit variable reading from ADC's A0
String result; //String containing data from ADC

void setup() {
  //Set pin modes
  pinMode(lcdSS, OUTPUT);
  pinMode(sdSS, OUTPUT);
  pinMode(MOSIpin, OUTPUT);
  pinMode(MISOpin, OUTPUT);
  pinMode(clk, OUTPUT);
  pinMode(PP, OUTPUT);

  //Initialize communication processes
  Serial.begin(9600); //Sets baud rate
  lcd.begin(16,2); //Initializes LCD with # of rows and columns
  ads1115.begin(); //Initializes ADC
  lcd.print(""); //Print nothing to LCD to calibrate
}

void loop() {
  writeResult();
}

void LCDwrite(String s, String s2){
  lcd.setCursor(0, 0);
  lcd.print(s);
  lcd.setCursor(0,1);
  lcd.print(s2 + " mV");
}

void readADS() {
  cVoltage = ads1115.readADC_Differential_0_1();
  result = cVoltage;
}

void writeResult(){
  readADS();
  delay(500);
  LCDwrite("Hello", result);
}

/* DATALOGGER FOR SENIOR CAPSTONE AND SCIENCE FAIR
 * By Luke Padgett, Plano Academy High School, 2016-17.
 *
 * This datalogger reads voltages automatically from a Vernier
 * conductivity probe, transforms those analog voltage readings
 * into digital signals via an ADS1115 ADC, sends those voltages to an
 * Arduino Uno, which transforms those voltage values into ppm (parts
 * per million) values, and finally sends those values to a datalogging
 * module to be recorded in .csv files, depending on the test cycle ID.
 * This datalogger also controls a peristaltic pump, though that
 * functionality may be removed if one desires after downloading these files.
 *
 * All code in these files is written by Luke Padgett unless specified otherwise
 * in the header(s) of a file, such as the Adafruit_ADS1015.h file.
 */

 /*
  * Pin specifications:
  * SS for LCD: 2
  * SS for SD Card Reader/Writer ("R/W"): 10
  * MOSI Pin: 11
  * MISO Pin: 12
  * Clock Pin: 13
  * SDA and SCL are used for the ADS1115.
  * Peristaltic Pump (PP) Pin: 5. Note: PWN is required for speed adjustment.
  */

//The Wire library allows communication with I2C / TWI devices.
#include <Wire.h>

//The ADS1015 library facilitates reading from the ADS1115.
#include <Adafruit_ADS1015.h>

//The LiquidCrystal library (by Juan Hernandez, aka juanh0238) facilitates usage of the
//LCD screen using a shift register via SPI.
#include <LiquidCrystal.h>

//The SPI library enables SPI interface bus.
#include <SPI.h>

//Set pins for MISO/MOSI/SS/PP
const int lcdSS = 2; //SS for LCD
const int sdSS = 10; //SS for SD card R/W
const int MOSIpin = 11; //MOSI pin
const int MISOpin = 12; //MISO pin
const int clk = 13; //Clock pin
const int PP = 5; //Peristaltic pump pin

float cVoltage = 0.0; //Conductivity meter voltage

LiquidCrystal lcd(2);

void setup() {
  //Set pin modes
  pinMode(lcdSS, OUTPUT);
  pinMode(sdSS, OUTPUT);
  pinMode(MOSIpin, OUTPUT);
  pinMode(MISOpin, OUTPUT);
  pinMode(clk, OUTPUT);
  pinMode(PP, OUTPUT);

  //Initialize communication processes
  Serial.begin(9600); //Sets baud rate
  lcd.begin(16,2); //Initializes LCD with # of rows and columns
//  ads.begin(); //Initializes ADC
  lcd.print("Hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  lcd.print("Test");
}


Add LedStrip sample

Add LedStrip sample

#include <Homie.h>

const unsigned char NUMBER_OF_LED = 4;
const unsigned char LED_PINS[NUMBER_OF_LED] = { 16, 5, 4, 0 };

bool stripHandler(String, String); // forward declaration (needed for Arduino <= 1.6.8)
HomieNode stripNode("ledstrip", "ledstrip", stripHandler, true); // last true: subscribe to all properties

bool stripHandler(String property, String value) {
  for (int i = 0; i < property.length(); i++) {
    if (!isDigit(property.charAt(i))) {
      return false;
    }
  }

  int ledIndex = property.toInt();
  if (ledIndex < 0 || ledIndex > NUMBER_OF_LED - 1) {
    return false;
  }

  if (value == "true") {
    digitalWrite(LED_PINS[ledIndex], HIGH);
    Homie.setNodeProperty(stripNode, String(ledIndex), "true"); // Update the state of the led
    Serial.print("Led ");
    Serial.print(ledIndex);
    Serial.println(" is on");
  } else if (value == "false") {
    digitalWrite(LED_PINS[ledIndex], LOW);
    Homie.setNodeProperty(stripNode, String(ledIndex), "false");
    Serial.print("Led ");
    Serial.print(ledIndex);
    Serial.println(" is off");
  } else {
    return false;
  }

  return true;
}

void setup() {
  for (int i = 0; i < NUMBER_OF_LED; i++) {
    pinMode(LED_PINS[i], INPUT);
    digitalWrite(LED_PINS[i], LOW);
  }

  Homie.setFirmware("awesome-ledstrip", "1.0.0");
  Homie.registerNode(stripNode);
  Homie.setup();
}

void loop() {
  Homie.loop();
}

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


Changed the name. Slidebright.ino to SlideBright.ino, because of Arduino IDE

/*
** SlideBright - Firmware for the overengineered Hexbright flashlight.
**               Hexbright: http://hexbright.com/
**                                ~ Tobias Jäger <Tobias.Jaeger@slidetex.de>
**
**
** Based on darcbright by Robert Quattlebaum <darco@deepdarc.com>
**
** List of Modes:
**  * 3-brightnesse-level mode (43,175,500)
**  * momentary mode
**  * strobe mode
**  * ajust-brightness-by-roll mode
*/

/*
Accelorometer axies:

(x,y,z)

If the flashlight is facing straight up:
  (0, 21, 0)

If the flashlight is facing straight down:
  (0, -21, 0)

If the flashlight is battery-up:
  (0, 0, -21)

If the flashlight is battery-down:
  (0, 0, 21)

If the flashlight is logo-up:
  (-21, 0, 0)

If the flashlight is logo-down:
  (21, 0, 0)

*/

#include <math.h>
#include <Wire.h>
#include <EEPROM.h>
#include "pt.h"
#include <avr/wdt.h>

// Settings
#define VOLTAGE_NOMINAL               3330
#define VOLTAGE_LOW                   3100
#define OVERTEMP_SHUTDOWN_C           60
#define OVERTEMP_THROTTLE_C           50
#define OVERTEMP_SHUTDOWN             (OVERTEMP_SHUTDOWN_C*10+500)
#define OVERTEMP_THROTTLE             (OVERTEMP_THROTTLE_C*10+500)
#define BUTTON_BRIGHTNESS_THRESHOLD   1000 // time in ms, after which a button press turns off
#define BUTTON_DEBOUNCE               20
#define POWER_ON_BUTTON_THRESHOLD     150 // Period of time button initially needs to be held to keep the light on.

#define BRT_MIN_LUMEN          4
#define BRT_MED_LUMEN          255                        // 175 lumens
#define BRT_LOW_LUMEN          (BRT_MED_LUMEN/4)            // 43 lumens
#define BRT_MAX_LUMEN          (BRT_MED_LUMEN+(3*255))    // 500 lumens

// Constants
#define ACC_ADDRESS             0x4C
#define ACC_REG_XOUT            0
#define ACC_REG_YOUT            1
#define ACC_REG_ZOUT            2
#define ACC_REG_TILT            3
#define ACC_REG_INTS            6
#define ACC_REG_MODE            7

// Pin assignments
#define DPIN_RLED_SW            2
#define DPIN_GLED               5
#define DPIN_PWR                8
#define DPIN_DRV_MODE           9
#define DPIN_DRV_EN             10
#define DPIN_ACC_INT            3
#define APIN_TEMP               0
#define APIN_CHARGE             3

// Interrupts
#define INT_SW                  0
#define INT_ACC                 1

// State
byte light_mode;
unsigned short overtemp_max;
unsigned short amount_current;
unsigned short amount_begin;
unsigned short amount_end;
unsigned short amount_fade_duration;
unsigned long amount_fade_start;
byte amount_flash,amount_off;

// Protothread States
struct pt fade_control_pt;
struct pt power_pt;
struct pt button_led_pt;

// Mode Protothread States
struct pt light_pt;
struct pt light_momentary_pt;
struct pt light_blinky_pt;
struct pt light_knob_pt;

// Variables updated every loop
bool button_is_pressed;
unsigned long button_pressed_time;
unsigned long button_released_time;
unsigned long button_pressed_duration;
unsigned long button_released_duration;
short vcc_current;
short vcc_filter_table[3];
short vcc_filtered;
short temp_filter_table[3];
short temp_filtered;
short temp_current;
enum {
    BATT_DISCHARGING,
    BATT_CHARGING,
    BATT_CHARGED,
} batt_state;
unsigned long time_current;
float angle_pitch;
float angle_roll;

#define PT_WAIT_FOR_PERIOD(pt,x) \
    lastTime =  time_current; \
    PT_WAIT_UNTIL(pt, (time_current-lastTime) > (x));

bool orientation_enabled;

void
enable_orientation(void) {
  pinMode(DPIN_ACC_INT,  INPUT);
  digitalWrite(DPIN_ACC_INT,  HIGH);

  // Configure accelerometer
  static const byte config[] = {
    ACC_REG_INTS,  // First register (see next line)
    0xE4,  // Interrupts: shakes, taps
    0x00,  // Mode: not enabled yet
    0x00,  // Sample rate: 120 Hz
    0x0F,  // Tap threshold
    0x10   // Tap debounce samples
  };
  Wire.beginTransmission(ACC_ADDRESS);
  Wire.write(config, sizeof(config));
  Wire.endTransmission();

  // Enable accelerometer
  static const byte enable[] = {ACC_REG_MODE, 0x01};  // Mode: active!
  Wire.beginTransmission(ACC_ADDRESS);
  Wire.write(enable, sizeof(enable));
  Wire.endTransmission();

  orientation_enabled = 1;
}

void
update_loop_variables(void) {
  static char i;

  // Time stamp for this loop cycle.
  time_current = millis();

  // Grab the voltage and the temperature.
  vcc_filter_table[i] = vcc_current = readVcc();
  temp_filter_table[i] = analogRead(APIN_TEMP);

  temp_current = temp_filter_table[i]*(long)vcc_current/1024;

  vcc_filtered = median_short(vcc_filter_table[0],vcc_filter_table[1],vcc_filter_table[2]);

  temp_filtered *= 7;
  temp_filtered += median_short(temp_filter_table[0],temp_filter_table[1],temp_filter_table[2])*(long)vcc_filtered/1024;
  temp_filtered /= 8;

  if(++i==3)
    i=0;

  // Read out the state of but button.
  {
    bool prev_value = digitalRead(DPIN_RLED_SW);
    pinMode(DPIN_RLED_SW,  INPUT);
    digitalWrite(DPIN_RLED_SW, 0);
    button_is_pressed = digitalRead(DPIN_RLED_SW);
    pinMode(DPIN_RLED_SW,  OUTPUT);
    digitalWrite(DPIN_RLED_SW, prev_value);
  }

  if(button_is_pressed) {
    button_released_time = time_current;
    button_pressed_duration = time_current - button_pressed_time;
  } else {
    button_pressed_time = time_current;
    button_released_duration = time_current - button_released_time;
    button_pressed_duration = 0;
  }

  short chargeState = analogRead(APIN_CHARGE);

  if (chargeState < 128) {  // Low - charging
    batt_state = BATT_CHARGING;
  } else if (chargeState > 768) {  // High - fully charged.
    batt_state = BATT_CHARGED;
  } else {  // Hi-Z - Not charging, not pulged in.
    // But if the voltage is over 3.4 volts, then we know we are plugged in.
    if(vcc_current>3400)
      batt_state = BATT_CHARGING;
    else
      batt_state = BATT_DISCHARGING;
  }

  if(orientation_enabled) {
    char acc[3];
    readAccelFiltered(acc);
    angle_roll = atan2(acc[0],acc[2]);
    angle_pitch = atan2(acc[1],sqrt(acc[0]*acc[0]+acc[2]*acc[2]));
  }

  // Check if the accelerometer wants to interrupt
//  byte tapped = 0, shaked = 0;
//  if (!digitalRead(DPIN_ACC_INT)) {
//    Wire.beginTransmission(ACC_ADDRESS);
//    Wire.write(ACC_REG_TILT);
//    Wire.endTransmission(false);       // End, but do not stop!
//    Wire.requestFrom(ACC_ADDRESS, 1);  // This one stops.
//    byte tilt = Wire.read();
//
//    if (time-lastAccTime > 500) {
//      lastAccTime = time;
//
//      tapped = !!(tilt & 0x20);
//      shaked = !!(tilt & 0x80);
//
//      if (tapped) Serial.println("Tap!");
//      if (shaked) Serial.println("Shake!");
//    }
//  }
}

short
readVcc(void) {
  short result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  noInterrupts();
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  interrupts();
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

void readAccel(char *acc)
{
  while (1)
  {
    Wire.beginTransmission(ACC_ADDRESS);
    Wire.write(ACC_REG_XOUT);
    Wire.endTransmission(false);       // End, but do not stop!
    Wire.requestFrom(ACC_ADDRESS, 3);  // This one stops.

    for (int i = 0; i < 3; i++)
    {
      if (!Wire.available())
        continue;
      acc[i] = Wire.read();
      if (acc[i] & 0x40)  // Indicates failed read; redo!
        continue;
      if (acc[i] & 0x20)  // Sign-extend
        acc[i] |= 0xC0;
    }
    break;
  }
}

void readAccelFiltered(char *acc_filtered) {
  static char acc[3][3];
  static char i;
  readAccel(acc[i++]);
  if(i==3)
    i=0;
  acc_filtered[0] = median_char(acc[0][0],acc[1][0],acc[2][0]);
  acc_filtered[1] = median_char(acc[0][1],acc[1][1],acc[2][1]);
  acc_filtered[2] = median_char(acc[0][2],acc[1][2],acc[2][2]);
}

/* Returns the median value of the given three parameters */
char median_char(char a, char b, char c) {
    if(a<c) {
        if(b<a) {
            return a;
        } else if(c<b) {
            return c;
        }
    } else {
        if(a<b) {
            return a;
        } else if(b<c) {
            return c;
        }
    }
    return b;
}
short median_short(short a, short b, short c) {
    if(a<c) {
        if(b<a) {
            return a;
        } else if(c<b) {
            return c;
        }
    } else {
        if(a<b) {
            return a;
        } else if(b<c) {
            return c;
        }
    }
    return b;
}

void
retrieve_settings(void) {
  byte data[4];
  data[0] = EEPROM.read(0);
  data[1] = EEPROM.read(1);
  data[2] = EEPROM.read(2);
  data[3] = EEPROM.read(3);
  if(data[0] == (byte)~(data[1]^data[2]^data[3] + sizeof(data))) {
    light_mode = data[1];
    if(light_mode) {
      set_amount(data[2]+((unsigned short)data[3]<<8));
    }
    Serial.println("Settings retrieved");
  }
}

void
save_settings(void) {
  byte data[4];
  data[1] = light_mode;
  data[2] = (byte)amount_current;
  data[3] = (amount_current>>8);
  data[0] = ~(data[1]^data[2]^data[3] + sizeof(data));
  EEPROM.write(0,data[0]);
  EEPROM.write(1,data[1]);
  EEPROM.write(2,data[2]);
  EEPROM.write(3,data[3]);
}

void set_brightness(unsigned short b) {
  noInterrupts();
  if(b<=255) {
    digitalWrite(DPIN_DRV_MODE, LOW);
    analogWrite(DPIN_DRV_EN, b);
  } else if(b<=BRT_MAX_LUMEN) {
    analogWrite(DPIN_DRV_MODE, ((long)b-BRT_MED_LUMEN)*255/((long)BRT_MAX_LUMEN-BRT_MED_LUMEN));
    digitalWrite(DPIN_DRV_EN, HIGH);
  } else {
    digitalWrite(DPIN_DRV_EN, HIGH);
    digitalWrite(DPIN_DRV_MODE, HIGH);
  }
  interrupts();
}

void
set_amount(unsigned short amount) {
  amount_current = amount_begin = amount_end = amount;
  amount_fade_duration = 0;
  amount_off = 0;

  set_brightness(amount_current);
  pinMode(DPIN_PWR, OUTPUT);
  if(time_current<POWER_ON_BUTTON_THRESHOLD || amount_current==0)
    digitalWrite(DPIN_PWR, LOW);
  else
    digitalWrite(DPIN_PWR, HIGH);
}

void
fade_to_amount(unsigned short amount, unsigned short fade_duration) {
  amount_begin = amount_current;
  amount_end = amount;
  amount_fade_duration = fade_duration;
  amount_fade_start = millis();
  amount_off = 0;
}

PT_THREAD(fade_control_pt_func(struct pt *pt))
{
  static long fade_time;

  PT_BEGIN(pt);

  do {
    PT_YIELD(pt);

    if(amount_flash) {
      analogWrite(DPIN_DRV_EN, 0);
      fade_time =  time_current;
      PT_WAIT_UNTIL(pt, (time_current-fade_time) > (100));
    }

    amount_flash = 0;

    fade_time = time_current - amount_fade_start;

    if(fade_time >= amount_fade_duration) {
      if(amount_current != amount_end) {
        amount_current = amount_end;
      }
    } else {
      amount_current = (((long)amount_end - (long)amount_begin)*fade_time)/amount_fade_duration + amount_begin;
    }

    pinMode(DPIN_PWR, OUTPUT);
    if(time_current<POWER_ON_BUTTON_THRESHOLD || amount_current==0)
      digitalWrite(DPIN_PWR, LOW);
    else
      digitalWrite(DPIN_PWR, HIGH);

    if(amount_current>overtemp_max) {
      amount_current = overtemp_max;
    }

    set_brightness(amount_off?0:amount_current);
  } while(1);

  PT_END(pt);
}

PT_THREAD(button_led_pt_func(struct pt *pt))
{
  PT_BEGIN(pt);

  do {
    switch(batt_state) {
    case BATT_CHARGING:
      {
        const unsigned long pulseTime = time_current;
        // Smoothly pulse the green LED over a two-second interval,
        // as if it were "breathing". This is the charging indication.
        byte pulse = ((pulseTime>>2)&0xFF);
        pulse = ((pulse * pulse) >> 8);
        pulse = ((pulseTime>>2)&0x0100)?0xFF-pulse:pulse;
        analogWrite(DPIN_GLED, pulse);
      }
      if(overtemp_max<BRT_MAX_LUMEN) {
        digitalWrite(DPIN_RLED_SW, (time_current&0x03FF)>0x01FF?LOW:HIGH);
      } else {
        digitalWrite(DPIN_RLED_SW, LOW);
      }
      break;
    case BATT_CHARGED:
      // Solid green LED.
      digitalWrite(DPIN_GLED, HIGH);
      if(overtemp_max<BRT_MAX_LUMEN) {
        digitalWrite(DPIN_RLED_SW, (time_current&0x03FF)>0x01FF?LOW:HIGH);
      } else {
        digitalWrite(DPIN_RLED_SW, LOW);
      }
      break;
    case BATT_DISCHARGING:
      // Blink the indicator LED now and then.
      if(overtemp_max<BRT_MAX_LUMEN) {
        digitalWrite(DPIN_RLED_SW, (time_current&0x03FF)>50?LOW:HIGH);
        digitalWrite(DPIN_GLED, LOW);
      } else {
        digitalWrite(DPIN_GLED, (time_current&0x03FF)>10?LOW:HIGH);
        digitalWrite(DPIN_RLED_SW, LOW);
      }
      break;
    }
    PT_YIELD(pt);
  } while(1);

  PT_END(pt);
}

PT_THREAD(power_pt_func(struct pt *pt))
{
  static unsigned short count;
  count++;
  PT_BEGIN(pt);

  overtemp_max = BRT_MAX_LUMEN;
  do {
    // Check the temperature sensor
    {
      static bool low_power_condition = false;
      static uint8_t anti_flicker = 255;

      if(temp_filtered > OVERTEMP_SHUTDOWN) {
        if(amount_current)
          Serial.println("Overheat shutdown!");
        set_amount(0);
        digitalWrite(DPIN_DRV_MODE, LOW);
        digitalWrite(DPIN_DRV_EN, LOW);
        digitalWrite(DPIN_PWR, LOW);
      }

      if(low_power_condition || (vcc_current<VOLTAGE_LOW)) {
        if(!low_power_condition) {
          overtemp_max = amount_current;
        }
        low_power_condition = true;
        if((vcc_filtered < VOLTAGE_LOW) && (overtemp_max > BRT_MIN_LUMEN)) {
          digitalWrite(DPIN_DRV_EN, LOW);
          digitalWrite(DPIN_DRV_MODE, LOW);
          analogWrite(DPIN_DRV_EN,BRT_MIN_LUMEN);
          overtemp_max = overtemp_max/2 + BRT_MIN_LUMEN;
          anti_flicker = 0;
        }
      }

      if(anti_flicker == 255) {
        if((vcc_filtered > VOLTAGE_NOMINAL+50) && (overtemp_max != BRT_MAX_LUMEN))
          overtemp_max++;
          anti_flicker -= 10;
      } else {
        anti_flicker++;
      }

      if(temp_filtered > OVERTEMP_THROTTLE) {
        short new_max = (256-((temp_filtered-OVERTEMP_THROTTLE)*2)<<2)-1;
        if((overtemp_max>BRT_MIN_LUMEN) && (new_max<(signed)overtemp_max)) {
          overtemp_max--;
          anti_flicker = 0;
        }
      }

      static unsigned long lastStatTime;
      if(time_current-lastStatTime > 1000) {
        while(time_current-lastStatTime > 1000)
          lastStatTime += 1000;

        Serial.print("stat: ");
        Serial.print(time_current);

        switch(batt_state) {
        case BATT_CHARGING:
          Serial.print(" [CHARGING]");
          break;
        case BATT_CHARGED:
          Serial.print(" [CHARGED]");
          break;
        case BATT_DISCHARGING:
          Serial.print(" [BATTERY]");
          break;
        }

        Serial.print(" lHz=");
        Serial.print(count);
        count = 0;

        Serial.print(" duty=");
        Serial.print(amount_current);

        Serial.print(" Vcc=");
        Serial.print(vcc_filtered);
        Serial.print("mv");

        Serial.print(" Temp=");
        Serial.print((temp_filtered-500)/10.0f);
        Serial.print("C");

        if(orientation_enabled) {
          Serial.print(" roll=");
          Serial.print(angle_roll);

          Serial.print(" pitch=");
          Serial.print(angle_pitch);
        }

        if(overtemp_max<BRT_MAX_LUMEN) {
          Serial.print(" THRTTL=");
          Serial.print(overtemp_max);
        }
        Serial.println("");
        }
    }

    PT_YIELD(pt);
  } while(1);

  PT_END(pt);
}

PT_THREAD(light_momentary_pt_func(struct pt *pt))
{
  // If more than two minutes go by without the user
  // pressing a button, then go ahead and shut down.
  if(button_released_duration > 120000) {
    pinMode(DPIN_PWR, OUTPUT);
    digitalWrite(DPIN_PWR, LOW);
  }

  PT_BEGIN(pt);

  do {
    pinMode(DPIN_PWR, OUTPUT);
    digitalWrite(DPIN_PWR, HIGH);
    amount_off = 0;

    PT_WAIT_UNTIL(pt, !button_is_pressed);

    amount_off = 1;

    PT_WAIT_UNTIL(pt, button_is_pressed);
  } while(amount_current);

  PT_END(pt);
}

PT_THREAD(light_blinky_pt_func(struct pt *pt))
{
  PT_BEGIN(pt);

  PT_WAIT_UNTIL(pt, !button_is_pressed && (button_released_duration > BUTTON_DEBOUNCE));
  button_pressed_duration = 0;

  do {
    amount_off = !((time_current&0xFF)<=64) || !((time_current&0x1F)<=16);
    PT_YIELD(pt);
  } while(amount_current && (button_pressed_duration<BUTTON_DEBOUNCE));

  amount_off = 0;
  PT_WAIT_UNTIL(pt,!button_is_pressed);

  PT_END(pt);
}

PT_THREAD(light_knob_pt_func(struct pt *pt))
{
  static unsigned long lastTime;
  static float lastKnobAngle, knob;

  PT_BEGIN(pt);

  enable_orientation();

  // Set the initial knob value based on our current light bightness level.
  knob = sqrt((float)amount_current/(float)BRT_MAX_LUMEN);

  // Wait for the user to let go of the button.
  PT_WAIT_UNTIL(pt,!button_is_pressed);

  // Wait for a brief moment for any vibrations to stabalize.
  PT_WAIT_FOR_PERIOD(pt,50);

  lastKnobAngle = angle_roll;

  do {
    {
      // Make apparent brightness changes linear by squaring the
      // value and dividing back down into range.  This gives us
      // a gamma correction of 2.0, which is close enough.
      unsigned short bright = (uint16_t)(knob * knob * BRT_MAX_LUMEN);

      // Avoid ever appearing off in this mode!
      if (bright < BRT_MIN_LUMEN) bright = BRT_MIN_LUMEN;

      if((amount_current != amount_end) || abs((int16_t)(amount_end-bright)) > 4)
        fade_to_amount(bright,100);
    }

    PT_WAIT_FOR_PERIOD(pt,50);

    {
      #define DEG_TO_RAD(x)    ((PI*(x))/180.0f)
      float change = angle_roll - lastKnobAngle;
      lastKnobAngle = angle_roll;

      // Don't bother updating our brightness reading if our angle isn't good.
      if(abs(angle_pitch) < DEG_TO_RAD(60)) {
        if (change >  PI) change -= 2.0f*PI;
        if (change < -PI) change += 2.0f*PI;
        knob += change / -7.0f;
        if (knob < 0) knob = 0;
        if (knob > 1) knob = 1;
      }
    }
  } while(amount_current && (button_pressed_duration<BUTTON_DEBOUNCE));

  PT_WAIT_UNTIL(pt,!button_is_pressed);

  PT_END(pt);
}

PT_THREAD(light_pt_func(struct pt *pt))
{
  static unsigned long lastTime;
  static byte level;

  PT_BEGIN(pt);

  // Estimate what the current brighness level is closest to.
  if(amount_current < (BRT_LOW_LUMEN/2)) {
    level = 0;
  } else if(amount_current < (BRT_MED_LUMEN/2)) {
    level = 1;
  } else if(amount_current < (BRT_MAX_LUMEN/2)) {
    level = 2;
  } else {
    level = 3;
  }

  button_released_time = time_current;
  button_released_duration = 0;

  Serial.println("Starting light thread.");
  do {
    PT_WAIT_UNTIL(pt, button_is_pressed && (button_pressed_duration > BUTTON_DEBOUNCE));

    if(!amount_current || (button_released_duration<BUTTON_BRIGHTNESS_THRESHOLD)) {
      level++;
      level &= 3;
      Serial.print("intensity=");
      Serial.println(level);
    } else {
      Serial.println("turning off");
      level = 0;
    }

    switch(level) {
    case 0:
      break;

    case 1:
      fade_to_amount(BRT_LOW_LUMEN,250);
      break;

    case 2:
      fade_to_amount(BRT_MED_LUMEN,500);
      break;

    case 3:
      fade_to_amount(BRT_MAX_LUMEN,500);
      break;
    }

    PT_WAIT_UNTIL(pt, !button_is_pressed && (button_released_duration > BUTTON_DEBOUNCE));

    if(!level)
      fade_to_amount(0,500);
  } while(1);

  PT_END(pt);
}

void
check_serial_port(void)
{
  // Check the serial port
  if(Serial.available()) {
    char c = Serial.read();
    switch(c) {
    case '+':
      if(BRT_MAX_LUMEN-amount_current<BRT_MIN_LUMEN)
        set_amount(BRT_MAX_LUMEN);
      else
        set_amount(amount_current+BRT_MIN_LUMEN);
      break;

    case '-':
      if(amount_current<BRT_MIN_LUMEN)
        set_amount(0);
      else
        set_amount(amount_current-BRT_MIN_LUMEN);
      break;

    case 'X':
    case 'x': set_amount(0); break;
    case 'H':
    case 'h': set_amount(BRT_MAX_LUMEN); amount_off = 0; break;

    case '0': light_mode = 0; amount_off = 0; break;
    case '1': light_mode = 1; amount_off = 0; break;
    case '2': light_mode = 2; amount_off = 0; break;
    case '3': light_mode = 3; amount_off = 0; break;
    case '4': light_mode = 4; amount_off = 0; break;
    case '5': light_mode = 5; amount_off = 0; break;

    case 'R':
      // Let the watchdog reset us.
      Serial.println("Rebooting");
      wdt_enable(WDTO_15MS);
      while(1) { }
      break;
      /*
    case 'C':
    case 'c': Serial.println("+------+---------------------+");
              Serial.println("| +    | increase brightness |");
              Serial.println("| -    | decrease brightness |");
              Serial.println("| x/X  | turn light off      |");
              Serial.println("| h/H  | max brightness      |");
              Serial.println("| 0..5 | set light_mode      |");
              Serial.println("| c/C  | list commands       |");
              Serial.println("| R    | reboot              |");
              Serial.println("+------+---------------------+");
    */
    default:
      break;
    }
  }
}

void
setup(void)
{
  // Set our watchdog to kill us if we don't
  // check in every two seconds.
  wdt_enable(WDTO_2S);

  // We just powered on!  That means either we got plugged
  // into USB, or (more likely) the user is pressing the
  // power button.  We need to pull up the enable pin of
  // the regulator very soon so we don't lose power.

  // We don't pull the pin high here quite yet because
  // we will do that when we transition out of MODE_OFF,
  // somewhere in the main loop. Delaying this as long
  // as possible acts like a debounce for accidental button
  // taps.
  pinMode(DPIN_PWR,      INPUT);
  digitalWrite(DPIN_PWR, LOW);

  // Initialize GPIO
  pinMode(DPIN_RLED_SW,  INPUT);
  pinMode(DPIN_GLED,     OUTPUT);
  pinMode(DPIN_DRV_MODE, OUTPUT);
  pinMode(DPIN_DRV_EN,   OUTPUT);
  digitalWrite(DPIN_DRV_MODE, LOW);
  digitalWrite(DPIN_DRV_EN,   LOW);

  // Initialize serial busses
  Serial.begin(9600);
  Wire.begin();

  button_released_time = millis();
  button_pressed_time = millis();

  update_loop_variables();
  update_loop_variables();
  update_loop_variables();

  // Don't bother loading the settings if we are connected to USB.
  // Only load the settings when we are running from the battery.
  if (batt_state == BATT_DISCHARGING) {
    retrieve_settings();
  }

  Serial.println("Powered up!");
}

void
loop(void)
{
  static unsigned long lastTime;
  unsigned long time = millis();

  // Reset the watchdog timer
  wdt_reset();

  update_loop_variables();

  check_serial_port();

  button_led_pt_func(&button_led_pt);

  power_pt_func(&power_pt);

  fade_control_pt_func(&fade_control_pt);

#define NUMBER_OF_MODES    (4)

  static byte last_mode;
  static byte save_mode;
  if((button_pressed_duration > 2048+1024+512*NUMBER_OF_MODES+1024)) {
    if(save_mode == 1) {
      amount_off = 1;
      save_settings();
      amount_off = 0;
      save_mode = 2;
    }
  } else if((button_pressed_duration > 2048+1024+512*NUMBER_OF_MODES)) {
    amount_off = ((button_pressed_duration/64) & 1);
    if(save_mode == 0) {
      save_mode = 1;
      last_mode = 0;
    }
  } else if((button_pressed_duration > 2048)) {
    byte selected_mode = (button_pressed_duration-2048)/512 + 1;
    amount_off = 0;
    if(selected_mode-1>=light_mode) {
      selected_mode++;
    }
    if(selected_mode > NUMBER_OF_MODES)
      selected_mode = NUMBER_OF_MODES;
    if(selected_mode-1==light_mode)
      selected_mode--;
    if(selected_mode != last_mode) {
      amount_flash = 1;
      last_mode = selected_mode;
      Serial.print("Mode selected: ");
      Serial.println(selected_mode-1);
    }
  } else {
    char thread_status;
    if(save_mode) {
      save_mode = 0;
      amount_off = 0;
      button_pressed_duration = 0;
      button_released_duration = 0;
    }
    if(last_mode) {
      light_mode = last_mode-1;
      last_mode = 0;
      Serial.print("Mode change: ");
      Serial.println(light_mode);
      PT_INIT(&light_pt);
      PT_INIT(&light_momentary_pt);
      PT_INIT(&light_blinky_pt);
      PT_INIT(&light_knob_pt);
    }
    switch(light_mode) {
      default:
      case 0: thread_status = light_momentary_pt_func(&light_momentary_pt); break;
      case 1: thread_status = light_pt_func(&light_pt); break;
      case 2: thread_status = light_blinky_pt_func(&light_blinky_pt); break;
      case 3: thread_status = light_knob_pt_func(&light_knob_pt); break;
    }
    if(!PT_SCHEDULE(thread_status)) {
      light_mode = 0;
      fade_to_amount(0,500);
    }
  }

  return;
}

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


Create mdns.ino

Create mdns.ino

#include "MDNS.h"

#define HTTP_PORT 80

MDNS mdns;

String html = "
Ok!
";

TCPServer server = TCPServer(HTTP_PORT);

void setup() {
    bool success = mdns.setHostname("core-1");

    if (success) {
        success = mdns.setService("_http._tcp", HTTP_PORT, "Core 1");
    }

    if (success) {
        success = mdns.addTXTEntry("coreid", "1");
    }

    if (success) {
        success = mdns.begin();
    }

    if (success) {
        Spark.publish("mdns/setup", "success");
    } else {
        Spark.publish("mdns/setup", "error");
    }
}

void loop() {
    mdns.processQueries();

    TCPClient client = server.available();

    if (client){
        client.println(html);
        client.println();
        client.flush();
        client.stop();
    }
}

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


Change to foxy-head-2020.

Change to foxy-head-2020.

Clara visited 20/08/2020 and we changed to swivel to a slowly driven set
of movements.

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


testing led strip

testing led strip

error: pathspec 'Documentation/unit' did not match any file(s) known to git
error: pathspec 'tests/lpd8806/lpd8806.ino' did not match any file(s) known to git


Six channels Leonardo code added

Six channels Leonardo code added

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


Added ESP gw

Added ESP gw

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/werar/iothome.git/'


New example

New example

/*
  Custom view example

 A simple web server that hosts files from SD card.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 27.11.2015
 by Szymon Zmilczak
 */

#include <Ethernet.h>
#include <MiniApache.h>

byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // MAC address from Ethernet shield sticker under board
IPAddress ip(192, 168, 0, 179); // IP address, may need to be changed depending on network
MiniApache apache(80); // Create a server at port 80

void setup(){
    Serial.begin(9600); // Serial for debugging
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH); // Disable Ethernet chip
    Ethernet.begin(mac, ip);  // Initialize Ethernet device
    apache.begin("/served", 4); // Initialize MiniApache server: served path and SD card pin
}

void loop() {
  if(apache.PendingRequest()){ // Check for pending request
    if (apache.RequestIs("/test")){ // Check if request path is equal to /test
      apache.PrintHeader(); // Start response
      // equivalent to PrintHeader(200, "OK", "text/html", false); -  200 (OK) response of text/html type, not cached
      apache.client.print("Test succesfull"); // Write response
      apache.ReportClientServed(); // Finish response
    }
  }
  apache.ProcessRequest();
}

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


example for firmware check

example for firmware check

/*
 * ----------------------------------------------------------------------------
 * This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
 * for further details and other examples.
 *
 * NOTE: The library file MFRC522.h has a lot of useful info. The functions are
 * documented in MFRC522.cpp. Please read it.
 *
 * Released into the public domain.
 * ----------------------------------------------------------------------------
 * Example sketch/program showing how to test your firmware.
 *
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno           Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 */

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.

void setup() {
  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);      // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 module

  Serial.println(F("*****************************"));
  Serial.println(F("MFRC522 Digital self test"));
  Serial.println(F("*****************************"));
  ShowReaderDetails();  // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Performing test..."));
  bool result = mfrc522.PCD_PerformSelfTest();
  Serial.println(F("-----------------------------"));
  Serial.print(F("Result: "));
  if (result)
    Serial.println(F("OK"));
  else
    Serial.println(F("defect or unknown"));
  Serial.println();
}

void loop() {} // nothing to do

void ShowReaderDetails() {
  // Get the MFRC522 firmware version
  byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
  Serial.print(F("Firmware Version: 0x"));
  Serial.print(v, HEX);
  if (v == 0x91)
    Serial.print(F(" = v1.0"));
  else if (v == 0x92)
    Serial.print(F(" = v2.0"));
  else
    Serial.print(F(" = (unknown)"));
  Serial.println();
  // When 0x00 or 0xFF is returned, communication probably failed
  if ((v == 0x00) || (v == 0xFF))
    Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
}

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


Adding Arduino test sketch to check bubbling occurs when asked.

/* BubbleTriggerTest
*
*  copyright Becky Stewart, Anti-Alias Labs
*  becky@antialiaslabs.com
*
*  Tests that bubbling is occurring correctly by cycling
*  through bubbling.
*/

// pins
int greenStatusLED = 6;
int yellowStatusLED = 5;
int relay1 = 2;
int relay2 = 3;

// other variables
int bubbleTime = 150;
int bubbleThrottle = 5000;

void setup() {
  // set up pin modes
  pinMode( greenStatusLED, OUTPUT );
  pinMode( yellowStatusLED, OUTPUT );
  pinMode( relay1, OUTPUT );
  pinMode( relay2, OUTPUT );

  // start serial
  //Serial.begin( 9600 );
  //while( !Serial );

  // print welcome message at startup
  //Serial.println( "Testing the bubbler");

}

void loop() {

  // bubble a test series
  //Serial.println("...bubbles");
  bubble();

  delay( 500 );

  bubble();

  delay( 30000 );
}

void bubble() {
  // turn on status LED
  digitalWrite( greenStatusLED, HIGH );
  digitalWrite( yellowStatusLED, LOW );

  // trigger relay
  digitalWrite( relay1, HIGH );
  digitalWrite( relay2, HIGH );

  // wait to create bubbles
  delay( bubbleTime );

  // stop relay
  digitalWrite( relay1, LOW );
  digitalWrite( relay2, LOW );

  // update status LEDs
  digitalWrite( greenStatusLED, LOW);
  digitalWrite( yellowStatusLED, HIGH);

  // wait to throttle bubbling
  delay( bubbleThrottle );
}

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


versionmejorada

versionmejorada

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


Create BH1750FVI_4Wire.ino

Create BH1750FVI_4Wire.ino

Added a new very simple example with just 4 wires (VCC,GND,SDA,SCL)

/*
  This example uses only 4 wires to test the BH1750 Light sensor

  Connecting the sensor to a NodeMCU ESP8266:
  VCC  <-> 3V3
  GND  <-> GND
  SDA  <-> D2
  SCL  <-> D1

  Connecting the sensor to a Arduino UNO:
  VCC  <-> 3V3
  GND  <-> GND
  SDA  <-> A4/SDA
  SCL  <-> A5/SCL

  Connecting the sensor to a Arduino DUE:
  VCC  <-> 3V3
  GND  <-> GND
  SDA  <-> D20/SDA
  SCL  <-> D21/SCL
*/

#include <BH1750FVI.h>

// Create the Lightsensor instance
BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);

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

void loop()
{
  uint16_t lux = LightSensor.GetLightIntensity();
  Serial.print("Light: ");
  Serial.println(lux);
  delay(250);
}

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


display on nokia screen with arduino -ac

/*********************************************************************
This is an example sketch for our Monochrome Nokia 5110 LCD Displays

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/338

These displays use SPI to communicate, 4 or 5 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, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include <math.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer.  Be careful sharing these pins!

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

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

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

  display.begin();
  // init done

  // you can change the contrast around to adapt the display
  // for the best viewing!
  display.setContrast(50);

  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer

  // draw a single pixel
  display.drawPixel(10, 10, BLACK);
  display.display();
  delay(2000);
  display.clearDisplay();

//  // draw many lines
//  //testdrawline();
//  //display.display();
//  //delay(2000);
//  //display.clearDisplay();
//
//  // draw rectangles
//  testdrawrect();
//  display.display();
//  delay(2000);
//  display.clearDisplay();
//
//  // draw multiple rectangles
//  testfillrect();
//  display.display();
//  delay(2000);
//  display.clearDisplay();
//
//  // draw mulitple circles
//  testdrawcircle();
//  display.display();
//  delay(2000);
//  display.clearDisplay();

  // draw a circle, 10 pixel radius
  display.fillCircle(display.width()/2, display.height()/2, 10, BLACK);
  display.display();
  delay(2000);
  display.clearDisplay();
//
//  testdrawroundrect();
//  delay(2000);
//  display.clearDisplay();
//
//  testfillroundrect();
//  delay(2000);
//  display.clearDisplay();
//
//  testdrawtriangle();
//  delay(2000);
//  display.clearDisplay();
//
//  testfilltriangle();
//  delay(2000);
//  display.clearDisplay();
//
  // draw the first ~12 characters in the font
  testdrawchar();
  display.display();
  delay(2000);
  display.clearDisplay();

  // text display tests
  //display.setTextSize(1);
//  display.setTextColor(BLACK);
//  display.setCursor(0,0);
//  display.println("Hello, world!");
//  display.setTextColor(WHITE, BLACK); // 'inverted' text
//  display.println(3.141592);
//  display.setTextSize(2);
//  display.setTextColor(BLACK);
//  display.print("0x"); display.println(0xDEADBEEF, HEX);
//  display.display();
//  delay(2000);
//
//  // rotation example
//  display.clearDisplay();
//  display.setRotation(1);  // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further.
//  display.setTextSize(1);
//  display.setTextColor(BLACK);
//  display.setCursor(0,0);
//  display.println("Rotation");
//  display.setTextSize(2);
//  display.println("Example!");
//  display.display();
//  delay(2000);

  // revert back to no rotation
  display.setRotation(0);

  // miniature bitmap display
  //display.clearDisplay();
  //display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  //display.display();

  // invert the display
  //display.invertDisplay(true);
  //delay(1000);
  //display.invertDisplay(false);
  //delay(1000);

  // draw a bitmap icon and 'animate' movement
  //testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT);
   // Wait for serial to come in, then clear display and go to echo
   display.fillCircle(display.width()/2, display.width()/2, 2, BLACK);
   display.display();
   delay(2000);
   display.clearDisplay();

   while (! Serial); // Wait until Serial is ready
}

// Loop turns the display into a local serial monitor echo.
// Type to the Arduino from the serial monitor, and it'll echo
// what you type on the display. Type ~ to clear the display.
void loop()
{

  int16_t x0 = display.width()/2;
  int16_t y0 = display.height()/2;
  display.fillCircle(x0, y0, 0.5, BLACK);
  display.display();

  int16_t r =20;

  double theta=0;
  double DEGREES_TO_RADIANS = 2*PI/360;

  if (Serial.available())
  {
    int angle = Serial.parseInt();

    theta = angle*DEGREES_TO_RADIANS;
    double delta_x = r*cos(theta);
    double delta_y = r*sin(theta);
    int16_t x1 = x0+ (int)delta_x;
    int16_t y1 = y0+ (int)delta_y;

    // draw a circle, 2 pixel radius
    display.fillCircle(x1, y1, 2, BLACK);
    display.display();
    // draw a line
    display.drawLine(x0, y0, x1, y1, BLACK);
    display.display();
    delay(1000);
    display.clearDisplay();
    display.fillCircle(x0, y0, 0.5, BLACK);
    display.display();

  }
}

void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
  uint8_t icons[NUMFLAKES][3];
  randomSeed(666);     // whatever seed

  // initialize
  for (uint8_t f=0; f< NUMFLAKES; f++) {
    icons[f][XPOS] = random(display.width());
    icons[f][YPOS] = 0;
    icons[f][DELTAY] = random(5) + 1;

    Serial.print("x: ");
    Serial.print(icons[f][XPOS], DEC);
    Serial.print(" y: ");
    Serial.print(icons[f][YPOS], DEC);
    Serial.print(" dy: ");
    Serial.println(icons[f][DELTAY], DEC);
  }

  while (1) {
    // draw each icon
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, BLACK);
    }
    display.display();
    delay(200);

    // then erase it + move it
    for (uint8_t f=0; f< NUMFLAKES; f++) {
      display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, WHITE);
      // move it
      icons[f][YPOS] += icons[f][DELTAY];
      // if its gone, reinit
      if (icons[f][YPOS] > display.height()) {
	icons[f][XPOS] = random(display.width());
	icons[f][YPOS] = 0;
	icons[f][DELTAY] = random(5) + 1;
      }
    }
   }
}

void testdrawchar(void) {
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.setCursor(0,0);

  for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    //if ((i > 0) && (i % 14 == 0))
      //display.println();
  }
  display.display();
}

void testdrawcircle(void) {
  for (int16_t i=0; i<display.height(); i+=2) {
    display.drawCircle(display.width()/2, display.height()/2, i, BLACK);
    display.display();
  }
}

void testfillrect(void) {
  uint8_t color = 1;
  for (int16_t i=0; i<display.height()/2; i+=3) {
    // alternate colors
    display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
    display.display();
    color++;
  }
}

void testdrawtriangle(void) {
  for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
    display.drawTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, BLACK);
    display.display();
  }
}

void testfilltriangle(void) {
  uint8_t color = BLACK;
  for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
    display.fillTriangle(display.width()/2, display.height()/2-i,
                     display.width()/2-i, display.height()/2+i,
                     display.width()/2+i, display.height()/2+i, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}

void testdrawroundrect(void) {
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, BLACK);
    display.display();
  }
}

void testfillroundrect(void) {
  uint8_t color = BLACK;
  for (int16_t i=0; i<display.height()/2-2; i+=2) {
    display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
    if (color == WHITE) color = BLACK;
    else color = WHITE;
    display.display();
  }
}

void testdrawrect(void) {
  for (int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, BLACK);
    display.display();
  }
}

void testdrawoneline() {
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, BLACK);
    display.display();
  }
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, BLACK);
    display.display();
  }
  delay(250);
}

void testdrawline() {
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, BLACK);
    display.display();
  }
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, BLACK);
    display.display();
  }
  delay(250);

  display.clearDisplay();
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, BLACK);
    display.display();
  }
  for (int8_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, BLACK);
    display.display();
  }
  delay(250);

  display.clearDisplay();
  for (int16_t i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, BLACK);
    display.display();
  }
  for (int16_t i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, BLACK);
    display.display();
  }
  delay(250);

  display.clearDisplay();
  for (int16_t i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, BLACK);
    display.display();
  }
  for (int16_t i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, BLACK);
    display.display();
  }
  delay(250);
}

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


Add Arduino - MQ7, Temperature Sensor

Add Arduino - MQ7, Temperature Sensor

#include <DHT11.h>
#include <SoftwareSerial.h>

//SoftwareSerial BTSerial(10, 11); // BLE(TXD) - RX(Arduino - 10) | BLE(RXD) - TX(Arduino - 11)

                                   // Serial1 (Arduino - Mega)
                                   // BLE(TXD) - RX(Arduino - 19) | BLE(RXD) - TX(Arduino - 18)
uint8_t buffer[256];
uint8_t index = 0;

// 3.3 v
//int Magnetic_Value = 0;
//int Magnetic_PIN = 2;   // Digital
//int Flame_Value = 0;
//int Flame_PIN = 5;      // Digital

// no Voltage
int LEDGREEN_PIN = 9;        // Digital
int LEDRED_PIN = 10;        // Digital

// 5.0v
int CO_Value = 100;
int CO_PIN = 3;         // Analog
int Buzzer_PIN = 12;    // Digital

int DHT_PIN=4;          // Digital
DHT11 dht11(DHT_PIN);

void setup(){
//  pinMode(Magnetic_PIN, INPUT);
  //pinMode(Flame_PIN, INPUT);
  pinMode(Buzzer_PIN,OUTPUT);
  pinMode(LEDGREEN_PIN, OUTPUT);
  pinMode(LEDRED_PIN, OUTPUT);

  //pinMode(13, OUTPUT);
//  Buzzer_OFF();

  Serial.begin(9600);        //Arduino Bluetooth - PC Serial
  Serial1.begin(9600);
  // PC   ==  Serial1.begin(115200);    //Arduino Bluetooth - Bluetooth connect Device
  // using Putty set baudrate
  Serial.println("Ready..");

}

void loop(){

  // 불꽃 발생시  0, 평상 시 1 반환
  //Flame_Check();

  // 문 닫혀있을 경우(자석 붙어있음) 0, 열려있을 경우(자석 떨어짐) 1 반환
  //Magnetic_Check();

  // 라이터 가스 주입 시 500 이상 유지 평사시 300 ~ 500 미만 사이 유지
  CO_Check();
  Serial.println("temp");
 Temp_Check();
  Serial.print("index=");
  Serial.println(index);

  Serial1.write(buffer,index);
   for(uint8_t i = 0; i< index; i++){
     Serial.println(buffer[i]);
     delay(50);
   }

   delay(50);

  index = 0;
}

// 불꽃 발생시  0, 평상 시 1 반환
/*void Flame_Check(){
  Flame_Value = digitalRead(Flame_PIN);

  if(Flame_Value == HIGH){
    Buzzer_OFF();
    ColorLed_OFF();
    buffer[index++] = 's';
  }else{
    ColorLed_ON();
    //Buzzer_ON();
    buffer[index++] = 'f';
  }
  Serial.print("FlameValue : \r ");
  Serial.print(Flame_Value, DEC);
  Serial.println("\n");
  delay(50);

  Flame_Value = 0;
}

// 문 닫혀있을 경우(자석 붙어있음) 0, 열려있을 경우(자석 떨어짐) 1 반환
void Magnetic_Check(){
  Magnetic_Value = digitalRead(Magnetic_PIN);

  if(Magnetic_Value == HIGH){
    ColorLed_ON();
   buffer[index++] = 'o';
  }else{
    ColorLed_OFF();
   buffer[index++] = 'c';
  }
  Serial.print("MagneticValue : \r ");
  Serial.print(Magnetic_Value, DEC);
  Serial.println("\n");
  delay(50);

  Magnetic_Value = 0;
}
*/
// 라이터 가스 주입 시 500 이상 유지 평사시 300 ~ 500 미만 사이 유지
void CO_Check(){
  CO_Value = analogRead(CO_PIN) * 3;
/*
  // 1단계_안전(~400)
  if(CO_Value < 400) {
    ColorLed_ON();
    buffer[index++] = 'a';
  }
  // 2단계 (400~600)
  else if (CO_Value >= 400 && CO_Value < 600) {
    buffer[index++] = 'b';
  }
  // 3단계 (600~1000)
  else if (CO_Value >= 600 && CO_Value < 1000) {
    buffer[index++] = 'c';
  }
  else {
    ColorLed_OFF();
    buffer[index++] = 'd';
  }*/

  Serial.print("CO_Value : \r ");
  Serial.print(CO_Value, DEC);
  Serial.println("\n");
  Serial.println(index);

  pack32(CO_Value,buffer);

  delay(50);

  CO_Value = 0;

}

void pack32(uint32_t val,uint8_t *dest)
{
        dest[index++] = (val & 0xff000000) >> 24;
        dest[index++] = (val & 0x00ff0000) >> 16;
        dest[index++] = (val & 0x0000ff00) >>  8;
        dest[index++] = (val & 0x000000ff)      ;
}

void Temp_Check(){
  int err;
  float temp,humi;

  if((err=dht11.read(temp,humi))==0)
  {
    buffer[index++] = temp;
   // buffer[index++] = humi;
  }

    Serial.print(temp);

  delay(DHT11_RETRY_DELAY); //delay for reread
}
/*
void Buzzer_ON(){
  int i;
    for(i=0;i<80;i++){ //output sound of one frequency
      digitalWrite(Buzzer_PIN,HIGH);//make a sound
      delay(1);//delay 1ms
      digitalWrite(Buzzer_PIN,LOW);//silient
      delay(1);//delay 1ms
    }
    for(i=0;i<300;i++) {//output sound of another frequency
      digitalWrite(Buzzer_PIN,HIGH);//make a sound
      delay(2);//delay 2ms
      digitalWrite(Buzzer_PIN,LOW);//silient
      delay(2);//delay 2ms
    }
}
void Buzzer_OFF(){
   digitalWrite(Buzzer_PIN,LOW);
}

// RED 점멸
void ColorLed_ON(){
  digitalWrite(LEDGREEN_PIN,HIGH);
}

// GREEN 점멸
void ColorLed_OFF(){
  digitalWrite(LEDGREEN_PIN, LOW);
}*/

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


add version 3.10

add version 3.10

#include "CapacitiveSensor.h"

CapacitiveSensor cs_7_8 = CapacitiveSensor(7, 8);
CapacitiveSensor cs_7_9 = CapacitiveSensor(7, 9);
CapacitiveSensor cs_7_10 = CapacitiveSensor(7, 10);
CapacitiveSensor cs_7_11 = CapacitiveSensor(7, 11);
CapacitiveSensor cs_7_12 = CapacitiveSensor(7, 12);

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

  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(13, OUTPUT);
  // CAPACITIVE SENSOR
/*  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);

  */

  cs_7_8.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_7_9.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_7_10.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_7_11.set_CS_AutocaL_Millis(0xFFFFFFFF);
  cs_7_12.set_CS_AutocaL_Millis(0xFFFFFFFF);

}

void loop() {

  int scale = map(analogRead(0), 0, 1023, 0, 4);
  int len = analogRead(5) + 50;
  float t1 = 220;
  float t2 = 246.94;
  float t3 = 277.18;
  float t4 = 293.66;
  float t5 = 329.63;

  long total0 = cs_7_8.capacitiveSensor(30);
  long total1 = cs_7_9.capacitiveSensor(30);
  long total2 = cs_7_10.capacitiveSensor(30);
  long total3 = cs_7_11.capacitiveSensor(30);
  long total4 = cs_7_12.capacitiveSensor(30);

  long sens = 500;

  if (scale == 0) {

    t1 = 220;
    t2 = 246.94;
    t3 = 277.18;
    t4 = 293.66;
    t5 = 329.63;
  }
  if (scale == 1) {

    t1 = 261.63;
    t2 = 293.66;
    t3 = 329.63;
    t4 = 349.23;
    t5 = 392.00;
  }
  if (scale == 2) {

    t1 = 293.66;
    t2 = 329.63;
    t3 = 349.23;
    t4 = 392.00;
    t5 = 440.00;
  }
  if (scale == 3) {

    t1 = 349.23;
    t2 = 392.00;
    t3 = 440.00;
    t4 = 466.16;
    t5 = 523.25;
  }
  if (scale == 4) {

    t1 = 392.00;
    t2 = 440.00;
    t3 = 493.88;
    t4 = 523.25;
    t5 = 587.33;
  }

  if (total0 > sens) {
    tone(13, t1);
    delay(len);
    noTone(13);

  }

  if (total1 > sens) {
    tone(13, t2);
    delay(len);
    noTone(13);

  }
  if (total2 > sens) {
    tone(13, t3);
    delay(len);
    noTone(13);

  }
  if (total3 > sens) {
    tone(13, t4);
    delay(len);
    noTone(13);

  }
  if (total4 > sens) {
    tone(13, t5);
    delay(len);
    noTone(13);
  }

// regular buttons
if (digitalRead(2) == HIGH) {
    tone(13, t1);
    delay(len);
    noTone(13);

  }

  if (digitalRead(3) == HIGH) {
    tone(13, t2);
    delay(len);
    noTone(13);

  }
  if (digitalRead(4) == HIGH) {
    tone(13, t3);
    delay(len);
    noTone(13);

  }
  if (digitalRead(5) == HIGH) {
    tone(13, t4);
    delay(len);
    noTone(13);

  }
  if (digitalRead(6) == HIGH) {
    tone(13, t5);
    delay(len);
    noTone(13);
  }

}

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


Added VernierAnalogStore sketch.

Added VernierAnalogStore sketch.

/*
VernierAnalogStore
Reads a Vernier analog (BTA) Sensor connected to pin A0 of the Arduino and and stores  the data in the non-volatile EEPROM memory of the Arduino.
This sketch displays the time and sensor readings on the Serial Monitor.
As written, the readings will be displayed every half second.
Change the variable TimeBetweenReadings to change the rate.
Change the variable NumberOfReadings to change the number of data points to take.
 See www.vernier.com/arduino for more information, especially for information on how this sketch can be used to collect remote data with the Arduino away from a computer.
 Thanks to B. Huang, for help on this program, especially the structure of a program to store and retrieve data.
*/
int buttonPin= 12; // analog input pin to use as a digital input
int ledPin1= 13; // digital output pin for LED 1 indicator
int debounce= 20; // ms debounce period to prevent flickering when pressing or releasing the button
int holdTime= 2000; // ms hold period: how long to wait for press+hold event
#include <EEPROM.h>
int base = 0;  // the base address in EEPROM for data storage
// note first two bytes store the number of points collected
// Button variables
int buttonVal = 0; // value read from button
int buttonLast = 1; // buffered value of the button's previous state
long btnDnTime; // time the button was pressed down
long btnUpTime; // time the button was released
boolean ignoreUp = false; // whether to ignore the button release because the click+hold was triggered
boolean ledVal1 = false; // state of LED 1
int AnalogDataPin = A1; // this may be changed depending on circuit wiring
int Count;
float Voltage;
float SensorReading;
unsigned long Time;
long unsigned int TimeBetweenReadings = 500; //in ms
int NumberOfPoints= 511;
///////////////////////////////////
String SensorName = "Dual-Range Force Sensor";
String Measurement = "Force";
String ShortMeasurement = "F"; // this is a shortened version of the label
String Units = "Newtons";
float Intercept = 12.25;
float Slope = -4.9;
///////////////////////////////////
void setup()
{
// Set button input pin
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
pinMode(AnalogDataPin, INPUT);
pinMode(ledPin1, OUTPUT);// Set LED output pin
Serial.begin(9600);
Serial.println("VernierAnalogStore sketch");
Serial.println("Press and hold to collect new data");
Serial.println("Press button briefly to read data stored in EEPROM");
Serial.println("and send it to the Serial Monitor");
Serial.println(" ");
}
void loop()
{
digitalWrite(ledPin1, false);
// Read the state of the button
buttonVal = digitalRead(buttonPin);// button down is low
// Test for button pressed and store the down time
if (buttonVal == LOW && buttonLast == HIGH && (millis() - btnUpTime) > long(debounce))
{ //button pressed
  btnDnTime = millis();// note time of press
}
// Test for button release and store the up time
if (buttonVal == HIGH && buttonLast == LOW && (millis() - btnDnTime) > long(debounce))
{
  if (ignoreUp == false) ReadEEPROMData();// read data from EEPROM and send to Serial Monitor
  else ignoreUp = false;
btnUpTime = millis();// note time of button release
}
// Test for button held down for longer than the hold time
if (buttonVal == LOW && (millis() - btnDnTime) > long(holdTime))
{
CollectData(); //collect new data
ignoreUp = true;
btnDnTime = millis(); // get new button down time
}
buttonLast = buttonVal;
}
//=================================================
// Events to trigger by click and press+hold
void ReadEEPROMData()// //Send data to Serial Monitor
{
  ledVal1 = !ledVal1;
  digitalWrite(ledPin1, true);
  int NumberOfPointsRead;// local variable
  Serial.println("Send Data to Serial Monitor");
  Serial.println(" ");
  int Sample = 0;// local variables
  int i = 0;
  int addr = base+ 2; //starting address of memory for data storage
  //note addr is laterincremented
  NumberOfPointsRead = EEPROM.read(base) + EEPROM.read(base+ 1)*256;
  Serial.println( "Vernier Format 2");
  Serial.print(NumberOfPointsRead);
  Serial.print(" readings taken with a Vernier ");
  Serial.println(SensorName);
  Serial.println("Data Set From Arduino");
  Serial.print("Time");
  Serial.print("\t");                // print a tab character
  Serial.println(Measurement);
  Serial.print("T");
  Serial.print("\t");                // print a tab character
  Serial.println(ShortMeasurement);
  Serial.print("s");
  Serial.print("\t");                // print a tab character
  Serial.println(Units);
  for (i = 0; i <(NumberOfPointsRead)*2; i+=2)
   {
    Count = EEPROM.read(base+2 + i) | EEPROM.read(base+2 + i + 1) << 8;
    //the print below does the division first to avoid overflows
    Serial.print(i/2/1000.0*TimeBetweenReadings);
    Serial.print("\t");                // print a tab character
    Voltage = Count  * (5.0/ 1024);
    SensorReading= Intercept + Voltage * Slope;
    Serial.println(SensorReading);
  }
Serial.println(" ");
Serial.println("Press and hold button to collect new data ");
Serial.println(" ");
digitalWrite(ledPin1, false); //turn off LED
//end of send data to Serial Monitor
}
void CollectData() //Collect Data
{
ledVal1 = !ledVal1;
Serial.begin(9600);
Serial.println("Collecting Data...");
Serial.println(" ");
int Sample = 0;// local variable
unsigned long StartTime =0;
int addr = base+ 2; //starting address of memory for data storage
//note addr is later incremented
 Serial.println( "Vernier Format 2");
  Serial.print(NumberOfPoints);
  Serial.print(" readings taken with a Vernier ");
  Serial.println(SensorName);
  Serial.println("Data Set From Arduino");
  Serial.print("Reading");
  Serial.print("\t");
  Serial.print("Time");
  Serial.print("\t");                // print a tab character
  Serial.println(Measurement);
  Serial.print("n");
  Serial.print("\t");
  Serial.print("T");
  Serial.print("\t");                // print a tab character
  Serial.println(ShortMeasurement);
  Serial.print("#");
  Serial.print("\t");
  Serial.print("s");                // print a tab character
  Serial.print("\t");
  Serial.println(Units);
  StartTime = millis();// time of last reading in ms
  for (Sample=0;Sample<NumberOfPoints;Sample++)
  {digitalWrite(ledPin1, true);
    Serial.print(Sample);
    Serial.print("\t");
    //the print below does the division first to avoid overflows
    Serial.print(Sample/1000.0*TimeBetweenReadings);
    Serial.print("\t");
    Count= analogRead(A1);
    Voltage = Count * (5.0/ 1024);
    SensorReading = Intercept + Voltage * Slope;
    Serial.println(SensorReading);
    EEPROM.write(addr, lowByte(Count));
    EEPROM.write(addr + 1, highByte(Count));
    addr +=2;  //increment address pointer twice
   delay (TimeBetweenReadings/2);//these lines are to give a blink to the LED
   digitalWrite(ledPin1, false);
   delay (TimeBetweenReadings/2);
  }
//the number of points is stored at base and base+1;
//data starts at the next two bytes (base=2 and base+3, etc);
EEPROM.write(base+ 0, lowByte(NumberOfPoints));
EEPROM.write(base + 1, highByte(NumberOfPoints));
Serial.println(" ");
Serial.println("Press button briefly to send data to Serial Monitor");
Serial.println("Press and hold to collect new data");
Serial.println(" ");
digitalWrite(ledPin1, false);
};//end of Data Collect

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


Just adding a File

Just adding a File

#include <Motor.h>
#include "QTRSensors_teensy3.h"

#define BLUETOOTH Serial1

#define ON_LINE(sensor)((sensor<COMPARE))
#define OVERSHOOT_LINE_TIME 50

// PID Constants
#define KP	2
#define KI	0
#define KD	80

// MAX SPEED
#define SPEED_MAX 2048
#define SPEED_CALIBRATE 786
#define SPEED_TURN 1024

// Enable for white line on black background
#define WHITE_ON_BLACK 1
#define COMPARE 300

// QTR 8RC SETUP
#define NUMBER_OF_SENSORS 8
#define EMITTER_ON 1
#define EMITTER_PIN 22
#define TIMEOUT 2500

// Motor Driver Configurations
#define MOTOR_DRIVER_PIN_STANDBY 7
#define ENABLE_STANDBY digitalWrite(MOTOR_DRIVER_PIN_STANDBY, HIGH)
#define DISABLE_STANDBY digitalWrite(MOTOR_DRIVER_PIN_STANDBY, LOW)

// Buzzer Settings
#define BUZZER_PIN 23
#define BUZZER_ON digitalWrite(BUZZER_PIN, HIGH);
#define BUZZER_OFF digitalWrite(BUZZER_PIN, LOW);

#define DEBUG_MODE 0

motor motorLeft, motorRight;

// Sensor configs
unsigned char sensorPins[] = { 14, 15, 16, 17, 18, 19, 20, 21 };
unsigned short sensorValues[NUMBER_OF_SENSORS];

// PID Variables
float position_ = 0, proportional = 0, derivative = 0, integral = 0, lastProportional = 0;
float control = 0;

// Record the path
char path[100];
unsigned int pathCounter = 0;

// Initialize QTR8RC Sensor Array with sensor pins array
// and number of sensors as second parameter
QTRSensorsRC qtrRC(sensorPins, NUMBER_OF_SENSORS, TIMEOUT, EMITTER_PIN);

unsigned char FOUND_LEFT()
{
	return (ON_LINE(sensorValues[0]) && ON_LINE(sensorValues[1]) && ON_LINE(sensorValues[2]) && ON_LINE(sensorValues[3]) && ON_LINE(sensorValues[4]));
}

unsigned char FOUND_RIGHT()
{
	return (ON_LINE(sensorValues[7]) && ON_LINE(sensorValues[6]) && ON_LINE(sensorValues[5]) && ON_LINE(sensorValues[4]) && ON_LINE(sensorValues[3]));
}

unsigned char FOUND_STRAIGHT()
{
	return((ON_LINE(sensorValues[2]) || ON_LINE(sensorValues[3])) && (ON_LINE(sensorValues[4]) && ON_LINE(sensorValues[5])));
}

char selectTurn(unsigned char found_left, unsigned char found_right, unsigned char found_straight)
{
	if (found_left)
		return 'L';
	else if (found_right)
		return 'R';
	else if (found_straight)
		return 'S';
}

void turn(char direction, unsigned int speed, unsigned short delayTime)
{
	switch (direction)
	{
	case 'L':
		motorLeft.write(-speed);
		motorRight.write(speed);
		delay(delayTime);
		break;

	case 'R':
		motorLeft.write(speed);
		motorRight.write(-speed);
		delay(delayTime);
		break;

	case 'S':
		break;
	}

}

int readSensors()
{
	int pos;
	if (WHITE_ON_BLACK == 1)
		pos = qtrRC.readLine(sensorValues, QTR_EMITTERS_ON, true);

	else
		pos = qtrRC.readLine(sensorValues);

	return pos;
}

void setup()
{
	if (DEBUG_MODE == 1)
	{
		Serial.begin(9600);
	}

	BLUETOOTH.begin(9600);

	pinMode(MOTOR_DRIVER_PIN_STANDBY, OUTPUT);
	pinMode(13, OUTPUT);

	//DISABLE_STANDBY;
	ENABLE_STANDBY;

	pinMode(BUZZER_PIN, OUTPUT);

	motorLeft.setPins(6, 5, 4);
	motorRight.setPins(8, 9, 10);

	motorLeft.setMaxSpeed(SPEED_MAX);
	motorRight.setMaxSpeed(SPEED_MAX);

	motorLeft.initialise();
	motorRight.initialise();

	//12 bit width of analog write values
	analogWriteResolution(12);

	//BLUETOOTH.begin(9600);

	digitalWrite(13, HIGH);
	BUZZER_ON;
	initializeBot();
	BUZZER_OFF;
	digitalWrite(13, LOW);

}

void initializeBot()
{
	// Calibrate sensors
	for (unsigned int i = 0; i < 75; i++)
	{
		if (i == 0)
			turn('L', SPEED_CALIBRATE, 0);
		if (i == 20)
			turn('R', SPEED_CALIBRATE, 0);
		if (i == 55)
			turn('L', SPEED_CALIBRATE, 0);

		// Emitters on
		//if (WHITE_ON_BLACK == 1 && EMITTER_ON == 1)
		//	qtrRC.calibrate(QTR_EMITTERS_ON);

		// Emitters off
		//else
		qtrRC.calibrate();

	}

	//Display values serially in debugMode for Debugging
	if (DEBUG_MODE == 1)
	{
		for (unsigned char i = 0; i < NUMBER_OF_SENSORS; i++)
		{
			Serial.print(qtrRC.calibratedMinimumOn[i]);
			Serial.print(' ');
		}
		Serial.println(' ');
		for (unsigned char i = 0; i < NUMBER_OF_SENSORS; i++)
		{
			Serial.print(qtrRC.calibratedMinimumOff[i]);
			Serial.print(' ');
		}
	}
}

void showSensorValues()
{
	for (unsigned char i = 0; i < NUMBER_OF_SENSORS; i++)
	{
		Serial.print(sensorValues[i]);
		Serial.print(' ');
	}

	Serial.println();

}

void loop()
{
	//delay(500);
	followSegment();
	followSegment();
	followSegment();
	runMappingMode();
}

void followSegment()
{
	position_ = readSensors();

	if (DEBUG_MODE == 1)
		showSensorValues();

	proportional = position_ - 3500;

	derivative = proportional - lastProportional;
	lastProportional = proportional;
	integral += proportional;

	control = proportional *KP + integral*KI + derivative*KD;

	if (DEBUG_MODE == 1)
	{
		Serial.print("Control  ");
		Serial.print(control);
		Serial.print(" Position  ");
		Serial.print(proportional);
		Serial.println("  ");
	}

	if (control > SPEED_MAX)
		control = SPEED_MAX;
	if (control < -SPEED_MAX)
		control = -SPEED_MAX;

	if (control < 0)
	{
		motorLeft.write(SPEED_MAX + control);
		motorRight.write(SPEED_MAX);
	}
	else
	{
		motorLeft.write(SPEED_MAX);
		motorRight.write(SPEED_MAX - control);
	}

}

void runMappingMode()
{

	unsigned char foundLeft = 0, foundStraight = 0, foundRight = 0;
	// C - Left 90 Junction
	// D - Right 90 Junction
	// T - Point Junction
	// L - Left 90
	// R - Right 90

	//followSegment();

	position_ = readSensors();

	// Starting of intersection
	if (FOUND_LEFT())
		foundLeft = 1;
	if (FOUND_RIGHT())
		foundRight = 1;

	if (foundLeft || foundRight)
	{
		/*BLUETOOTH.print("foundLeft");
		BLUETOOTH.println(foundLeft);

		BLUETOOTH.print("foundRight");
		BLUETOOTH.println(foundRight);
		*/

		//motorLeft.setSpeed(-1024);
		//motorRight.setSpeed(-1024);

		//motorLeft.stop();
		//motorRight.stop();

		//delay(30);

		//position_ = readSensors();

		if (foundLeft && foundRight)
		{
			//delay(10);
			while (FOUND_LEFT() || FOUND_RIGHT())
				position_ = readSensors();

			if (FOUND_STRAIGHT())
			{

				path[pathCounter++] = 'J';
				path[pathCounter] = '\0';
				motorLeft.write(-1024);
				motorRight.write(-1024);
				delay(50);
				DISABLE_STANDBY;
				BLUETOOTH.println(path[pathCounter - 1]);
				BLUETOOTH.println(path);
				while (1)
					BUZZER_ON;
			}
			else
				foundLeft = 1;/*
			if (!FOUND_STRAIGHT)
			{
				BUZZER_ON;
				path[pathCounter++] = 'T';
				BLUETOOTH.println(path[pathCounter - 1]);
				foundLeft = 1;
			}*/

			BUZZER_OFF;
		}

		else if (foundLeft && !foundRight)
		{
			BUZZER_ON;
			while (FOUND_LEFT())
			{
				position_ = readSensors();
			}
			if (FOUND_STRAIGHT())
			{
				BUZZER_ON;
				path[pathCounter++] = 'C';
				BLUETOOTH.println(path[pathCounter - 1]);
				foundLeft = 1;
			}
			else
			{
				path[pathCounter++] = 'L';
				BLUETOOTH.println(path[pathCounter - 1]);
				foundLeft = 1;
			}
			BUZZER_OFF;

		}

		else if (foundRight && !foundLeft)
		{
			BUZZER_ON;
			while (FOUND_RIGHT())
			{
				position_ = readSensors();
			}
			if (!FOUND_STRAIGHT())
			{

				path[pathCounter++] = 'R';
				BLUETOOTH.println(path[pathCounter - 1]);
				foundRight = 1;
			}

			else
			{
				BUZZER_ON;
				path[pathCounter++] = 'D';
				BLUETOOTH.println(path[pathCounter - 1]);
				foundRight = 1;

			}
			BUZZER_OFF;
		}

		//BUZZER_ON;
		////delay(30);
		//motorLeft.write(-32);
		//motorRight.write(-32);
		//

		//delay(70);
		//BUZZER_OFF;

		//position_ = readSensors();

		//// appx in the middle of intersection
		///*if (ON_LINE(sensorValues[0]))
		//	foundLeft = 1;
		//	if (ON_LINE(sensorValues[7]))
		//	foundRight = 1;

		//	delay(OVERSHOOT_LINE_TIME / 2);*/

		////Ahead of intersection
		///*if (ON_LINE(sensorValues[0]))
		//	foundLeft = 1;
		//if (ON_LINE(sensorValues[7]))
		//	foundRight = 1;*/

		//if ( (ON_LINE(sensorValues[2]) || ON_LINE(sensorValues[3]) ) && ( ON_LINE(sensorValues[4]) && ON_LINE(sensorValues[5]) ))
		//	foundStraight = 1;

		////'+' Junction Stop the Motors
		//if (foundLeft && foundRight && foundStraight)
		//{
		//	path[pathCounter++] = 'J';
		//	path[pathCounter] = '\0';
		//	motorLeft.stop();
		//	motorRight.stop();
		//	DISABLE_STANDBY;
		//	BLUETOOTH.println(path[pathCounter - 1]);
		//	BLUETOOTH.println(path);
		//	while (1)
		//		BUZZER_ON;
		//}

		char direction = selectTurn(foundLeft, foundRight, foundStraight);
		turn(direction, SPEED_TURN, 200);

		/*motorLeft.stop();
		motorRight.stop();

		while (1);*/

		// left 90 Junction
		//if (foundStraight)
		//{
		//	// Left 90 Junction
		//	if (foundLeft && !foundRight)
		//	// T point Junction
		//	{
		//		path[pathCounter++] = 'C';
		//		BLUETOOTH.println(path[pathCounter - 1]);
		//	}
		//	// Right 90 Junction
		//	else if (foundRight && !foundLeft)
		//	{

		//		path[pathCounter++] = 'D';
		//		BLUETOOTH.println(path[pathCounter - 1]);
		//	}
		//}
		//else if (foundLeft && foundRight && !foundStraight)
		//{

		//	path[pathCounter++] = 'T';
		//	BLUETOOTH.println(path[pathCounter - 1]);
		//}

		//else if (foundLeft || foundRight)
		//{
		//	path[pathCounter++] = direction;
		//	BLUETOOTH.println(path[pathCounter - 1]);
		//}

	}
}

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


Battery Countdown Timer with Memory

Battery Countdown Timer with Memory

This code works on the basis of simply counting down from a fixed time and converting that into a battery percentage to be displayed on a 7 Segment Display. Includes ability to remember battery level via storage in EEPROM.

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


Fixes

Fixes

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/markwatneyy/ttt_arduino.git/'


passthrough sketch

passthrough sketch

error: pathspec 'unit' did not match any file(s) known to git
error: pathspec 'tests/wifi_test/BareMinimum/BareMinimum.ino/BareMinimum.ino.ino' did not match any file(s) known to git


class DripSensor
{
	// Class Member Variables
	// These are initialized at startup
	int sensorPin;      // the number of the sensor pin
	long DelayTime;

	// These maintain the current state
	int previousValue; // sensorData used to store the sensor data
        int currentValue; // sensorData used to store the sensor data
	unsigned long previousMillis;  // will store last time sensorData was updated
        int drip;
public:
               DripSensor(int pin, long frequency)
                 {
	          sensorPin = pin;
	          DelayTime = frequency;
	          previousValue = 0;
	          previousMillis = 0;
                  drip=1;
                 }
void Update()
             {
             // check to see if it's time to read the analog sensor
            unsigned long currentMillis = millis();

            if (previousMillis >= DelayTime)
                {
   	        currentValue = analogRead(sensorPin);    // read the input pin

                 if ((previousValue < 150) && (currentValue > 250))
                     {
                     Serial.print("drip count = ");
                     Serial.println(drip);
                     drip += 1;
                     }
                  previousValue = currentValue;
                  }
                previousMillis = currentMillis - previousMillis;  // Remember the time
             }

};

DripSensor dripSensor(3,5);

void setup()
{
   Serial.begin(9600);
}
void loop()
{
  long a;
  long b;
  a = millis();

	dripSensor.Update();
  b = millis();
  Serial.println(b-a);
  delay(200);
}

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


switch to consistent 80ms I2C powerup

switch to consistent 80ms I2C powerup

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


Syma servo sketch

Syma servo sketch

Woo!

/*******************************************************************
  SYMA X5C servo control
*******************************************************************

  Uses the camera port on the SYMA X5C to control a servo.
  When the picture or video buttons are pressed on the transmitter
  the signal wire (yellow) drops from 3.7v to 0v for 0.25s (picture)
  or 0.75s (video).

  Using those signals this sketch moves a servo from 0 degress to
  - 90 degrees to tilt a camera from horizontal (normal FPV flight)
  to looking down (for landing).

  Current config just toggles between 0 and -90 degrees using a single
  button push (picture button), leaving one button open (use tbd). Could
  be coded however so one button increments servo in one direction, and the
  other button increments it the other.

 *******************************************************************
  Board: Adafruit Trinket (3v)
  Notes:

  "Required library is the Adafruit_SoftServo library
  available at https://github.com/adafruit/Adafruit_SoftServo
  The standard Arduino IDE servo library will not work with 8 bit
  AVR microcontrollers like Trinket and Gemma due to differences
  in available timer hardware and programming. We simply refresh
  by piggy-backing on the timer0 millis() counter"

  Tutorial: https://learn.adafruit.com/trinket-gemma-servo-control/overview

 *******************************************************************

  Detecting the camera signal was adapted from a 'hold button'
  sketch at http://playground.arduino.cc/Code/HoldButton

  Other bits and pieces were found in the Arduino forums

 *******************************************************************/

#include <Adafruit_SoftServo.h>

#define SERVO1PIN 0   // Servo control line on Trinket Pin #7
int signal = 2; // The signal from the SYMA camera port
int LEDsignal = 1; // Blink

int current;         // Current state of the button
                     // (LOW is pressed b/c i'm using the pullup resistors)
long millis_held;    // Duration of signal (milliseconds)
long secs_held;      // Duration of signal (seconds)
long prev_secs_held; // Duration previously
byte previous = HIGH;
unsigned long firstTime; // how long since the signal was detected

Adafruit_SoftServo myServo1;
boolean toggle = true;

void setup()
{
  digitalWrite(signal, HIGH);
  pinMode(LEDsignal, OUTPUT);
  digitalWrite(LEDsignal, LOW);

 OCR0A = 0xAF;            // any number is OK
 TIMSK |= _BV(OCIE0A);    // Turn on the compare interrupt (below!)

  myServo1.attach(SERVO1PIN);   // Attach the servo to pin 0 on Trinket
  myServo1.write(165);          // Initial position (horizontal)
  delay(15);                   // Wait 15ms for the servo to reach the position
}

void loop() {
  current = digitalRead(signal);

  //--------------- Reading the camera signal ----------------
  //----------------------------------------------------------

  // if the state changes to low signal, remember the start time
  if (current == LOW && previous == HIGH && (millis() - firstTime) > 200) {
    firstTime = millis();
  }

  millis_held = (millis() - firstTime);
  secs_held = millis_held / 1000;

  //debouncing tool... the low signal must have a duration for at least 100 milliseconds to be considered
  if (millis_held > 100) {

    // check that the low signal returned to high since we last checked
    if (current == HIGH && previous == LOW) {

      //----------------- Controlling the Servo ------------------
      //----------------------------------------------------------

      // Low signal from Camera, 0.15 - 0.35s (picture button)
      if (millis_held > 150  && millis_held < 350) {

        //Move from 0 to -90 degrees (horizontal to straight down)
        if(toggle){
          myServo1.write(70);
          toggle = !toggle;
          digitalWrite(LEDsignal, HIGH);   // turn the LED on
          delay(500);                       // wait for half a second
          digitalWrite(LEDsignal, LOW);    // turn the LED off
        }
        //Move from 90 to 0 degrees (straight down to horizontal)
        else{
          myServo1.write(165);
          toggle = !toggle;
          digitalWrite(LEDsignal, HIGH);   // turn the LED on
          delay(500);                       // wait for half a second
          digitalWrite(LEDsignal, LOW);    // turn the LED off
        }
      } //0.25s end_if

     // Low signal from Camera is >0.5s (video button)
      if (millis_held > 500) {
        //whatever we want... haven't decided yet
      }//0.75s end_if

      //----------------------------------------------------------
      //----------------------------------------------------------

      }
  }

  previous = current;
  prev_secs_held = secs_held;
} //end loop

//----------------------------------------------------------
//----------------------------------------------------------

// We'll take advantage of the built in millis() timer that goes off
      // to keep track of time, and refresh the servo every 20 milliseconds
      // The SIGNAL(TIMER0_COMPA_vect) function is the interrupt that will be
      // Called by the microcontroller every 2 milliseconds

    volatile uint8_t counter = 0;
    SIGNAL(TIMER0_COMPA_vect) {
      // this gets called every 2 milliseconds
        counter += 2;
        // every 20 milliseconds, refresh the servos!
        if (counter >= 20) {
        counter = 0;
        myServo1.refresh();
            }
        }

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