text:
Compiling error at ATmega2560
I have a error.The error is showing as:
exit status 1
Error compiling for board Arduino Mega or Mega 2560.
The Code is:
#include <Wire.h>

#include <LCD.h>

#include <LiquidCrystal_I2C.h>

#include <SoftwareSerial.h>

LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);

SoftwareSerial BT(10,11); //Tx and Rx pins for BT communication const int temp_sensor = 0; //pin A0 (temperature sensor) const int fan = 22; //pin D2 (fan) float temp; //temperature value

int threshold = 21; //temperature threshold

const int LDRsensor = 1; //pin A1 (lighting sensor)

const int LED1 = 6; //pin D6 (LED 1)

const int LED2 = 7; //pin D7 (LED 2)

const int LED3 = 8; //pin D8 (LED 3)

const int LED4 = 9; //pin D9 (LED 4)

int LDRvalue; //natural light value

const int WL_sensor = 15; //pin A15 (water level sensor)

const int Wpump = 13; //pin D13 (water pump)

float water_level; //water level value

const int mov_sensor = 3; //pin D3 (movement sensor)

const int LEDalrm = 4; //pin D4 (alarm LED)

const int buzzer = 5; //pin D5 (buzzer)

int mov_value; //movement value (true or false)

char state; //data sent from App

char mode; //mode selected according to "state" value char order; //order to actuators according to "state" value
void setup() //this function is only executed one time

{

lcd.begin (16,2);

lcd.setBacklightPin(3,POSITIVE);

lcd.setBacklight(HIGH);

lcd.setCursor(0,0);

lcd.print("TFG");

lcd.setCursor(0,1);

lcd.print("Anna Merino");

delay(4000);

lcd.clear();

pinMode(temp_sensor, INPUT); //temperature sensor Mode

pinMode(fan, OUTPUT) ; //fan Mode

pinMode(LDRsensor, INPUT); //lighting sensor Mode

pinMode(LED1, OUTPUT); //LED1 Mode

pinMode(LED2, OUTPUT); //LED2 Mode

pinMode(LED3, OUTPUT); //LED3 Mode

pinMode(LED4, OUTPUT); //LED4 Mode

pinMode(WL_sensor, INPUT) ; //water level sensor Mode

pinMode(Wpump, OUTPUT); //water pump Mode

pinMode(mov_sensor, INPUT); //movement sensor Mode

pinMode(LEDalrm, OUTPUT); //alarm LED Mode

pinMode(buzzer, OUTPUT); //buzzer Mode

BT.begin(9600); //set data rate in bits per second (baud) for data transmission }
void loop() //function loop – continuously executed

{

if(BT.available()>0)

{

state = BT.read(); //transfer data sent by App to a local variable

}

if (state == 'Y')

{

mode = 'A';

}

else

if (state == 'Z')

{

mode = 'R';

}

else

if (state == 'X')

{

mode = 'D';

}

if (mode == 'A')

{

automaticmode(); //execute automatic function

}

else

if (mode == 'R')

{

remotemode(); //execute remote function

}

else

if (mode == 'D')

{

alarmmode(); //execute alarm function

}

}
void alarmmode() // alarm function

{

water_level = analogRead(WL_sensor); //data of water level sensor transmission to a local variable

if (digitalRead(mov_sensor)) //evaluate movement captured {

digitalWrite(LEDalrm, HIGH);

digitalWrite(buzzer, HIGH);

}

else

{

digitalWrite(LEDalrm, LOW);

digitalWrite(buzzer, LOW);

}

if (water_level > 100) //water level control

{

digitalWrite(Wpump, HIGH);

}

else

{

digitalWrite(Wpump, LOW);

}

}
void automaticmode() // automatic function

{

LDRvalue = analogRead(LDRsensor); //data of natural light transmission to a local variable water_level = analogRead(WL_sensor); //data of water level sensor transmission to a local variable

temp = analogRead(temp_sensor); //data of temperature sensor transmission to a local variable temp = temp*0.4883; //adjustment of temperature value digitalWrite(LEDalrm, LOW);

digitalWrite(buzzer, LOW);

lcd.setCursor(0,0);

lcd.print("Temperature");

lcd.setCursor(0,1);

lcd.print(temp); //LCD display – shows temperature value

lcd.setCursor(7,1);

lcd.print("ºC");

if (water_level > 100) //water level control

{

digitalWrite(Wpump, HIGH);

}

else

{

digitalWrite(Wpump, LOW);

}

if ((LDRvalue < 1023) & (LDRvalue >= 822)) //light control {

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

}

else if ((LDRvalue < 821)& (LDRvalue >= 617))

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);

}

else if ((LDRvalue < 616)& (LDRvalue >= 412))

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

}

else if ((LDRvalue < 411)& (LDRvalue >= 206))

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, LOW);

}

else if (LDRvalue < 205)

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, HIGH);

}

if (temp >= threshold) //temperature control

{

digitalWrite(fan, HIGH);

}

else if (temp < threshold)

{

digitalWrite(fan, LOW);

}

}

void remotemode() // remote function

{

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

digitalWrite(fan, LOW);

digitalWrite(Wpump, LOW);

digitalWrite(LEDalrm, LOW);

digitalWrite(buzzer, LOW);

if(BT.available()>0)

{

state = BT.read(); //transfer data sent by App to a local variable

}

if (state == 'D') //actuators operation according to orders received {

digitalWrite(LED1, LOW);

}

else

if (state == 'C')

{

digitalWrite(LED1, HIGH);

}

else

if (state == 'F')

{

digitalWrite(LED2, LOW);

}

else

if (state == 'E')

{

digitalWrite(LED2, HIGH);

}

else

if (state == 'H')
{

digitalWrite(LED3, LOW);

}

else

if (state == 'G')

{

digitalWrite(LED3, HIGH);

}

else

if (state == 'J')

{

digitalWrite(LED4, LOW);

}

else

if (state == 'I')

{

digitalWrite(LED4, HIGH);

}

else

if (state == 'L')

{

digitalWrite(fan, LOW);

}

else

if (state == 'K')

{

digitalWrite(fan, HIGH);

}

else

if (state == 'N')

{

digitalWrite(Wpump, LOW);

}

else

if (state == 'M')

{

digitalWrite(Wpump, HIGH);

}
if (state == 'O')

{

digitalWrite(LED1, HIGH);

digitalWrite(LED2, HIGH);

digitalWrite(LED3, HIGH);

digitalWrite(LED4, HIGH);

}

else

if (state == 'P')

{

digitalWrite(LED1, LOW);

digitalWrite(LED2, LOW);

digitalWrite(LED3, LOW);

digitalWrite(LED4, LOW);

}

}

what is the error? ... you only included a small part of the error message .... also, please format your code so that all of it is legible

If you run the auto-formatter in the IDE (Ctrl-T), your error should become obvious.

The main issue with your code is the formatting. It seems that you have managed to 'comment out' some of the necessary { or } for some of the functions and/or if/else blocks, hence the failure to compile.
e.g.
BT.begin(9600); //set data rate in bits per second (baud) for data transmission }

The } at the end of that particular line is the closing brace for the void setup() function... but because it's after the // for the comment, the compiler won't see it, so it is effectively missing.
This code should now compile on your system... once all the missing { and } were un-commented.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);
SoftwareSerial BT(10, 11); //Tx and Rx pins for BT communication const int temp_sensor = 0; //pin A0 (temperature sensor) const int fan = 22; //pin D2 (fan) float temp; //temperature value

int threshold = 21; //temperature threshold

const int LDRsensor = 1; //pin A1 (lighting sensor)
const int LED1 = 6; //pin D6 (LED 1)
const int LED2 = 7; //pin D7 (LED 2)
const int LED3 = 8; //pin D8 (LED 3)
const int LED4 = 9; //pin D9 (LED 4)
const int WL_sensor = 15; //pin A15 (water level sensor)
const int Wpump = 13; //pin D13 (water pump)
const int mov_sensor = 3; //pin D3 (movement sensor)
const int LEDalrm = 4; //pin D4 (alarm LED)
const int buzzer = 5; //pin D5 (buzzer)

int LDRvalue; //natural light value
float water_level; //water level value
int mov_value; //movement value (true or false)

char state; //data sent from App
char mode;   //mode selected according to "state" value char order; //order to actuators according to "state" value

void setup() //this function is only executed one time
{
    lcd.begin(16, 2);
    lcd.setBacklightPin(3, POSITIVE);
    lcd.setBacklight(HIGH);

    lcd.setCursor(0, 0);
    lcd.print("TFG");
    lcd.setCursor(0, 1);
    lcd.print("Anna Merino");

    delay(4000);

    lcd.clear();

    pinMode(temp_sensor, INPUT); //temperature sensor Mode
    pinMode(fan, OUTPUT); //fan Mode
    pinMode(LDRsensor, INPUT); //lighting sensor Mode
    pinMode(LED1, OUTPUT); //LED1 Mode
    pinMode(LED2, OUTPUT); //LED2 Mode
    pinMode(LED3, OUTPUT); //LED3 Mode
    pinMode(LED4, OUTPUT); //LED4 Mode
    pinMode(WL_sensor, INPUT); //water level sensor Mode
    pinMode(Wpump, OUTPUT); //water pump Mode
    pinMode(mov_sensor, INPUT); //movement sensor Mode
    pinMode(LEDalrm, OUTPUT); //alarm LED Mode
    pinMode(buzzer, OUTPUT); //buzzer Mode

    BT.begin(9600); //set data rate in bits per second (baud) for data transmission
}

void loop() //function loop – continuously executed
{
    if (BT.available() > 0)
    {
        state = BT.read(); //transfer data sent by App to a local variable
    }

    if (state == 'Y')
    {
        mode = 'A';
    }
    else if (state == 'Z')
    {
        mode = 'R';
    }
    else if (state == 'X')
    {
        mode = 'D';
    }

    if (mode == 'A')
    {
        automaticmode(); //execute automatic function
    }
    else if (mode == 'R')
    {
        remotemode(); //execute remote function
    }
    else if (mode == 'D')
    {
        alarmmode(); //execute alarm function
    }
}

void alarmmode() // alarm function
{
    water_level = analogRead(WL_sensor); //data of water level sensor transmission to a local variable

    if (digitalRead(mov_sensor)) //evaluate movement captured
    {
        digitalWrite(LEDalrm, HIGH);
        digitalWrite(buzzer, HIGH);
    }
    else
    {
        digitalWrite(LEDalrm, LOW);
        digitalWrite(buzzer, LOW);
    }
    if (water_level > 100) //water level control
    {
        digitalWrite(Wpump, HIGH);
    }
    else
    {
        digitalWrite(Wpump, LOW);
    }
}

void automaticmode() // automatic function
{
    LDRvalue = analogRead(LDRsensor); //data of natural light transmission to a local variable water_level = analogRead(WL_sensor); //data of water level sensor transmission to a local variable
    temp = analogRead(temp_sensor); //data of temperature sensor transmission to a local variable temp = temp*0.4883; //adjustment of temperature value digitalWrite(LEDalrm, LOW);

    digitalWrite(buzzer, LOW);

    lcd.setCursor(0, 0);
    lcd.print("Temperature");

    lcd.setCursor(0, 1);
    lcd.print(temp); //LCD display – shows temperature value

    lcd.setCursor(7, 1);
    lcd.print("ºC");

    if (water_level > 100) //water level control
    {
        digitalWrite(Wpump, HIGH);
    }
    else
    {
        digitalWrite(Wpump, LOW);
    }

    if ((LDRvalue < 1023) & (LDRvalue >= 822)) //light control
    {
        digitalWrite(LED1, LOW);
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, LOW);
        digitalWrite(LED4, LOW);
    }
    else if ((LDRvalue < 821) & (LDRvalue >= 617))
    {
        digitalWrite(LED1, HIGH);
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, LOW);
        digitalWrite(LED4, LOW);
    }
    else if ((LDRvalue < 616) & (LDRvalue >= 412))
    {
        digitalWrite(LED1, HIGH);
        digitalWrite(LED2, HIGH);
        digitalWrite(LED3, LOW);
        digitalWrite(LED4, LOW);
    }
    else if ((LDRvalue < 411) & (LDRvalue >= 206))
    {
        digitalWrite(LED1, HIGH);
        digitalWrite(LED2, HIGH);
        digitalWrite(LED3, HIGH);
        digitalWrite(LED4, LOW);
    }
    else if (LDRvalue < 205)
    {
        digitalWrite(LED1, HIGH);
        digitalWrite(LED2, HIGH);
        digitalWrite(LED3, HIGH);
        digitalWrite(LED4, HIGH);
    }

    if (temp >= threshold) //temperature control
    {
        digitalWrite(fan, HIGH);
    }
    else if (temp < threshold)
    {
        digitalWrite(fan, LOW);
    }
}

void remotemode() // remote function
{
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
    digitalWrite(LED3, LOW);
    digitalWrite(LED4, LOW);

    digitalWrite(fan, LOW);
    digitalWrite(Wpump, LOW);
    digitalWrite(LEDalrm, LOW);
    digitalWrite(buzzer, LOW);

    if (BT.available() > 0)
    {
        state = BT.read(); //transfer data sent by App to a local variable
    }

    if (state == 'D') //actuators operation according to orders received
    {
        digitalWrite(LED1, LOW);
    }
    else if (state == 'C')
    {
        digitalWrite(LED1, HIGH);
    }
    else if (state == 'F')
    {
        digitalWrite(LED2, LOW);
    }
    else if (state == 'E')
    {
        digitalWrite(LED2, HIGH);
    }
    else if (state == 'H')
    {
        digitalWrite(LED3, LOW);
    }
    else if (state == 'G')
    {
        digitalWrite(LED3, HIGH);
    }
    else if (state == 'J')
    {
        digitalWrite(LED4, LOW);
    }
    else if (state == 'I')
    {
        digitalWrite(LED4, HIGH);
    }
    else if (state == 'L')
    {
        digitalWrite(fan, LOW);
    }
    else if (state == 'K')
    {
        digitalWrite(fan, HIGH);
    }
    else if (state == 'N')
    {
        digitalWrite(Wpump, LOW);
    }
    else if (state == 'M')
    {
        digitalWrite(Wpump, HIGH);
    }

    if (state == 'O')
    {
        digitalWrite(LED1, HIGH);
        digitalWrite(LED2, HIGH);
        digitalWrite(LED3, HIGH);
        digitalWrite(LED4, HIGH);
    }
    else if (state == 'P')
    {
        digitalWrite(LED1, LOW);
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, LOW);
        digitalWrite(LED4, LOW);
    }
}

In future, when posting a question, please also list WHICH libraries you are using. e.g. there is more than one LiquidCrystal_I2C library... and probably only one right one. Also, that will only be part of the error message. Give the entire message - as the end bit isn't of much use!


text:
Sending Strings from NRF24L01 to app
I want to send pushbutton status from the nrf24l01 module to the app named nrfConnect. I could only find libraries that allow me to send float values. How could I send String values to the app? Thank You!

nRF Connect is for Bluetooth LE devices, the nRF24L01+ is really not a Bluetooth Low Energy transceiver.
The best the nRF24L01+ can do is make a few Bluetooth LE advertisements but that's very finicky. Here's a long description how: https://dmitry.gr/index.php?r=05.Projects&proj=15&proj=11.%20Bluetooth%20LE%20fakery

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
What is "tws_delay" and how can I use it? (with an ATTiny85)
EDIT: Alright I'm stupid, I had the 2012 library installed somehow, maybe when I downloaded it indirectly from another old tutorial site. Thanks a ton to Peter Freerick for pointing that out! It finally compiled now
So I'm currently doing a little project where I have an ATTiny85 controlling some (neopixel) RGB addressable LEDs, which is controlled over i2c from an Arduino UNO Master. The goal is to make an Attiny85 into an i2c slave that receives a simple command (such as a single digit int) and decide which premade LED display program to use.
I'm using ATTinyCore, TinyWireS, and Adafruit's tinyNeopixel library for the tiny, and programming it using an Arduino UNO as ISP.
My issue is this: The led code requires a delay to change the speed of the light show. But I see in the TinyWireS example here that I should be using tws_delay instead of the normal delay.
Various googling attempts have left me nowhere to learn how to use tws_delay, what it is, or how to even declare it. I get a declaration error when I try to use the delay with the TinyWireS library included.
I would like to find a resource for learning how to declare and use this delay. Thank you for reading this far
EDIT: I have now added my code and error below, you can find the tws_delay in void loop near the bottom
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#if (F_CPU>7370000) //neopixel library required 7.37MHz minimum clock speed; this line is used to skip this sketch in internal testing. It is not needed in your sketches.
#include <tinyNeoPixel.h>
#include <TinyWireS.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            3

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      8

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

int delayval = 500; // delay for half a second

void setup() {

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

  for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    tws_delay(delayval); // Delay for a period of time (in milliseconds).

  }
}
#else //neopixel library required 7.37MHz minimum clock speed; these and following lines are used to skip this sketch in internal testing. It is not needed in your sketches.
#warning "Neopixel control requires F_CPU > 7.37MHz"
void setup() {}
void loop() {}
#endif

And the error:
C:\Users\Dean\AppData\Local\Temp\arduino_modified_sketch_145294\simple.ino: In function 'void loop()':

simple:36:5: error: 'tws_delay' was not declared in this scope

     tws_delay(delayval); // Delay for a period of time (in milliseconds).

     ^~~~~~~~~

C:\Users\Dean\AppData\Local\Temp\arduino_modified_sketch_145294\simple.ino:36:5: note: suggested alternative: 'delay'

     tws_delay(delayval); // Delay for a period of time (in milliseconds).

     ^~~~~~~~~

     delay

Multiple libraries were found for "tinyNeoPixel.h"
 Used: C:\Users\Dean\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.2\libraries\tinyNeoPixel
Multiple libraries were found for "TinyWireS.h"
 Used: C:\Users\Dean\Documents\Arduino\libraries\TinyWireS
exit status 1
'tws_delay' was not declared in this scope

Can you please show your code and the full error message, that you get? When including the library, you should be able to use the tws_delay() function, just as it is used in this example from the library

Alright I have added the code and error message, just to note I tried putting tws_delay(50) as well and still got the same error

The "EDIT: Alright I'm" suggests someone answered your question.  If so, you should mark their answer accepted.  At a minimum you found it helpful, vote it up.  If you found the answer to your own question, post your own answer and mark that accepted.

Answer: Make sure you install the right library :P

It would make more sense to bring your answer-material out of the question and down here into your "answer" to make it a proper answer.

Sorry I'm not sure how to do that at all. Is there some button I'm not seeing?

You have edit links under both your question and answer, so can effectively cut and paste between them.  It's also possible to mark your own answer as accepted, so that there is an accept answer to the question.

tws_delay() is a function provided by the TinyWireS library here. As you can see from the declaration - void tws_delay(unsigned long); - it accepts a parameter of unsigned long, just like delay() does.
In fact, the comment on the line above that declaration says...
// Implement a delay loop that checks for the stop bit (basically direct copy of the stock arduino implementation from wiring.c)
... so, it's safe to say that wherever you would have used delay(), you can use tws_delay().
So there should be no need to declare or define it. But to simply use it. If using tws_delay() in code that includes TinyWireS.h doesn't work, I would be checking that you have a version of the library that declares/defines it. Which you should, given the example you linked, as that repo has had the function since 2012!

Thanks for the reply! So I've added my code and error to the original post. It seems I still get the error even though the library should have declared it right? Also yes I have the newest version of the library installed. I will go double check now just in case. Edit: Oh crap I actually somehow have the code from 2012!! That must be the issue! I'm going to install the new library right now and try that.

Okay sorry to be a pest but I have now solved the issue thanks to you but immediately came across another slight issue, the timing for the delays seems to be way off. For example if I put 1000 in the parenthesis it blinks for a fraction of a second. I wanted to ask you since you seemed to know how it works but I'll open another full question post for this if needed.

Sorry, can't help you with that one off the top of my head... the twi_delay function looks like it should operate properly... if the clock speed of your device is set properly. It should basically put in a 'blocking' 500ms delay (blocking as far as nothing else except TinyWireS_stop_check can repeatedly run, but no longer does anything, as the comment above the implementation suggests TinyWireS became interrupt driven). I bet that is the actual issue, and that tinyNeopixel  uses the interrupt TinyWireS wants to use.

Okay that actually makes sense, I'll look into it, thanks!

Voting your answer up because they didn't despite clearly finding it helpful.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
I am making my blinds automatic, but I don't want to use a delay
I am trying to make it so I can pull the time so that they open at 8 am and close at 10 pm. The loop is already set up to open and close the blinds completely.
#include <CheapStepper.h>

CheapStepper stepper;

boolean moveClockwise = true;
int motorPostion = 10;
boolean up = true;
boolean down = false;

void setup() {
  Serial.begin (9600);
  Serial.println ("Ready to start moving");
}

void loop() {

    for (int i = 1; i < 16384; i++)
      {
      stepper.step (moveClockwise);
      Serial.println (i);
      int nStep = stepper.getStep();

      if (nStep%4096==0) {
        Serial.println ("Moved full rotation Clockwise");
        }
     }

    for (int i = 16384; i > 0; i--)
      {
      stepper.step (!moveClockwise);
      Serial.println (i);
      int nStep = stepper.getStep();

      if (nStep%4096==0) {
        Serial.println ("Moved full rotation Counter Clockwise");
      }
    }
  }

what is your question? ... please format all of your code, not just a part of your code.

So, are you asking about how to write non-blocking code (Then look at the BlinkWithoutDelay example and tutorials about the millis() function), or are you asking about how to do things at a specific time of the day (In that case you need an RTC)?


text:
How do I make my LCD screen scroll text while allowing for button input?
Here's what I want my code to do: This is part of a tea infusing project that would automate the steeping of tea, part of this is initially having a selection of either Black/Herbal tea or White/Green tea, this will then set off several other factors down the timeline.
I want my LCD screen to display and scroll "Please select a tea" while still being able to take in pushbutton input.
I've been doing this all day, and I've tried several things. I firstly tried using a normal delay function so my text could scroll properly, but the problem with that is that it halts all the code and doesn't allow for any other input, so I quickly found millis() was likely what I needed to use. However, when I try to apply it to this specific example, it just scrolls all my text extremely quickly through the LCD.
Perhaps I'm being stupid and ignoring something obvious, but please let me know.

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

const int black_herbal_osb = 2;

int black_select;

//Timing
unsigned long prev_millis;
unsigned long current_millis;
const unsigned long LCD_delay = 500;

void setup() {

  //Tea selection buttons
  pinMode(black_herbal_osb, INPUT);

  //LCD screen setup
  lcd.init();
  lcd.backlight();

}

void loop() {

  lcd.autoscroll();
  lcd.setCursor(16, 0);
  lcd.print("Please");

  current_millis = millis();

  black_select = digitalRead(black_herbal_osb);

  if (black_select != HIGH) {

    if (current_millis - prev_millis >= LCD_delay) {
      lcd.print(" select ");
      prev_millis = current_millis;
    }
    if (current_millis - prev_millis >= LCD_delay * 2) {
      lcd.print("a ");
      prev_millis = current_millis;
    }
    if (current_millis - prev_millis >= LCD_delay * 3) {
      lcd.print("tea ");
      prev_millis = current_millis;
    }
  }

  else if (black_select == HIGH) {
    lcd.clear();
    lcd.autoscroll();
    lcd.setCursor(16, 0);
    lcd.print("Black/Herbal ");
    delay(500);
    lcd.print("tea ");
    delay(500);
    lcd.print("selected");
    delay(2000);
    lcd.noAutoscroll();
    lcd.clear();
  }

}

why don't you solve the scrolling problem before adding button code

That's what I did, I just added the button code for illustration reasons, with or without the button code the scrolling is still an issue

I figured it out. I was thinking about it all wrong, I just needed to figure out how the scrolling worked for the LCD and the rest was much easier. Only current issue with my code is that on the initial scroll of "Please select a tea" right after the "Booting..." process, it doesn't seem to start at (16,0) but nearer to the front which makes it not super easy to read initially but it corrects itself after a single scroll.
Here's the code for those interested:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

const int black_herbal_pin = 2;
const int white_green_pin = 3;
const int LCD_scroll = 200;

int black_select;
int white_select;

unsigned long current_millis = 0;    // stores the value of millis() in each iteration of loop()
unsigned long previous_scroll_millis = 0;

void setup() {
  Serial.begin(9600);
  //Tea selection buttons
  pinMode(black_herbal_pin, INPUT);
  pinMode(white_green_pin, INPUT);

  //LCD screen setup
  lcd.init();
  lcd.backlight();

}

void loop() {

  if (current_millis == 0) {
    lcd.setCursor (0, 0);
    lcd.print("Booting");
    delay(500);
    lcd.print(".");
    delay(500);
    lcd.print(".");
    delay(500);
    lcd.print(".");
    delay(1000);
    lcd.clear();
  }

  lcd.setCursor(16, 0);
  lcd.print("Please select a tea ");

  current_millis = millis();
  for (int position_counter = 0; position_counter < 16; position_counter++) {

    if (current_millis - previous_scroll_millis >= LCD_scroll) {
      lcd.scrollDisplayLeft();

      previous_scroll_millis += LCD_scroll;
    }
  }

  if (digitalRead(black_herbal_pin) == HIGH) {
    lcd.clear();
    lcd.setCursor (16, 0);
    lcd.print("Black/Herbal tea selecte");
    for (int position_counter = 0; position_counter < 26; position_counter++) {
      lcd.setCursor (0, 0); //This part is likely not necessary for you as it seems to be a bug within my own LCD
      lcd.print("d"); // without this it prints "d" on the second row
      lcd.scrollDisplayLeft();
      delay (150);
    }

    delay(2000);
    lcd.clear();
  }

  if (digitalRead(white_green_pin) == HIGH) {
    lcd.clear();
    lcd.setCursor (16, 0);
    lcd.print("White/Green tea selected");
    for (int position_counter = 0; position_counter < 26; position_counter++) {
      lcd.scrollDisplayLeft();
      delay (150);
    }

    delay(2000);
    lcd.clear();
  }

}

You could make the "Please select a tea" code a function instead. So `void selection() { lcd.setCursor(16, 0);
lcd.print("Please select a tea ");
current_millis = millis();
for (int position_counter = 0; position_counter < 16; position_counter++) {
if (current_millis - previous_scroll_millis >= LCD_scroll) {
  lcd.scrollDisplayLeft();

  previous_scroll_millis += LCD_scroll;
}

}
} and then addselection();` where the code used to be in the loop for a state machine look lmao

See my answer to a similar question - about motors but the idea is the same. You call a function for each piece of the job that needs to be done. The function itself decides whether it needs to be done yet, and if so, does it and returns, otherwise it just returns. The loop() function just calls all your other action functions and does nothing else -- all of the real work takes place in those functions.
Looking at your scrolling code, I think one function could print successive pieces of the message by remembering what did last. Another could read and debounce the button(s) and save its/their state.
And once you get to controlling the infusing process, one (or maybe more) functions could be used to control that.


text:
Integrating blinking light code and time on/off code
I'm trying to integrate code from one of my projects with another. One is code that blinks some Adafruit Neopixel LED strips at a specific rate and the other is a time on/off circuit here is the code for both of these projects, respectively:
NeoPixel LEDs

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

#define PIN        6
#define NUMPIXELS 7

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void NeoBlink(int num, int wait)
{
for (int i = 0; i < num; i++)
{
pixels.setPixelColor(i, 0, 0, 0);
}
pixels.show();
delay(8000);
for (int j = 0; j < num; j++)
{
pixels.setPixelColor(j, 255, 255, 255);
}
pixels.show();
delay(3);
}

void setup()
{
pixels.begin();
pixels.setBrightness(255);
}

void loop()
{
NeoBlink(7, 500);
}

AND

#include <EEPROM.h>
#include <RTClib.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>

hd44780_I2Cexp lcd;//0x3F is my lcd address, maybe not yours!
RTC_DS3231 RTC;

#define HD44780_LCDOBJECT

//-----------------------//
//------Variables--------//
//-----------------------//

//------First Timer
byte onhour1;
byte onmin1;
byte onsec1;

byte offhour1;
byte offmin1;
byte offsec1;
//------Pages or menus
int page_counter=1;
int subpage1_counter=0;
int subpage2_counter=0;

//-------To convert clock into single number
unsigned long Time;
unsigned long Hour;
unsigned long Min;
unsigned long Sec;
//------To convert first timer into Single number
unsigned long on_Time1;
unsigned long on_hour1;
unsigned long on_min1;
unsigned long on_sec1;

unsigned long off_Time1;
unsigned long off_hour1;
unsigned long off_min1;
unsigned long off_sec1;

//-------Push buttons current/last state
boolean current_up = LOW;
boolean last_up=LOW;
boolean current_sel = LOW;
boolean last_sel = LOW;
boolean last_down = LOW;
boolean current_down = LOW;
//-------Pins
int up=2;      //Up button to pin 2
int sel=3;     //Select button to pin 3
int down=4;   //Down button to pin 4

//Custom return char
byte back[8] = {
  0b00100,
  0b01000,
  0b11111,
  0b01001,
  0b00101,
  0b00001,
  0b00001,
  0b11111
};

//Custom arrow char
byte arrow[8] = {
  0b01000,
  0b00100,
  0b00010,
  0b11111,
  0b00010,
  0b00100,
  0b01000,
  0b00000
};

void setup() {
  pinMode(6, OUTPUT);

     Wire.begin();
     RTC.begin();
     lcd.init();
     lcd.backlight();
     lcd.clear();
  lcd.createChar(1, back);//Custom chars
  lcd.createChar(2, arrow);
//--------eePROM  read values-------//
//------First Timer
onhour1=EEPROM.read(0);
onmin1=EEPROM.read(1);
onsec1=EEPROM.read(2);

offhour1=EEPROM.read(3);
offmin1=EEPROM.read(4);
offsec1=EEPROM.read(5);

}

   //---- De-bouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(10);
current = digitalRead(pin);
}
return current;
}

void loop() {

current_up = debounce(last_up, up);         //Debounce for Up button
current_sel = debounce(last_sel, sel);      //Debounce for Select  button
current_down = debounce(last_down, down);   //Debounce for Down button

DateTime now = RTC.now();        // Clock call
now = RTC.now();

//-----Up/Down functions to move main pages------///

if(subpage1_counter==0 && subpage2_counter==0){ //up/down buttons enabled if subpages counters are 0,Disabled if 1,2..etc to work on submenus

//Page Up
    if (last_up== LOW && current_up == HIGH){ //Up button pressed
      lcd.clear();                            //Clear lcd if page is changed to print new one
      if(page_counter <3){                   //Page counter never higher than 3(total of pages)
      page_counter ++;                       //Page up
      }
      else{
      page_counter= 1;                       //If higher than 3 (last page)go to main page
      }

}
last_up = current_up;                   //Save up button last state

//Page Down
    if (last_down== LOW && current_down == HIGH){//Down button pressed
      lcd.clear();                               //Clear lcd if page is changed to print new one
      if(page_counter >1){                      //Page counter never lower than 1
      page_counter --;                          //Page down

      }
      else{
      page_counter= 3;                 //If lower than 1(first page)go to last page
      }
  }
    last_down = current_down;         //Save down button last state
}
//------------Pages and submenus display and control----------//
  switch (page_counter){
    case 1:                      //Content of main page
     last_sel=current_sel;  //Save last state of select button when we jump from the save screen
      lcd.setCursor(0,0);
      lcd.print("ULTRA MEGA TIMER");
      lcd.setCursor(0,1);
      lcd.print("TIME");

//--------Show  Time On LCD

lcd.setCursor(7,1);
if(now.hour() < 10)
{
lcd.print("0");
}
lcd.print(now.hour(), DEC); //Print hour
lcd.print(':');
if(now.minute() < 10)
{
lcd.print("0");
}
lcd.print(now.minute(), DEC); //Print min
lcd.print(':');
if(now.second() < 10)
{
lcd.print("0");
}
lcd.print(now.second(), DEC); //Print sec
    //case 1
    break;

    case 2:                   //Content and functions of page 2
      lcd.setCursor(0,0);
      lcd.print("T1");
      lcd.setCursor(3,0);
      lcd.print("ON");
      lcd.setCursor(1,1);
      lcd.write(byte(1));
      lcd.setCursor(3,1);
      lcd.print("OFF");

            lcd.setCursor(7,0);    //Printing on/off values
            if(onhour1<10){
              lcd.print("0");
            }
            lcd.print(onhour1);
            lcd.setCursor(10,0);
            if(onmin1<10){
              lcd.print("0");
            }
            lcd.print(onmin1);
            lcd.setCursor(13,0);
            if(onsec1<10){
              lcd.print("0");
            }
            lcd.print(onsec1);
            lcd.setCursor(7,1);
            if(offhour1<10){
              lcd.print("0");
            }
            lcd.print(offhour1);
            lcd.setCursor(10,1);
            if(offmin1<10){
              lcd.print("0");
            }
            lcd.print(offmin1);
            lcd.setCursor(13,1);
            if(offsec1<10){
              lcd.print("0");
            }
            lcd.print(offsec1);

//--------------Modifying on/off values-------//
     // Sub counter control
     if (last_sel== LOW && current_sel == HIGH){ //select button pressed
      if(subpage1_counter <7){                    // subpage counter never higher than 7 (total of items)
     subpage1_counter ++;                         //subcounter to move beetwen submenu
     }
     else{                                       //If subpage higher than 7 (total of items) return to first item
      subpage1_counter=1;
     }
     }
     last_sel=current_sel;                      //Save last state of select button

     //First item control(subpage_counter =1) onhour1
     if(subpage1_counter==1){
     lcd.setCursor(0,1);         //Delete last arrow position (back)
     lcd.print(" ");
     lcd.setCursor(6,0);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      if(onhour1 < 23){
     onhour1 ++;
      }
      else{
     onhour1 =0;
      }
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
     if(onhour1 >0){
      onhour1 --;
     }
     else{
      onhour1=23;
     }
     }
     last_down=current_down;
    }//subpage1_counter 1

     //Second item control(subpage_counter =2) onmin1
     if(subpage1_counter==2){
     lcd.setCursor(6,0);         //Delete last arrow position (onhour1)
     lcd.print(" ");
     lcd.setCursor(9,0);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      if(onmin1 < 59){
     onmin1 ++;
      }
      else{
     onmin1 =0;
      }
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
     if(onmin1 >0){
      onmin1 --;
     }
     else{
      onmin1=59;
     }
     }
     last_down=current_down;
    }//subpage1_counter 2

     //Thirth item control(subpage_counter =3) onsec1
     if(subpage1_counter==3){
     lcd.setCursor(9,0);         //Delete last arrow position (onmin1)
     lcd.print(" ");
     lcd.setCursor(12,0);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      if(onsec1 < 59){
     onsec1 ++;
      }
      else{
     onsec1 =0;
      }
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
     if(onsec1 >0){
      onsec1 --;
     }
     else{
      onsec1=59;
     }
     }
     last_down=current_down;
    }//subpage1_counter 3

     //fourth item control(subpage_counter =4) offhour1
     if(subpage1_counter==4){
     lcd.setCursor(12,0);         //Delete last arrow position (onsec1)
     lcd.print(" ");
     lcd.setCursor(6,1);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      if(offhour1 < 23){
     offhour1 ++;
      }
      else{
     offhour1 =0;
      }
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
     if(offhour1 >0){
      offhour1 --;
     }
     else{
      offhour1=23;
     }
     }
     last_down=current_down;
    }//subpage1_counter 4

     //fifth item control(subpage_counter =5) offmin1
     if(subpage1_counter==5){
     lcd.setCursor(6,1);         //Delete last arrow position (offhour1)
     lcd.print(" ");
     lcd.setCursor(9,1);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      if(offmin1 < 59){
     offmin1 ++;
      }
      else{
     offmin1 =0;
      }
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
     if(offmin1 >0){
      offmin1 --;
     }
     else{
      offmin1=59;
     }
     }
     last_down=current_down;
    }//subpage1_counter 5

     //sixth item control(subpage_counter =6) offsec1
     if(subpage1_counter==6){
     lcd.setCursor(9,1);         //Delete last arrow position (offmin1)
     lcd.print(" ");
     lcd.setCursor(12,1);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      if(offsec1 < 59){
     offsec1 ++;
      }
      else{
     offsec1 =0;
      }
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
     if(offsec1 >0){
      offsec1 --;
     }
     else{
      offsec1=59;
     }
     }
     last_down=current_down;
    }//subpage1_counter 6

     //seventh item control(subpage_counter =7) back
     if(subpage1_counter==7){
     lcd.setCursor(12,1);         //Delete last arrow position (offsec1)
     lcd.print(" ");
     lcd.setCursor(0,1);          //Place arrow in front of selected item
     lcd.write(byte(2));
     //Move item + or -
     if (last_up== LOW && current_up == HIGH){  //Up
      lcd.setCursor(0,1);         //Delete last arrow position (back) to exit
      lcd.print(" ");
     subpage1_counter=0;         //Exit submenu. Up/down butons enabled to move main pages
     }
     last_up=current_up;

     if(last_down== LOW && current_down == HIGH){//Down
      lcd.setCursor(0,1);         //Delete last arrow position (back)
      lcd.print(" ");
     subpage1_counter=1;         //Go to first item (onhour1)
     }
     last_down=current_down;
    }//subpage1_counter 7
    //case 2
    break;

    case 3:                //Page 3 display and functions
      lcd.setCursor(4,0);
      lcd.print("PRESS SEL");
      lcd.setCursor(5,1);
      lcd.print("TO SAVE");
     if (last_sel== LOW && current_sel == HIGH){  //select button pressed.Save settings to eeprom
  EEPROM.write(0, onhour1);
  EEPROM.write(1, onmin1);
  EEPROM.write(2, onsec1);
  EEPROM.write(3, offhour1);
  EEPROM.write(4, offmin1);
  EEPROM.write(5, offsec1);
  lcd.clear();                 //Print message "SAVED!"
  lcd.setCursor(5,1);
  lcd.print("SAVED!");
  delay(2000);
  lcd.clear();               //Clear lcd and go to main page
  page_counter=1;
     }
     last_sel=current_sel;  //Save last state of select button

    //Case 3
    break;
  }//switch

//-------------Conversion----------//

//---------Converting clock time into single number

Hour = now.hour();
Min = now.minute();
Sec = now.second();
Time = (Hour*10000+ Min*100 +Sec*1);

//--------Converting firt timer on/off into single number
on_hour1=onhour1;
on_min1=onmin1;
on_sec1=onsec1;
on_Time1=(on_hour1*10000 + on_min1*100 + on_sec1);

off_hour1=offhour1;
off_min1=offmin1;
off_sec1=offsec1;
off_Time1=(off_hour1*10000 + off_min1*100 + off_sec1);

//----Relay Function----//
if(onhour1 == offhour1 && onmin1==offmin1 && onsec1==offsec1){
   digitalWrite(Relay, LOW);
}

if(on_Time1 < off_Time1){

             if(Time >= on_Time1 && Time < off_Time1){  //Start
             digitalWrite(Relay, HIGH);
             }
             else if(Time >= off_Time1) {
             digitalWrite(Relay, LOW);
             }
             else{
             digitalWrite(Relay, LOW);
             }
}
if (on_Time1 > off_Time1){

            if(Time >= on_Time1 && Time <= 235959){     //Start
            digitalWrite(Relay, HIGH);
            }
            else if(Time < off_Time1 ){
            digitalWrite(Relay, HIGH);
            }
            else if(Time >= off_Time1 && Time < on_Time1){
            digitalWrite(Relay, LOW);
            }
}

}//void loop

And this is my attempt at integration:

void loop() {

  current_up = debounce(last_up, up);         //Debounce for Up button
  current_sel = debounce(last_sel, sel);      //Debounce for Select  button
  current_down = debounce(last_down, down);   //Debounce for Down button

  DateTime now = RTC.now();        // Clock call
  now = RTC.now();

  //-----Up/Down functions to move main pages------///

  if (subpage1_counter == 0 && subpage2_counter == 0) { //up/down buttons enabled if subpages counters are 0,Disabled if 1,2..etc to work on submenus

    //Page Up
    if (last_up == LOW && current_up == HIGH) { //Up button pressed
      lcd.clear();                            //Clear lcd if page is changed to print new one
      if (page_counter < 3) {                //Page counter never higher than 3(total of pages)
        page_counter ++;                       //Page up
      }
      else {
        page_counter = 1;                      //If higher than 3 (last page)go to main page
      }

    }
    last_up = current_up;                   //Save up button last state

    //Page Down
    if (last_down == LOW && current_down == HIGH) { //Down button pressed
      lcd.clear();                               //Clear lcd if page is changed to print new one
      if (page_counter > 1) {                   //Page counter never lower than 1
        page_counter --;                          //Page down

      }
      else {
        page_counter = 3;                //If lower than 1(first page)go to last page
      }
    }
    last_down = current_down;         //Save down button last state
  }
  //------------Pages and submenus display and control----------//
  switch (page_counter) {
    case 1:                      //Content of main page
      last_sel = current_sel; //Save last state of select button when we jump from the save screen
      lcd.setCursor(0, 0);
      lcd.print("ULTRA MEGA TIMER");
      lcd.setCursor(0, 1);
      lcd.print("TIME");

      //--------Show  Time On LCD

      lcd.setCursor(7, 1);
      if (now.hour() < 10)
      {
        lcd.print("0");
      }
      lcd.print(now.hour(), DEC); //Print hour
      lcd.print(':');
      if (now.minute() < 10)
      {
        lcd.print("0");
      }
      lcd.print(now.minute(), DEC); //Print min
      lcd.print(':');
      if (now.second() < 10)
      {
        lcd.print("0");
      }
      lcd.print(now.second(), DEC); //Print sec
      //case 1
      break;

    case 2:                   //Content and functions of page 2
      lcd.setCursor(0, 0);
      lcd.print("T1");
      lcd.setCursor(3, 0);
      lcd.print("ON");
      lcd.setCursor(1, 1);
      lcd.write(byte(1));
      lcd.setCursor(3, 1);
      lcd.print("OFF");

      lcd.setCursor(7, 0);   //Printing on/off values
      if (onhour1 < 10) {
        lcd.print("0");
      }
      lcd.print(onhour1);
      lcd.setCursor(10, 0);
      if (onmin1 < 10) {
        lcd.print("0");
      }
      lcd.print(onmin1);
      lcd.setCursor(13, 0);
      if (onsec1 < 10) {
        lcd.print("0");
      }
      lcd.print(onsec1);
      lcd.setCursor(7, 1);
      if (offhour1 < 10) {
        lcd.print("0");
      }
      lcd.print(offhour1);
      lcd.setCursor(10, 1);
      if (offmin1 < 10) {
        lcd.print("0");
      }
      lcd.print(offmin1);
      lcd.setCursor(13, 1);
      if (offsec1 < 10) {
        lcd.print("0");
      }
      lcd.print(offsec1);

      //--------------Modifying on/off values-------//
      // Sub counter control
      if (last_sel == LOW && current_sel == HIGH) { //select button pressed
        if (subpage1_counter < 7) {                 // subpage counter never higher than 7 (total of items)
          subpage1_counter ++;                         //subcounter to move beetwen submenu
        }
        else {                                      //If subpage higher than 7 (total of items) return to first item
          subpage1_counter = 1;
        }
      }
      last_sel = current_sel;                    //Save last state of select button

      //First item control(subpage_counter =1) onhour1
      if (subpage1_counter == 1) {
        lcd.setCursor(0, 1);        //Delete last arrow position (back)
        lcd.print(" ");
        lcd.setCursor(6, 0);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          if (onhour1 < 23) {
            onhour1 ++;
          }
          else {
            onhour1 = 0;
          }
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          if (onhour1 > 0) {
            onhour1 --;
          }
          else {
            onhour1 = 23;
          }
        }
        last_down = current_down;
      }//subpage1_counter 1

      //Second item control(subpage_counter =2) onmin1
      if (subpage1_counter == 2) {
        lcd.setCursor(6, 0);        //Delete last arrow position (onhour1)
        lcd.print(" ");
        lcd.setCursor(9, 0);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          if (onmin1 < 59) {
            onmin1 ++;
          }
          else {
            onmin1 = 0;
          }
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          if (onmin1 > 0) {
            onmin1 --;
          }
          else {
            onmin1 = 59;
          }
        }
        last_down = current_down;
      }//subpage1_counter 2

      //Thirth item control(subpage_counter =3) onsec1
      if (subpage1_counter == 3) {
        lcd.setCursor(9, 0);        //Delete last arrow position (onmin1)
        lcd.print(" ");
        lcd.setCursor(12, 0);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          if (onsec1 < 59) {
            onsec1 ++;
          }
          else {
            onsec1 = 0;
          }
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          if (onsec1 > 0) {
            onsec1 --;
          }
          else {
            onsec1 = 59;
          }
        }
        last_down = current_down;
      }//subpage1_counter 3

      //fourth item control(subpage_counter =4) offhour1
      if (subpage1_counter == 4) {
        lcd.setCursor(12, 0);        //Delete last arrow position (onsec1)
        lcd.print(" ");
        lcd.setCursor(6, 1);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          if (offhour1 < 23) {
            offhour1 ++;
          }
          else {
            offhour1 = 0;
          }
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          if (offhour1 > 0) {
            offhour1 --;
          }
          else {
            offhour1 = 23;
          }
        }
        last_down = current_down;
      }//subpage1_counter 4

      //fifth item control(subpage_counter =5) offmin1
      if (subpage1_counter == 5) {
        lcd.setCursor(6, 1);        //Delete last arrow position (offhour1)
        lcd.print(" ");
        lcd.setCursor(9, 1);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          if (offmin1 < 59) {
            offmin1 ++;
          }
          else {
            offmin1 = 0;
          }
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          if (offmin1 > 0) {
            offmin1 --;
          }
          else {
            offmin1 = 59;
          }
        }
        last_down = current_down;
      }//subpage1_counter 5

      //sixth item control(subpage_counter =6) offsec1
      if (subpage1_counter == 6) {
        lcd.setCursor(9, 1);        //Delete last arrow position (offmin1)
        lcd.print(" ");
        lcd.setCursor(12, 1);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          if (offsec1 < 59) {
            offsec1 ++;
          }
          else {
            offsec1 = 0;
          }
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          if (offsec1 > 0) {
            offsec1 --;
          }
          else {
            offsec1 = 59;
          }
        }
        last_down = current_down;
      }//subpage1_counter 6

      //seventh item control(subpage_counter =7) back
      if (subpage1_counter == 7) {
        lcd.setCursor(12, 1);        //Delete last arrow position (offsec1)
        lcd.print(" ");
        lcd.setCursor(0, 1);         //Place arrow in front of selected item
        lcd.write(byte(2));
        //Move item + or -
        if (last_up == LOW && current_up == HIGH) { //Up
          lcd.setCursor(0, 1);        //Delete last arrow position (back) to exit
          lcd.print(" ");
          subpage1_counter = 0;       //Exit submenu. Up/down butons enabled to move main pages
        }
        last_up = current_up;

        if (last_down == LOW && current_down == HIGH) { //Down
          lcd.setCursor(0, 1);        //Delete last arrow position (back)
          lcd.print(" ");
          subpage1_counter = 1;       //Go to first item (onhour1)
        }
        last_down = current_down;
      }//subpage1_counter 7
      //case 2
      break;

    case 3:                //Page 3 display and functions
      lcd.setCursor(4, 0);
      lcd.print("PRESS SEL");
      lcd.setCursor(5, 1);
      lcd.print("TO SAVE");
      if (last_sel == LOW && current_sel == HIGH) { //select button pressed.Save settings to eeprom
        EEPROM.write(0, onhour1);
        EEPROM.write(1, onmin1);
        EEPROM.write(2, onsec1);
        EEPROM.write(3, offhour1);
        EEPROM.write(4, offmin1);
        EEPROM.write(5, offsec1);
        lcd.clear();                 //Print message "SAVED!"
        lcd.setCursor(5, 1);
        lcd.print("SAVED!");
        delay(2000);
        lcd.clear();               //Clear lcd and go to main page
        page_counter = 1;
      }
      last_sel = current_sel; //Save last state of select button

      //Case 3
      break;
  }//switch

  //-------------Conversion----------//

  //---------Converting clock time into single number

  Hour = now.hour();
  Min = now.minute();
  Sec = now.second();
  Time = (Hour * 10000 + Min * 100 + Sec * 1);

  //--------Converting firt timer on/off into single number
  on_hour1 = onhour1;
  on_min1 = onmin1;
  on_sec1 = onsec1;
  on_Time1 = (on_hour1 * 10000 + on_min1 * 100 + on_sec1);

  off_hour1 = offhour1;
  off_min1 = offmin1;
  off_sec1 = offsec1;
  off_Time1 = (off_hour1 * 10000 + off_min1 * 100 + off_sec1);

 //----Relay Function----//
if(onhour1 == offhour1 && onmin1==offmin1 && onsec1==offsec1){
   NeoBlink(0, 0);
}

if(on_Time1 < off_Time1){

             if(Time >= on_Time1 && Time < off_Time1){  //Start
             NeoBlink(7, 500);
             }
             else if(Time >= off_Time1) {
             NeoBlink(0, 0);
             }
             else{
            NeoBlink(0, 0);
             }
}
if (on_Time1 > off_Time1){

            if(Time >= on_Time1 && Time <= 235959){     //Start
            NeoBlink(7, 500);
            }
            else if(Time < off_Time1 ){
            NeoBlink(7, 500);
            }
            else if(Time >= off_Time1 && Time < on_Time1){
            NeoBlink(0, 0);
            }
}

}//void

(I had to cut this last one down a bit^ -too many characters, the most important stuff is there though)
This actually has no apparent errors BUT when I run it-it messes with my RTC, LCD and I cannot access the serial display (referring to a Time On/Off Circuit minus the 5v relay I made
Also the lights don't run like they do when I run the first string of code I posted.
The majority of the changes are at the end where I subbed in NeoBlink() for digitalwrite(). I also made the correct changes to voidsetup() and voidloop().
Of course I can think of some reasons why this code wouldn't run but I have a specific question.
My question is would it even be possible to integrate the first string of code into the second or will it have to be completely re-formatted for integration? If re-formatting is required-where should I start?
Thanks

try merging the code before posting ... that way you can ask an actual question about a problem you are having

You're right-I've actually already tried. I don't know why I didn't do that.


text:
Touching a capacitive button, non-mechanically
This is not about using a capacitive button to control an Arduino; it is the opposite. I would like to "touch" a capacitive button on another conventional device. There could be a way like actually moving a finger-like stick and touch the button, but that is too much work. Can't it be done non-mechanically?
According to this page ( https://scienceline.org/2012/01/okay-but-how-do-touch-screens-actually-work/ ), "Instead, they work with anything that holds an electrical charge – including human skin.". Then, can I emulate "touching" the button by sending some small electrical current?
If so, what module/parts do I need to send such small current?

It's all about capacitance.  The micro is putting a voltage on that cap sensor and measuring how long it takes to fall or rise.  That gives a measure of capacitance.  When you put your finger you change the capacitance.  Perhaps you could put a second plate there and get the capacitance right to not trigger the button and then have a capacitor that you can switch in to make it higher and trigger it.  Not entirely sure how you'd do that, but maybe it gives you a place to start.

the button likely handles its own grounding so one question is whether you have access to that device's ground... if not for a purely isolated device, you'd need to mirror their two electrodes.  you then drive a voltage between your two (direction matters for this) to pretend to not touch or connect them to the same (both to either high or low) to simulate a touch

Check out these links: (1) https://www.youtube.com/watch?v=Ji2-2ehLCOQ
(2) https://www.youtube.com/watch?v=4ElZec033vQ (3) https://www.youtube.com/watch?v=gSifTiR_e2E (4) https://www.youtube.com/watch?v=XMZrUPBt-7M

The simply way is making a little capacitor.
Cut 2 circle with aluminium from a can and put a paper between them, then solder one one to one circle and other to the other side. One wire goes to the positive and the other to the I/O. When you set to 1 it should create a capacitive charge and "touch" de button.

"then solder one one..." do you mean "then solder one wire..."? Also, "de button" should be "the button" and "The simply way" should be "The simple way"? The typos aside, your answer would benefit from a diagram as it isn't particularly clear what you mean. "One wire goes to the positive". do you mean Vcc? If so, then what relationship does your DIY capacitor have with the capacitive button on the third-party device? How are they connected? How is the capacitive button activated?


text:
ESP8266 HttpClient recursive connections to URL to send sensor data
I am developing a project based in Arduino Nano and 2 sensors. In this projects is very important the energy because of the prototype is going to be powered by batteries or solar power.
In order to save energy in the
void loop(){....}

I am only getting the value of a temperature sensor continuously in a method that returns true / false.
When the method returns true, one relay is activated by Arduino, and it provides energy to the ESP8266-01 module and other sensor.
At this moment I need to connect the ESP8266 to WiFi network, and after the WiFi connection is successfully, I need to read other sensor value 50 times and make a connection with
client.connect(server, 80)

and send sensor data with GET method to upload every sensor value to server.
In this way I am able to send the first read, but for further sensor reads the connection to server gives error
My code resumed:
void setup(){
  // Setup sensors...
}

void initWifi(){
  // Open ESP8266 connection to WiFi network
}

boolean tempetarure_read(){
  // read continuously the temp sensor...
}

void loop(){
  if(tempetarure_read()){
    digitalWrite(relayPin, HIGH); //Open relay to give energy to ESP8266 module
    read_other_sensor_and_send_to_server();
    digitalWrite(relayPin, LOW); // Switch off the relay
  }
}

void read_other_sensor_and_send_to_server(){
  for (int x = 0; x < 50; x++) {
    string sensor_data = get_sensor_data();

    Serial.println();
    Serial.println("Starting connection to server...");
    // if you get a connection, report back via serial
    if (client.connect(server, 80)) {
        Serial.println("Connected to server");
        // Make a HTTP request
        //client.println("GET /asciilogo.txt HTTP/1.1");
        client.print("GET /sensor/store?");
        client.print(sensor_data);
        client.println(" HTTP/1.1");
        client.println("Host: my.server.com");
        client.println("Connection: close");
        client.println();
    }

    String res="";
    while (client.available()) {
        char c = client.read();
        res += c;
    }

    client.flush();
    client.stop();
    delay(1000);

  } // end for
}

I get
[WiFiEsp] Connecting to my.server.com
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Disconnecting  3

but the module is connected to wifi and my.serever.com is online. Can anybody help me to solve this issue?
Thanks in advance

There is a better approach than using a relay, you may want to read my blog on how I use an ESP-01 as a wifi shield and how an Arduino as a sensor node can "wake" it up when it is time to send data.

BTW, the problem of your code is that when you switch on the ESP-01, ESP-01 by default sent out some boot msg at baud rate of 74880, so what you received on Serial is not what you want. Secondly, it take several seconds for ESP-01 to established a wifi connection.

this is a case for troubleshooting not for an answer. turn on more logging. if you have an USB-to-TTL adapter, you can use it to sniff the communication between Arduino and esp8266, to see the exchanged AT commands and responses. do you use SoftwareSerial? is it at 9600 baud? if you have AT firmware 1.7+ (SDK3), try my WiFiEspAT library.


text:
Timer question: Phase Correct PWM at specific frequency
I am trying to create a sinusoidal wave segmented in 64 Frame, each holding a Duty cycle precisely varying from 0x00 to 0xff. This is for an Arduino Nano.
I have trouble understanding the following:

Which Wave Generator Mode and Matches will cause an interrupt at the constant Frame as well as help do a phase correct/fast PWM for the varying Duty Cycle?
How to tell which pin to use? I guess OC0B means Pin5 according to Pin Mapping but I'm not sure I truly understand.

This is what I have for the moment.
const byte waveFrame = 126;
const byte wave[]    = {
    0x80,0x98,/*a total of 64 values*/,0x67
};
byte frame = 0;
void setup(){
    pinMode(3,OUTPUT);
    noInterrupts();
    TCCR0A = (1<< WGM00)  // Phase correct PWM with top as OCR0A
           | (1<<COM0A0)  // Toggle OC0A on match
           | (1<<COM0B1); // Clear/Set OC0B on Compare Match when up/down-counting.
    TCCR0B = (1<<  CS01); // Prescaler of 8 (16MHz/8= 2MHz)
    TCNT0  = 0;           // Counter restarted
    OCR0A  = waveFrame;   // Constant frequency/64 for each frame
    OCR0B  = 0;           // Duty Cycle
    interrupts();
}
ISR(TIMER2_COMPA_vect){
    OCR0B = wave[frame & 0x3f]; //Rolls around
    frame++;
}

Thank you! I've lost a little bit of hair on this.

Are you sure your attiny runs at 16Mhz? The output pin is pin  OC0B, which is pin 6 on the ATTiny45. Not sure why you are using the pin mapping of the ATMega644P. Please tell us which processor you are actually using, because mentions three.

Thanks Gerben, I removed the comment regarding the ATTiny as it was not relevant to the issue here described. I'm using the Arduino Nano's ATMega indeed.

OC0B is on arduino pin 5. It seems you code also enables output on OC0A, which is Arduino pin 6, giving you a fixed 50% percent duty cycles. Which is quite useful when you are debugging things, and have it connected to a oscilloscope, or logic analyzer . EDIT Disregard this last part if you actually want to use waveform mode 1.

You'd want Waveform Generation Mode 5. This is PWM, Phase
Correct, but with TOP being the value of OCR0A instead of 255. For mode 5 you need to set both the WGM00 and WGM02 bits. Note that the WGM02 bit is in the TCCR0B register

pinMode(3,OUTPUT);

Pin 3 on the Nano is OC2B. It's PWM is controlled by Timer 2. You
want to use pin 5 (OC0B), since you are using Timer 0. Or
switch to Timer 2.

Phase correct PWM with top as OCR0A

Note that this is the description of mode 5. If you want this mode, you
have to set both the bit WGM00 in TCCR0A (which you did)
and the bit WGM02 in TCCR0B (which you didn't). Here you have set
mode 1: phase correct PWM with top = 0xff.

Not sure why I didn't validate it then. Thank you! That helped quite a fair bit!


text:
Convert Binary to char
I'm reading a text file saved on my ESP8266 device (using LittleFS).
while (myFile.available()) {
        Serial.write(myFile.read());
    }

My goal is to save file content ( each line ) to a String / char array.
myFile.read() returns a binary - and I'm looking for a quick and elegant way to do so ( as in Serial.write which converts it to text ).
Guy

It is unclear, what you are trying to do. Binary and characters are just different representations of the same data. Serial.write() just sends the data out as it is and the Serial monitor then interprets that data as ASCII. But the Arduino does not care about, what the data represents. For the Arduino, everything is just binary data. The character interpretation is only for us humans and is done in the Serial monitor, not on the Arduino. So, when you want to put the data into a char array, just do so array[position] = myFile.read().

@chrisl - I'm trying to exrract the text. When I did as you explained... I only got a bunch of numbers

You need to provide the full code, where you only got a bunch of numbers. Its all about, how you are writing or printing it to Serial. A character can also be interpreted as a number, so likely you are just outputting it to Serial the wrong way.

the point is, specially write does no conversion. print converts a number to text representation, by decomposing it to digits and mapping  every digit to ascii.. so from a byte with value 123 it prints string "123" consisting of characters '1', '2', '3'. but write sends 123 as t is and Serial Monitor prints the character with this value, which is '{'.

myFile.read() returns one character. That character can be represented as a number (such as 65 for 'A') or a character, or whatever you want. Everything is just a number.
Letters are just our personal representation of certain numbers as humans. You could think of it as the numbers represented in base 256, where each value between 0 and 255 is assigned a unique symbol.
Serial.write() just passes that number verbatim to the computer which then maps it in the serial monitor to the corresponding letter in the ASCII table.
Thanks to the object-oriented and polymorphic nature of the Arduino API (see C++ Polymorphism) there is no difference between reading from a file and reading from serial. They all inherit the same Stream class that gives you the same functions regardless of what you're reading.
So you could, like Serial, read each byte from the file one at a time until you reach the line ending character(s) (\n for a Unix file, or \r\n for a Windows file) and append each to the end of a string (either a String object, which is frowned upon, though less so on more capable MCUs like the ESP8266 and ESP32, or a char array).
Alternatively you could use one of the helper functions of the Stream class, such as readStringUntil(), which reads an entire string up to (and discarding) the specified terminating character and returns a String.
However both those have problems when it comes to building up an array of all the results, especially if you don't know beforehand how many lines there are in the file - since in C++ arrays have a fixed size.
A better solution, if you really do want it all in RAM (see below), might be instead to, at first, forget the idea of lines and just read the entire file into memory. Once it is in memory you can read through the entire block of data counting the number of \n bytes (and add one if it doesn't end with \n). That will give you the number of lines in the file.
You can then allocate an array of pointers with the same number of entries as there are lines.
From there you can use strtok() on the data to split it into chunks on the \n bytes and assign each chunk to one of the pointers in your array.  That array then becomes a kind of index to the data.
But one has to ask... why do you want to store this data in RAM anyway? You have it in flash, and that is quite fast to access (not as fast as internal flash in a traditional MCU, but still many times faster than an SD card for example). If ease of navigating the data is your goal, maybe you should be thinking of better ways of storing your data. Depending on what that data is maybe a fixed size record based file structure using a struct to manipulate the data would be a better solution - then you can just seek to multiples of the record (or struct) size to almost instantly get to different entries in the file.
If it's textual data then maybe reading through the file and recording the file offsets of the start of each line in an array (note: two passes - one to count the lines for allocating the array and one for recording the offsets into the array) similar to the indexing of the data block described above would be a better solution. That way you're only storing 4 bytes per entry in your array rather than all the data. Seeking is instant (just seek to the offset stored in the array for the line you want) and you're not having to store all the data in RAM.


text:
Missing ACKs on I²C
I am using a GY-521 accelerometer as well as BMP280 pressure sensors via I²C on an ESP8266.
When I analyze I²C data with the oscilloscope, I can see missing ACKs on both of them as shown in the pictures.
Is that something to worry about or is it just normal, considering I bought cheap Chinese sensors?

My BMP280 code is this:
// https://github.com/mahfuz195/BMP280-arduino-library
#include <BMP280.h>
BMP280 bmp280;

#include "Wire.h"
TwoWire i2c = TwoWire();

// Hardware setup
#define CLOCK_PIN D1
#define DATA_PIN D2
#define I2C_SPEED 400000

// I²C response codes
#define FOUND 0
#define NORESPONSE 2

bool sensorAvailableAt(byte address)
{
   i2c.beginTransmission(address);
   byte response = i2c.endTransmission();
   return response == FOUND;
}

void stop(char* message){
  Serial.println(message);
  while(true);
}

void setup() {
  Serial.begin(115200);
  while(!Serial){} // Waiting for serial connection

  i2c.begin(DATA_PIN, CLOCK_PIN, I2C_SPEED);
  if (!sensorAvailableAt(0x76))
  {
    stop("BMP280 sensor not found");
  }

  if (bmp280.begin())
  {
    Serial.println("BMP280 init success");
  }
  else
  {
    stop("BMP280 initialization failed.");
  }
}

void loop() {
  double temperature;
  double pressure;
  bmp280.getTemperatureAndPressure(temperature, pressure);
  double sealevel = bmp280.sealevel(pressure, 800);

  Serial.print("Temperature: ");
  Serial.print(temperature,1);
  Serial.println(" °C");

  Serial.print("Pressure: ");
  Serial.print(pressure, 1);
  Serial.println(" mbar (absolute)");

  Serial.print("Pressure: ");
  Serial.print(sealevel);
  Serial.println(" mbar (sealevel, compensated for 800 m height)");

  delay(50);
}

I'm not sure, how the images are to be interpeted. A NACK at the end of the transmission (before the stop condition) is normal and belongs to the I2C protocol. The master signals that way, that it does not want to read more data.

@chrisl: ah, that's valuable. I'll try to find more on that

Can you confirm, that the "missing ACK"/NACK happens on the end of every master read action? If yes, I will formulate that as an answer.

@chrisl: yes, that's what I see and how I interpret the data. Do I get it right that this should only happen with a dedicated sensor library, where the implementation knows how much data to expect? In case of a more generic I²C implementation, the master would not know how much data there is to read and thus would not stop the transmission?

The NACK at the end of a master read/slave send transmission is normal expected behavior.
In I2C communication the acknowledgement is a possibility to react to send data. For example, when the slave sends a NACK while the master sends data to it, it might be, because it currently cannot process further data. Acknowledgement goes in both ways, depending on the direction of transmission. The reader always needs to acknowledge the data to mark a successful transmission. It is normal for the master to send a NACK on the end of it's reading cycle to mark, that it doesn't want to receive more data. While this isn't strictly logically needed (since the end of a transmission is marked by the master by a STOP or RESTART condition), it is done nonetheless.
I think I have also seen this behavior with the Wire library of Arduino. So it comes down to the implementation of the I2C protocol in your case. As your library simply uses the Wire library, the behavior is not part of it. The I2C protocol is implemented by Wire. You would see the same behavior in every sensor library, that uses the Wire library.
You can read more about the I2C protocol at this site.


text:
Code for 2 ultrasonic sensors
This is my code:
int trigPin=13; //Sensor Trig pin connected to Arduino pin 13
int echoPin=11;  //Sensor Echo pin connected to Arduino pin 11
float pingTime;  //time for ping to travel from sensor to target and return
float targetDistance; //Distance to Target in inches
float speedOfSound=776.5; //Speed of sound in miles per hour when temp is 77 degrees.
int trigPin1=2;
int echoPin1=3;
float pingTime1;  //time for ping to travel from sensor to target and return 1
float targetDistance1; //Distance to Target in inches 1
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
}

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

  digitalWrite(trigPin, LOW); //Set trigger pin low
  delayMicroseconds(2000); //Let signal settle
  digitalWrite(trigPin, HIGH); //Set trigPin high
  delayMicroseconds(15); //Delay in high state
  digitalWrite(trigPin, LOW); //ping has now been sent
  delayMicroseconds(10); //Delay in low state
  digitalWrite(trigPin1, LOW); //Set trigger pin low
  delayMicroseconds(2000); //Let signal settle
  digitalWrite(trigPin1, HIGH); //Set trigPin high
  delayMicroseconds(15); //Delay in high state
  digitalWrite(trigPin1, LOW); //ping has now been sent
  delayMicroseconds(10); //Delay in low state

  pingTime1 = pulseIn(echoPin1, HIGH);  //pingTime is presented in microceconds
  pingTime1=pingTime1/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
  pingTime1=pingTime1/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour)
  targetDistance1= speedOfSound * pingTime;  //This will be in miles, since speed of sound was miles per hour
  targetDistance1=targetDistance1/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance.
  targetDistance1= targetDistance*63360;    //Convert miles to inches by multipling by 63360 (inches per mile)
  pingTime = pulseIn(echoPin, HIGH);  //pingTime is presented in microceconds
  pingTime=pingTime/1000000; //convert pingTime to seconds by dividing by 1000000 (microseconds in a second)
  pingTime=pingTime/3600; //convert pingtime to hourse by dividing by 3600 (seconds in an hour)
  targetDistance= speedOfSound * pingTime;  //This will be in miles, since speed of sound was miles per hour
  targetDistance=targetDistance/2; //Remember ping travels to target and back from target, so you must divide by 2 for actual target distance.
  targetDistance= targetDistance*63360;    //Convert miles to inches by multipling by 63360 (inches per mile)

  Serial.println(targetDistance);

  Serial.println(targetDistance1);

  delay(100); //delay tenth of a  second to slow things down a little.
}

Python code:
import serial #Import Serial Library

arduinoSerialData = serial.Serial('com3',9600) #Create Serial port object called arduinoSerialData

while (1==1):
    if (arduinoSerialData.inWaiting()>0):
        myData = arduinoSerialData.readline()
        myData=str(myData)
        myData= myData.replace("b'",'')
        myData=myData.replace("\\r\\n'",'')
        if myData<"3":

            print( myData)

When I compile the sketch, it shows no error.But when I run the file in python, output=0.However, when they are run individually, python gives me a valid input.so is this code correct?Also, is there a way to call for the exact c++file in python?Thanks for the help!

What file you are you running in python? You didn't show your python sketch. 2. How do you distinguish between the data from the first sensor and from the second sensor? Or doesn't that matter for you?

Edit:outputs are distinguished by targetDistance1 and targetDistance(one variable has a'1' and one doesn't)

I meant it your python program. But as you are just printing every line, that doesn't really apply here. Have you checked, that the Serial output of your Arduino sketch is as you expect it to be? You could check that simply in the Serial monitor. And why are you doing if myDATA<"3" in your python program? Why do you only want to display lines, which are lexically at a lower order as "3"?

I was testing if my idea was gonna work..Cus the program that i am building,triggers a series of actions if distance is lesser than 3

You are not checking for the distance being lesser than 3. You first need to convert the data to a number, before you can compare it that way. Currently you are comparing two strings lexically, not 3 numbers.

Please confirm, that the Serial output is as you expected. In that case it is purely a python problem. I think you should do some basic tutorials for python and read a bit about variable types in python. That will give you enough knowledge, to write your python script correctly

Alright ill look into it from a python perspective,thanks!

I just check my python code,it just prints the data outputted by the c++ code......so is the c++ code correct?
edit:The serial output is not exactally as expected.When I run the code for each ultrasonic sensor,it gives the correct output, but when i combine them (to form the code above) the output I get is 0.00.So there is a error when i combine the 2 codes.(What i mean by individual code is the above code without the echoPin1,triggerPin1,pingTime1 ect)

You are trying to measure with 2 ultrasonic sensors at once. You cannot do that so easily. You need to measure sequentially for 2 reasons:

The ultrasonic sensors might get confused by the others signal
You will miss the pulse of the one sensor, while you are reading the pulse of the other via pulseIn().

So the order of actions is like this:

Trigger sensor 1
Read sensor 1 with pulseIn()
Trigger sensor 2
Read sensor 2 with pulseIn()

Thanks so much!It works perfectly!

Is there a way i can differentiate the 2 inputs?

You can print an identifier before it, for example 1:100 for the value 100 of the first sensor. Then you can split the string in python at the colon to get the sensor number and the value individually

ah okok got it thanks!!

Is it possible to add for eg "a" and "b" to differentiate the 2 values?

Sure, just Serial.print them before each corresponding value


text:
Do I need a resistor to control a servo with a PWM signal?
I working with Arduino Nano Every that has several analog PWM pins. I want to use one to control a small servo.
Do I need to put a resistor between PWM pin and the servo signal?

It depends. In my case I had to add 1k resistor. https://arduino.stackexchange.com/questions/88609/long-servos-cable-causes-arduino-to-restart

No, you don't.
Resistors are used to limit and control current (amongst other things) and you don't need to do that when sending a signal from one digital device to another.


text:
Check if any of loop's insides returns 1 and hold it until the whole loop is 0 again
I'm new to this, so, please, don't crucify me.
I have a function that checks if an entry in multilevel array is in a certain range. Using FOR loop I check the whole array with this function, which gives me true/false value for each record.
And now the problem:
I need to check if ANY entry in that loop returns true and hold it until every result of that loop is false again.
Any tips?
Thanks a lot.
There is my for loop:
  for(int i = 0; i < arrayTop; i++){
for(int j = 0; j < arrayDay; j++){
  for(int k = 0; k < arrayTime; k++){
    timeCompare(timeArray[i][j][k][0], timeArray[i][j][k][1], timeArray[i][j][k][2], timeArray[i][j][k][3], timeArray[i][j][k][4], timeArray[i][j][k][5], timeArray[i][j][k][6]);

    //Serial.print(i);Serial.print(j);Serial.print(k);Serial.print(" ");
    Serial.println(compareVar);

    if(i == 0){

      //set water switch
      if(compareVar == 1){
        waterOn = 1;
        Serial.println("Water ON");

        goto bailout;
      }
      else {
        waterOn = 0;
        Serial.println("water OFF");
      }
    }
    else if(i == 1){

      //set light switch
      if(compareVar == 1){
        lightOn = 1;
        Serial.println("Light ON");
        goto bailout;
      }
      else {
        lightOn = 0;
        Serial.println("light OFF");
      }
    }
  }
}

}
bailout:
and this is the called function:
//time compare with ON/OFF switch
int timeCompare(int hrOn, int minOn, int secOn, int hrOff, int minOff, int secOff, int timerSwitch){
  unsigned long int onTime = (hrOn*10000UL) + (minOn*100UL) + secOn;
  unsigned long int offTime = (hrOff*10000UL) + (minOff*100UL) + secOff;
  unsigned long int currentTime = (dt.hour*10000UL) + (dt.minute*100UL) + dt.second;

  if(timerSwitch == 1){
    if(onTime < currentTime && offTime > currentTime){
      compareVar = 1;
    }
    else {
      compareVar = 0;
    }
  }
 else if(timerSwitch == 0) {
    compareVar = 0;
  }

  //Serial.print("compare: "); Serial.println(compareVar);

}

I don't understand, what you exactly you are trying to do. I think it would help, if you would show us the code, that you already have. What does "hold it" means?

Sorry, I know it's confusing :-) I added the relevant parts of the code as the whole thing is already quite long. By holds it I mean I need to know if there is a 1 anywhere in the loop, but so far it just tells me if there is 1 in a single entry and then sets it to 0 with the next entry. I need to keep the 1 as long as there is 1 anywhere in the full run of the loop.

First, you should really not use a global variable to get the result of your comparison function. That is only confusion and unnecessary complicated code. For that we have return values. So instead of setting the compareVar variable inside the timeCompare() function, you should just return the corresponding value. In the timeCompare() function replace
compareVar = 1;

with
return 1;

and
compareVar = 0;

with
return 0;

Then in your main code: As I understood, you only need compareVar in the for loops, so you could delete the globally defined compareVar and declare it directly before the for loops:
int compareVar = 0;

Now we can do the magic trick. We want to go through our for loops and get a result of 1, if for any of the elements timeCompare() returns 1. For that we just doing an OR operation:
compareVar = compareVar || timeCompare(timeArray[i][j][k][0], timeArray[i][j][k][1], timeArray[i][j][k][2], timeArray[i][j][k][3], timeArray[i][j][k][4], timeArray[i][j][k][5], timeArray[i][j][k][6]);

This is a boolean OR ||. In C++ zero is treated as false, while any other number is treated as true. We are starting with compareVar begin zero. When timeCompare() for the element returns also zero, it stays zero. If it returns 1, compareVar will become 1. If it returns 1 again, it will stay one. If it returns zero, it will stay zero.
So now you can check for compareVar after the for loops. It will be 1, if any of the elements gave you 1.
Similarly you could check for all elements returning 1, if you replace the OR || by an AND && operation.

Lastly I want to strongly discourage you from using goto. It ignores some important principles and you can easily create really bad code with it. Refer to questions like this one to read more about it. I would say, that in every case you have better ways than goto. Here it seems, that you simply want to go out of both loops. I would pack these loops into a function, so that you could simply use a return statement to get out of them.

For another perspective: I use goto in exactly this (and only this) situation - breaking out of a nest of loops. I just make it super obvious that I'm doing it, why, and to where. Specifically, I always have (though I seldom need it) a #define PUNT goto punt, and keep the punt: label easy to notice....

... This accomplishes two things: my code doesn't actually say "goto" (so the purists aren't so easily offended, though I'm sympathetic to their argument); and second, if I were to try to jump around in my code using this, or to create another nested-loops-with-breakout, my labels would conflict (multiple definitions) and prevent it. Either way, It gives me a heads-up that I need to re-think my coding structure and find a better way.


text:
Arduino I2C Multiplexing uisng TCA9548A
I am using 5 sensors out of which two have the same I2C address and are connected via TCA9548 multiplexer. The remaining 3 sensors are connected to the main arduino I2C bus. In example sketches online I see the following function to choose the specific port/channel on the multiplexer:
#define MPLXADR 0x70 // Address of TCA9548A I2C Multiplexer
void multiplexer (uint8_t ch) {
  if (ch > 7) return;
  Wire.beginTransmission(MPLXADR);
  Wire.write(1 << ch);
  Wire.endTransmission();
}

I understand that this function should be called before executing instructions for the sensors with shared address but how would it still send the data to the right sensor when the last line "Wire.endTransmission();" just closes connection?
Since in my circuit there are sensors which are connected directly to the arduino I2C bus, I wonder if the code related to those sensors comes after the code for sensors with shared address, wouldn't those instructions also be sent to the ensors with shared I2C address? To me it makes more sense if the instructions for the shared address sensors are enclosed inside the above mentioned function as follows:
channel select -> execute instruction -> end transmission
But the usage I see in the tutorials baffles me. Could somebody please clarify these points? Thanks
Here is the complete sketch I am using:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <AHT10.h>
#include <HDC2080.h>

Adafruit_BME280 bme1; // on Arduino I2C bus
Adafruit_BME280 bme2; // on multiplexer I2C bus
Adafruit_BME280 bme3; // on mulitplexer I2C bus
AHT10 AHT(AHT10_ADDRESS_0X38); // on Arduino I2C bus
HDC2080 HDC2080(0x41);// on Arduino I2C bus

#define MPLXADR 0x70 // Address of TCA9548A I2C Multiplexer
void multiplexer (uint8_t ch) {
  if (ch > 7) return;
  Wire.beginTransmission(MPLXADR);
  Wire.write(1 << ch);
  Wire.endTransmission();
}

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

  while (AHT.begin() != true)
  {
    Serial.println(F("AHT10 not connected or fail to load calibration coefficient"));
    delay(5000);
  }
  Serial.println(F("AHT10 OK"));

  HDC2080.begin();

  // Begin with a device reset
  HDC2080.reset();

  // Set up the comfort zone
  HDC2080.setHighTemp(28);         // High temperature of 28C
  HDC2080.setLowTemp(22);          // Low temperature of 22C
  HDC2080.setHighHumidity(55);     // High humidity of 55%
  HDC2080.setLowHumidity(40);      // Low humidity of 40%

  // Configure Measurements
  HDC2080.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  HDC2080.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  HDC2080.setTempRes(FOURTEEN_BIT);
  HDC2080.setHumidRes(FOURTEEN_BIT);

  //begin measuring
  HDC2080.triggerMeasurement();
  Serial.println();

  Serial.println(F("BME280 test"));

  //BME280 sensor 1
  multiplexer(0);
  if (! bme1.begin(0x77, &Wire)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // weather monitoring
  Serial.println("-- Weather Station Scenario --");
  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  Serial.println("filter off");
  bme1.setSampling(Adafruit_BME280::MODE_FORCED,
                   Adafruit_BME280::SAMPLING_X1, // temperature
                   Adafruit_BME280::SAMPLING_X1, // pressure
                   Adafruit_BME280::SAMPLING_X1, // humidity
                   Adafruit_BME280::FILTER_OFF   );

  //BME280 sensor 2
  multiplexer(1);
  if (! bme2.begin(0x77, &Wire)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // weather monitoring
  Serial.println("-- Weather Station Scenario --");
  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  Serial.println("filter off");
  bme2.setSampling(Adafruit_BME280::MODE_FORCED,
                   Adafruit_BME280::SAMPLING_X1, // temperature
                   Adafruit_BME280::SAMPLING_X1, // pressure
                   Adafruit_BME280::SAMPLING_X1, // humidity
                   Adafruit_BME280::FILTER_OFF   );

  //BME280 sensor 3
  if (! bme3.begin(0x76, &Wire)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  // weather monitoring
  Serial.println("-- Weather Station Scenario --");
  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  Serial.println("filter off");
  bme3.setSampling(Adafruit_BME280::MODE_FORCED,
                   Adafruit_BME280::SAMPLING_X1, // temperature
                   Adafruit_BME280::SAMPLING_X1, // pressure
                   Adafruit_BME280::SAMPLING_X1, // humidity
                   Adafruit_BME280::FILTER_OFF   );

  // suggested rate is 1/60Hz (1m)
 }

void loop() {
  bme3.takeForcedMeasurement(); // has no effect in normal mode
  printValuesBME3();
  delay(5000);

  printValuesAHT();
  delay(5000);

  printValuesHDC2080();
  delay(5000);

  multiplexer(0);
  bme1.takeForcedMeasurement(); // has no effect in normal mode
  printValuesBME1();
  delay(5000);

  multiplexer(1);
  bme2.takeForcedMeasurement(); // has no effect in normal mode
  printValuesBME2();
  delay(10000);
}

void printValuesBME1() {

  Serial.println();
  Serial.print("BME1 Readings");

  Serial.print("Temperature = ");
  Serial.print(bme1.readTemperature());
  Serial.println(" *C");

  Serial.print("Humidity = ");
  Serial.print(bme1.readHumidity());
  Serial.println(" %");

  Serial.println();
}

void printValuesBME2() {

  Serial.println();
  Serial.print("BME2 Readings");

  Serial.print("Temperature = ");
  Serial.print(bme2.readTemperature());
  Serial.println(" *C");

  Serial.print("Humidity = ");
  Serial.print(bme2.readHumidity());
  Serial.println(" %");

  Serial.println();
}

void printValuesBME3() {

  Serial.println();
  Serial.print("BME3 Readings");

  Serial.print("Temperature = ");
  Serial.print(bme3.readTemperature());
  Serial.println(" *C");

  Serial.print("Humidity = ");
  Serial.print(bme3.readHumidity());
  Serial.println(" %");

  Serial.println();
}

void printValuesHDC2080() {
  Serial.println("HDC2080 Values");
  Serial.print("Temperature (C): "); Serial.print(HDC2080.readTemp());
  Serial.print("\t\tHumidity (%): "); Serial.println(HDC2080.readHumidity());
}

void printValuesAHT() {

  Serial.println(F("AHT10: read 12-bytes, show 255 if communication error is occurred"));
  Serial.print(F("Temperature: ")); Serial.print(AHT.readTemperature()); Serial.println(F(" +-0.3C")); //by default "AHT10_FORCE_READ_DATA"
  Serial.print(F("Humidity...: ")); Serial.print(AHT.readHumidity());    Serial.println(F(" +-2%"));   //by default "AHT10_FORCE_READ_DATA"
}

The TCA9548 is a switch.
You begin a transaction to it, change the channel that it allows through, and then end that specific transaction.
From that point on one and only one of the other two sensors are attached to your bus - the other doesn't exist.  When you communicate on the address of that sensor it passes through the TCA9548 as if it doesn't exist.
You can think of the TCA9548 as a controller that sits next to the switch:

simulate this circuit – Schematic created using CircuitLab
Send channel 0 and it flips the switch one way. Send channel 1 and it flips the switch the other way. Once the switch is flipped it stays flipped until you tell it otherwise.
From your sketches perspective the two HDC2080s on the MUX are only one HDC2080. You just flip the switch to the right position to access the specific physical device you want at the time.


text:
ESP8266-01 Wifi module + Wifi shield not present + ESP8266-01 libraries not working?
I have Arduino IDE v. 1.8.13.
I bought an ESP8266-01 module which I want to use in my Arduino-UNO board to send fingerprint registration confirmation (ID) via HttpClient to a xampp server since I dont want to store the fingerprint image in the database.
My ESP connection is as below:

In the serial monitor, my AT commands work well when I connect the module to my wifi using AT+CWJAP="ssid","password".
When I upload my code, which is supposed to connect to wifi, it says WiFi shield not present.
Im new to this, is there anything I am missing?
Thanks in advance.
Here is my code:
#include <ArduinoHttpClient.h>
#include <WiFi101.h>
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;

char serverAddress[] = "localhost/bel/arduino/scannerstatus/php";  // server address
int port = 80;

WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;

void setup() {
  Serial.begin(9600);
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
  }

Basically, my uploaded code does not go past the wifi connection stage. Even though the AT commands individually can connect to wifi.
I have tried different ESP8266 libraries and HttpClient libraries but they all seem to not connect to wifi.
Is there any other way to call a php script from arduino without using wifi?

Why are you using wifi101???

WiFi101 library is for Arduino WiFi101 shield. with esp8266 you can use some of the libraries which use a firmware in esp8266

I have tried WiFi.h, WiFi101 (which seems to have come with my arduino). They all dont work. @majenko

Those are for specific hardware. You need to match your library to your device. Or in your case just send serial commands.

I also used 3.3 volts not 5 V

My Arduino library manager search has no result for esp8266-01. Unless the installation process is different. Kindly bear with me I am fairly new to this. I appreciate.

try the WiFiEsp library. but before using it, change the AT+UART speed to 9600

Can you please include some explanation of how the Arduino Uno and ESP8266-01 are connected. You will need to program for the ESP8266 ESP-01 module like shown below,

You will need to write code for the ESP module to connect to the WIFI and listen to its Serial Com Port. The ESP will need to handle the message interpretation & WIFI updating.
The Arduino Uni will not be capable of directly using the ESP-01 module as a WIFI shield. It will need to communicate with the ESP via a serial coms link, you will need to send commands that include instructions & a Message to the ESP from the Arduino.

https://create.arduino.cc/projecthub/jeffpar0721/add-wifi-to-arduino-uno-663b9e - Link to the above image document, this should help explain my concept in more detail
I apologies if my comments above miss the point but with the amount of information provided I don't think I can help further.

Thanks Jack for the quick informative reply. Let me edit the info

dd you here about AT firmware or WiFiLink firmware?