body:
This code is for automatically opening and closing a window using a motor with senors such as dust, humidity, temperature, and rain sensor with bluetooth module through phone. With this code if I press 1,2 it would close or open the window and 3 would let the window open or close regarding the measures that the  sensor reads. Right now pressing 3  would only simulate this once and then turn off untill I press it again
So I would want this part
 else if (cmd == '3')
to repeat itself until I press another cmd button so the window keeps opening and closing.

    //////////////////////////////////////////////////////////////////////////
    #include <SoftwareSerial.h>
    #include <Stepper.h>
    #include <DHT.h>
    #define DHTPIN A1
    #define DHTTYPE DHT11
    #define D_IN 3
    #define A_IN A0

    int Txpin = 7;
    int Rxpin = 8;
    int stepsmotor = 1024;
    const int stepsPerRevolution = 64;
    SoftwareSerial BTSerial(Txpin, Rxpin);
    DHT dht(DHTPIN, DHTTYPE);
    int measurePin = 0;          // measurePin을 0으로 설정합니다.
    int ledPower = 2; // ledPower를 2로 설정합니다.
    int samplingTime = 280;    // samplingTime을 280으로 설정합니다.
    int deltaTime = 40;           // deltaTime을 40으로 설정합니다.
    int sleepTime = 9680;       // sleepTime을 9690으로 설정합니다.
    float voMeasured = 0;      // voMeasured를 0으로 설정합니다.
    float calcVoltage = 0;       // calcVoltage를 0으로 설정합니다.
    float dustDensity = 0;       // dustDensity를 0으로 설정합니다.

    Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

    void setup()
    {
      Serial.begin(9600);
      BTSerial.begin(9600);
      myStepper.setSpeed(550);
      pinMode(ledPower,OUTPUT);
      pinMode(D_IN, INPUT);
    }

    void loop()
    {
     if (BTSerial.available())
      {
        char cmd = (char)BTSerial.read();
        if(cmd == '1'){
          for(int i=0; i<(32*3-6); i++){
        myStepper.step(stepsPerRevolution);
          }}
        else if (cmd == '2')
          for(int i=0; i<(32*3-6); i++){
        myStepper.step(-stepsPerRevolution);
       }
        else if (cmd == '3'){
         int dIn = digitalRead(D_IN);
      double aIn = analogRead(A_IN);
        int h = dht.readHumidity();
        int t = dht.readTemperature();
    digitalWrite(ledPower,LOW);
      delayMicroseconds(samplingTime);

      voMeasured = analogRead(measurePin);
      delayMicroseconds(deltaTime);
      digitalWrite(ledPower,HIGH);
      delayMicroseconds(sleepTime);

      calcVoltage = voMeasured * (5.0 / 1024.0);

      dustDensity = (0.17 * calcVoltage - 0.1) * 1000;

        Serial.print(dustDensity);
        Serial.println(" ug/m3");
      Serial.print("Digital Input = "); Serial.println(dIn);
      Serial.print("Analog Input  = "); Serial.println(aIn);
      Serial.println();
        Serial.print("humidity:");
        Serial.println(h);
        Serial.print("temperature:");
        Serial.println(t);
        delay(1000);

        if (t >= 25 or h >= 70 or dustDensity >= 100 or aIn <= 50)
         for(int i=0; i<(32*3-6); i++){
        myStepper.step(stepsPerRevolution);
        }
        else
         for(int i=0; i<(32*3-6); i++){
        myStepper.step(-stepsPerRevolution);
        }

      delay(3000);
        }
        else if (cmd == '4'){

        }
          }
        }

title: How do I repeat else if (cmd == '3') until I press another cmd?

Answers: 1

body:
I would suggest to rewrite your program as a Finite State Machine (FSM). It's a simple but powerful concept. You first model your program into multiple states, that are connected through state transitions. It is a good way to first draw this as a graph. You can see one example in my answer to [this question][1].

For your case I would use your "modes" as states for the FSM plus an idle state, where simply nothing happens. You would start in the idle stat and then change to different states depending on the Serial input. In the states/modes 1 and 2, which are only one time actions, you would execute the action in the state and then directly change to the idle state again.

From the programming side a FSM can be implemented in multiple ways. I have seen FSMs using a variable and switch cases, but also FSMs, that use a function pointer. The last is elegant, but not as easy to understand for beginners. So I suggest you use the switch-case variant, as you can see in the answer linked above. Basically you use a variable (something like `int` or `char`) to represent the current state. In your `loop()` function you then build a switch-case statement for different values of your state variable. Often an enum is used as variable type to make the code more readable. In each case statement you write the code for the corresponding state. In your state/mode 3 you would check your sensors and close/open the window as needed, then leaving the case statement. When the next iteration of the `loop()` function happens, the FSM will still be in this state, checking again the sensors. In your states/modes 1 and 2 you would check, if the window already has the needed state and - if not - drive to motor to close/open the window. Then - still in the case statement - you would set the state variable to the idle state, then leave the case statement. So in the next interation of the `loop()` function the FSM will be in the idle state, doing nothing, making the states/modes 1 and 2 a one-shot everytime, that you activate them.

In contrast to the code in the linked answer, I would read the Serial data outside of the switch statement, since you will write directly to the state variable in there.

I strongly suggest, that you try to implement this. It is an important principle, that makes your more structural sound and easier to extent. A great learning experience.

  [1]: https://arduino.stackexchange.com/questions/63488/wanted-to-control-2-servos-with-serial-read/63491#63491


body: How do I upload sketches in multiple arduinos from one supervisor Arduino using UART , cd4051 for Rx and TX separately and reset pin low

title: Upload sketch in multiple arduinos

Answers: 0


body:
I'm just starting up with arduino and i have few simple questions.

- Why shouldn't i power ESP8266 WiFi module directly from arduino nano 3.3V rail? There are bunch of tutorials explicitly avoiding this or using resistors and i would like to know why?

- Could i use something like a Mean Well Switching Power Supply, 5V 10A to power the Arduino Nano and therefore have stable voltage by avoiding batteries and by doing so, connect ESP8266 directly to arduino without fear of breaking something?

- Could Arduino nano be powered through USB? And if yes, would it be then safe to connect ESP module to arduinos' 3.3V rail?

title: Powering ESP8266 module from arduino nano

Answers: 1

body:
> Why shouldn't i power ESP8266 WiFi module directly from arduino nano 3.3V rail?

The 3.3V rail of the Arduino is not meant to provide much current. The onboard regulator is a simple linear voltage regulator, which will dissipate the extra power as heat. As you draw more current through it, it will get hotter and finally get fried, as it cannot dissipate the created heat. The ESP chip needs multiple hundreds of mA, especially, when it is connecting to a wifi network. The onboard voltage regulator of the Arduino cannot handle this much. So you cannot power it over the Arduino.

I don't really know, what you mean with "using resistors".

> Could i use something like a Mean Well Switching Power Supply, 5V 10A to power the Arduino Nano [...] connect ESP8266 directly to arduino without fear of breaking something?

Yes, you can power the Arduino with this power supply, but you should power the ESP through the Arduino. Not through the 3.3V, nor through the 5V rail (which will fry the protection diode, I think). Instead you should power the ESP directly from the power supply, in parallel to the Arduino. Often ESP modules have their own voltage regulator, that regulates the voltage from 5V to 3.3V. If that is the case for you, you should use this input of the ESP module with the power supply. If you don't have a 5V capable regulated input on your ESP module, you will have to use a dedicated voltage regulator for that. In that case be sure, that the voltage regulator can provide enough power for the ESP (with some headroom on top).

> Could Arduino nano be powered through USB? And if yes, would it be then safe to connect ESP module to arduinos' 3.3V rail?

Yes, the Arduino Nano can be powered over USB. But again you must be sure to not draw too much current from the Arduino. Between USB and the 5V rail is a diode, that will be destroyed, if you draw too much current through it. And the standard USB port can only provide up to 500mA. And regarding the 3.3V rail: All the explanations above about the 3.3V rail apply here again, since the USB voltage (5V) is regulated down to 3.3V by the linear voltage regulator. So: No, you still cannot power the ESP through the Arduino. It's not about the power supply here, but about the electronic parts inbetween.


body:
Hello i have several power management IC that have an active low indicator for a fault, it would be a waste to dedicate a single digital pin for each of them. So i thought of  to interface them to a single digital pin. I do not need to know which of them has a fault, i just need to know that there is a fault.

[![enter image description here][1]][1]

How do i safely do this? and as a follow up question if the fault voltage is 5v and the arduino pins only take 3.3v how do i shift it down with minimal components. can i just add a resistor in series?

  [1]: https://i.stack.imgur.com/BL11C.png

title: How to conect multiple output pin from sensors to a single digital pin on a arduino

Answers: 1

body:
If the ICs output 5V and your Arduino is 3.3V, you can simply use one voltage divider at the Arduinos pin to divide the voltage down to 3.3V.

But there is still one important thing to connect them safely: You have to check, if the outputs of the ICs are driven actively high, when no fault occured, or if they simply use a pullup resistor internally.

A pin, that is actively driven high, does not have an overcurrent protection. So, if one IC would pull it's pin to low and the others are still high, a high current would flow between them, potentially destroying them. In that case you need current limiting resistors in series with the ICs (directly at the ICs, so that the resistors are between them).

On the other side, if the ICs output a high level through a pullup resistor, you are safe to connect them directly, as there can only flow a very little current through the pullup resistors. Often such a situation is called Open-Drain (passive high level through pullup resistors, active low level by driving the pin to low through a MOSFET, like used in a digital output pin). In that case you don't need the current limiting resistors.

---

EDIT: The [datasheet][1] of the ICs, that you linked to states that the fault output is an

> Active-low open-drain output

Also the example circuit shows an external pullup resistor. That means, that the fault pin is internally connected to a MOSFET, which will connect the pin to ground in case of a fault. Otherwise the pin is floating. The external pullup resistor will pull the pin state to a high level, when the MOSFET is not activated. This is good for you, since you can now simply use 1 resistor (one resistor is enough for all ICs), to pull the level up to 3.3V. Then you directly have the correct level for your Arduino and you don't need a voltage divider.

  [1]: https://www.ti.com/lit/ds/symlink/tps2065c.pdf


body:
You can extract

> the low-order (rightmost) byte of a variable

or

> the high-order (leftmost) byte of a word

with the functions `lowByte()` and `highByte()` respectively (the quotes are from the Arduino Reference).

Does Arduino provide a way to extract *any* byte from a number with a similar function?

And does it provide a way to set *any* individual bytes of a number (which would be the counterparts to these functions, if they exist)?

title: Set and extract individual bytes of a number (lowByte() and highByte())

Answers: 3

body:
Any more sophisticated byte exchange can be done with binary operators.

## Extracting information

You'll need some constants like

    MASK         SHIFT
    0xFF000000   24       (first byte, most significant)
    0x00FF0000   16       (second byte)
    0x0000FF00    8       (third byte)
    0x000000FF    0       (last byte, least significant)

You would binary AND the original value with MASK

         0x12345678
    AND  0x00FF0000
     =   0x00340000

and then bit shift it left, e.g.

       0x00340000
    >> 16
     = 0x00000034

So from the original value 0x12345678 you have gotten 0x34.

## Setting information

The opposite direction is also possible with the same constants but opposite operators and in opposite order:

       0x00000034
    << 16
     = 0x00340000

and then

       0x12005678
    OR 0x00340000
     = 0x12345678

Note that the OR operation only works reliably if the corresponding positions are 0x00. That's fine with a starting value of 0x00000000.

If you don't know that or you want to process an arbitrary number, you can introduce a step in between

        0x12??5678   (?? could be anything)
    AND 0xFF00FFFF   (which is the inverse of 0x00FF0000 and can be expressed as ~0x00FF0000)
     =  0x12005678   (whatever ?? was, it'll be cleared out)

## Actual Code

Tested on Arduino Uno. The `long` data type is 32 bits or 4 bytes.

The code here may not be the most efficient. Advanced developers would likely not use `MASK` and `SHIFT` as arrays like this. This answer focuses more on the educational point.

    long MASK[]  = {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF};
    byte SHIFT[] = {24        , 16        , 8         , 0};

    // Extracts a byte from a larger data type
    // value: larger data type to extract a byte from
    // position: 0 based number, 0 = MSB, 3 = LSB
    byte getByteAt(long value, byte position)
    {
      long result = value & MASK[position];  // binary AND
      result = result >> SHIFT[position];    // Shift right, moving all bits
      byte resultAsByte = (byte) result;     // Convert to an actual byte
      return resultAsByte;
    }

    // Sets a byte in a larger data type
    // value: larger data type where to set the byte
    // position: 0 based number, 0 = MSB, 3 = LSB
    // newPartialValue: the byte to be inserted
    long setByteAt(long value, byte position, byte newPartialValue)
    {
      long result = value & ~MASK[position];                       // clear the affected byte so that it is 0x00
      long valueToSet = (long) newPartialValue << SHIFT[position]; // Shift left, moving all bits
      result = result | valueToSet;                                // binary OR
      return result;
    }

    void setup() {
      Serial.begin(9600);
      Serial.println(getByteAt(0x12345678, 1));       // Prints 52, which is 0x34
      Serial.println(setByteAt(0x87654321, 1, 0xBB)); // Prints -2017770719 which is 0x87BB4321
    }

    void loop() {

    }

body:
The header Arduino.h defines the macro `word(high_byte, low_byte)`. The
resulting value is an `uint16_t`.

body:
There are two alternative methods, and they can both be easily used "in reverse" as well:

### Unions

    union byte_extract {
        uint32_t ival;
        struct {
            uint8_t byte_0; // least significant byte
            uint8_t byte_1;
            uint8_t byte_2;
            uint8_t byte_3; // most significant byte
        } bval;
    };

    ... later ...

    union byte_extract x;

    x.ival = 65536 * 99; // change to whatever you want
    Serial.println(x.bval.byte_2); //3rd byte

Unions are a way to define multiple possible ways to interpret a piece of memory, usually to save memory when you know something can't be 2 things at once. Strictly speaking it is not recommended to use them in this way but it works.

### Pointer arithmetic

    uint32_t *xaddr;
    uint8_t *xbyteaddr;

    uint32_t x = 65536 * 99; // change to whatever you want
    xaddr = &x;
    xbyteaddr = (uint8_t *) xaddr;

    Serial.println(xbyteaddr[2]); //3rd byte

Memory addresses (on Arduino as well as on PCs) refer to the first byte of a variable.  If you have an (uint32_t *) you will read 4 bytes starting at that address. But if you have a (uint8_t *) or a (char *) you will only read 1 byte. You can shift this pointer-to-uint8_t forwards by as many bytes as you want.

Apologies if this doesn't quite work on Arduino, I have only tested it on PC.


body:
I am trying to read BME680 on ESP32-CAM with following code :

(Before trying BME680, I have suscessfully connected BME280 to ESP32-CAM over S/W SPI)

    #include <Wire.h>
    #include <SPI.h>
    #include <Adafruit_Sensor.h>
    #include "Adafruit_BME680.h"

    #define SEALEVELPRESSURE_HPA (1013.25)

    #define BME_SCK 12 //Connected SCL to IO12
    #define BME_MISO 15 //Connected SDO to IO15
    #define BME_MOSI 13 //Connected SDA to IO13
    #define BME_CS 14 //Connected CS to IO14

    //Adafruit_BME280 bme; // I2C
    Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
    //float temperature = 0;
    //float humidity = 0;
    //float pressure = 0;

    void setup() {
      Serial.begin(115200);
      while (!Serial);
      Serial.println(F("BME680 test"));

      if (!bme.begin(0x76))
      {
        Serial.println("Could not find a valid BME680 sensor, check wiring!");
        while (1);
      }

      // Set up oversampling and filter initialization
      bme.setTemperatureOversampling(BME680_OS_8X);
      bme.setHumidityOversampling(BME680_OS_2X);
      bme.setPressureOversampling(BME680_OS_4X);
      bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
      bme.setGasHeater(320, 150); // 320*C for 150 ms
    }

    void loop()
    {
      if (! bme.performReading())
      {
        Serial.println("Failed to perform reading :(");
        return;
      }
      Serial.print("Temperature = ");
      Serial.print(bme.temperature);
      Serial.println(" *C");

      Serial.print("Pressure = ");
      Serial.print(bme.pressure / 100.0);
      Serial.println(" hPa");

      Serial.print("Humidity = ");
      Serial.print(bme.humidity);
      Serial.println(" %");

      Serial.print("Gas = ");
      Serial.print(bme.gas_resistance / 1000.0);
      Serial.println(" KOhms");

      Serial.print("Approx. Altitude = ");
      Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
      Serial.println(" m");

      Serial.println();
      delay(2000);
    }

When I try to upload the code to ESP32-CAM while BME680 is connected I get following error

    esptool.py v2.6
    Serial port /dev/ttyUSB0
    Connecting....
    Chip is ESP32D0WDQ6 (revision 1)
    Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
    MAC: a4:cf:12:99:b5:70
    Uploading stub...
    Running stub...
    Stub running...
    Configuring flash size...
    Warning: Could not auto-detect Flash size (FlashID=0xffffff, SizeID=0xff), defaulting to 4MB
    Compressed 8192 bytes to 47...

    A fatal error occurred: Timed out waiting for packet content
    A fatal error occurred: Timed out waiting for packet content

Then I tried to disconnect BME680 and uploaded the code to ESP32-CAM which worked, then connected BME680 back to ESP32-CAM.

But now I see following error in Serial Monitor :

    ets Jun  8 2016 00:22:57

    rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
    flash read err, 1000
    ets_main.c 371
    ets Jn  8 2016 00:22:57

    rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
    flash read err, 1000
    ets_main.c 371
    ets Jun  8 2016 00:22:57

    rst:0x10 (RTCWDT_RTC_RESET),boot0x33 SPI_FAST_FLASH_BOT)
    lash read err, 1000
    et_main.c 371
    ets Jun  8 2016 00:22:57

    rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
    flash read err, 1000
    ets_main.c 371
    ets Jun  8 2016 00:22:57

    rst:0x10 (RTCWDT_RTC_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
    flash read err, 1000
    ets_main.c 371
    ets Jun  8 2016 00:22:57

Any idea what is wrong here ?

Update :

I switched `#define BME_SCK 12` to `#define BME_SCK 16`, now getting following message

    ts Jun  8 2016 00:2:57

    rst:0x1 (POWEON_REST),boot:0x13 (PI_FAT_FLASH_BOOT)
    cnfigsi: 0, SPIWP:0xee
    clk_dv:0x00,q_drv:0x0,d_drv0x00,cs0_drv:0x00,d_drv0x00,wp_drv:0x0
    mod:DIO, clock div:
    loa:0x3fff0018,len:4
    load0x3fff001c,len:1216
    ho 0 tail 12 room 4
    lod:0x40078000,len:9720
    h 0 tail 12 room 4
    load0x40080400,len:6352
    etry 0x400806b8
    [D][esp32-hal-psram.c:47] psramInit(): PSRAM enabled

title: ESP32-CAM not reading BME680

Answers: 2

body:
GPIO12 must not be pulled high during boot. It's possible there's a pull-up resistor on the BME680 breakout board you're using that's pulling SCK high and interfering with the boot process. I would avoid using GPIO12 here.

If you're out of pins on the ESP32 you can connect the BME680 via I2C rather than SPI. I2C only needs SDA and SCK (and power and ground, of course). The Adafruit library for the BME680 has an example of how to call the constructor for an I2C connection.

body:
You use pins

    #define BME_SCK 12 //Connected SCL to IO12
    #define BME_MISO 15 //Connected SDO to IO15
    #define BME_MOSI 13 //Connected SDA to IO13
    #define BME_CS 14 //Connected CS to IO14

for software SPI, but the esp32 can use any set of pins for hardware SPI.

And your set of pins are even the dedicated mux pins for SPI2 (they have the direct connection without mux). But they are in different mapping then your software SPI.

    SPI2:
    SCLK  14
    MISO  12
    MOSI  13
    SS      15

Source: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/spi_master.html

SPI2 is the default SPI used by the ESP32 Arduino SPI library, so the Adafruit library should have no problem to use hardware SPI with the SPI library.

    Adafruit_BME680 bme(BME_CS); // use hardware SPI

and wire the sensor to SPI2 pins according to their function


body:
I am trying to reduce the power of my [Arduino Nano IoT][1]. I would like to run it using a battery over a longer time period. I thought this would be possible when putting it to sleep most of the time. However, at the moment I can only reduce the power consumption to 10mA by

 - disabling wifi using the [WiFiNINA library][2]
 - putting the arduino to sleep using the [ArduinoLowPower library][3]
 - removing both LEDs
 - powering it through a 4,5V battery

Is there anything else I can do to further reduce power consumption? If not, is there another, more suitable device I can use instead for this project? It has to support wifi and use very low power during sleep.

  [1]: https://store.arduino.cc/arduino-nano-33-iot
  [2]: https://www.arduino.cc/en/Reference/WiFiNINA
  [3]: https://www.arduino.cc/en/Reference/ArduinoLowPower

title: Arduino Nano IoT Power Consumption

Answers: 1

body:
Two of those 10mA come from the ATECC608 crypto chip which idles at 2mA.  That leaves 8mA for you to track down.

The WiFi-NINA module has multiple "sleep" modes that range from 30mA down to 4.5µA. Since you can't be in the 30mA "modem sleep" mode (it's too high for your measurements) I suspect it enables "light sleep" at 800µA.

The switching regulator uses 200µA.  So those two together probably account for 1mA in total, leaving you 7mA more to find.

The accelerometer can be up to 1.25mA. I'll assume that since you don't mention it, you haven't set that to "power down" mode.  5.75mA left.

The main MCU is actually quite hungry for power, even when sleeping. Looking at the datasheet it can be between 1.3mA and 2.4mA for the different "idle" modes. Only "standby" mode (where clocks are switched off, etc) drops it below 1mA. With it running a simple program you are looking at 4-6mA.

So it could be that the MCU isn't actually sleeping properly, or that other modules that you think are in low power aren't.

I would suggest manually disabling chips completely (pull their respective RESET pins if available LOW if available) to see how that affects the current.


body:
My code initializes, the header (the ID; Value string) for the .csv file gets saved, but the dataString which is the most important part doesnt save to the .csv file.

I get an arraypointer to the start of the array. I dont have much experience with pointers but i dont get any errors.

The best solution would be if i could put everything into the "write matrix to SD"-function. Anyone has an idea? I am just dumbfounded because everything works perfectly without the arraypointer and i dont know what to try.

My setup()
```
  Serial.begin(115200);

  p_EKG_state_1 = &EKG_state_1;

  pinMode(CS_Pin, OUTPUT);
  if(!SD.begin(CS_Pin))
    {
      Serial.println("Card failed or not present");
    }

  EKG_data_transmision.matrixData = SD.open("/data.csv", FILE_APPEND);  //erstelle data.csv datei

  if(EKG_data_transmision.matrixData)
    {
    String header = "ID; Value;";
    EKG_data_transmision.matrixData.println(header);
    EKG_data_transmision.matrixData.close();
    Serial.println(header);
    Serial.println("card init sucess");
    }
  else
    {
    Serial.println("Couldnt open vector data file");
    }

  //Serial.println(ESP.getFreeHeap());
  pinMode(LED_BUILTIN, OUTPUT); // TEST OUTPUT LED PIN

  pinMode(btn_modus.PIN, INPUT_PULLUP); // MODUSAUSWAHL TASTER
  attachInterrupt(btn_modus.PIN, isr, FALLING); // MODUS TASTER hört auf fallende Flanke und führt dann Funktion isr aus
  WiFi.begin(ssid, password); // Verbinde mit WLAN

  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); // initialisiere Zeit variablen
  EKG_state_1.set_state(1);

}

```
My function that writes the matrix/arraypointer to the SD
```
bool  EKG_data_transmision::write_matrix_to_SD(unsigned short *array_pointer) // Übertrage , unsigned short id
{

   if(!SD.begin(CS_Pin))
  {
    Serial.println("Card failed or not present");
    return 1;
  }
  matrixData = SD.open("/data.csv", FILE_APPEND);  //erstelle data.csv datei

  if(matrixData)
  {
    //look if data.csv exists

    while(matrix_coloum < 3071)
    {
      if(matrix_coloum == 1024 || matrix_coloum == 2048)
      {
          header = "ID; Value;\n";
          matrixData.println(header);
      }
      dataString = String(matrix_coloum) + ";" + String(*array_pointer) + "\n";
      matrixData.println(dataString);
      Serial.println("This is datastring:");
      Serial.println(dataString);
      array_pointer++;
      matrix_coloum++;
    }

  }

  else{
    Serial.println("Error writing to file !");
}
  matrixData.close(); // close the file

  return 0;
}
```
My class with all the inits

```

class EKG_data_transmision
{
  private:

    String dataString;
    String header;
    unsigned short matrix_coloum = 0;

  public:
    EKG_data_transmision();

    File matrixData;

    //Definiere Funktionen:
    bool write_matrix_to_SD(unsigned short *array_pointer);
    bool delete_matrix_from_SD(unsigned int record);
```

title: ESP32 doesnt save every string to SD Card

Answers: 0


body:
hi I am using Arduino transmitter and receiver it works properly with sending and receiving username and password but I would include to check the username if its true open the led , I added this in the code but it seems that the code ignoring it ( the last part) as well as I want it to take the password and username at the same time

this is the recover code

    #include <RH_ASK.h>//include radioHead ASK library
    #include <SPI.h> // include dependant SPI libray

     RH_ASK rf_driver; // create ASK object
    int ledon = 13;
    String userid;
    String password;
     //RH_ASK ID1; // create ASK object
    //RH_ASK pass1; // create ASK object

    void setup() {

      rf_driver.init(); //initialize ASK object

      Serial.begin(9600); //setup serial monitor to 9600

      //if(!rf_driver.init())
           //Serial.print("init failed");
    }

    void loop() {

      // set buffer to size of expected message
      uint8_t buf[9];
      uint8_t buflen =sizeof(buf);

      //check if recevied packet is correct size
      if (rf_driver.recv(buf,&buflen))
      {
        int i;
        // message received with valid checksum
        Serial.print("id: ");
        Serial.println((char*)buf);
          userid =(char*)buf;
            Serial.println(userid);

      }

    delay(5000);

       uint8_t buf2[8];
      uint8_t buflen2 = sizeof(buf2);

       if (rf_driver.recv(buf,&buflen))

      {

        int i;
        // message received with valid checksum
        Serial.print("password: ");
        Serial.println((char*)buf);
          password = (char*)buf;
          Serial.println(password);

      }
      delay(5000);

    while ( userid =="A00034732" && password == "123456789"){
    digitalWrite(ledon, HIGH);
    delay(2000);
    digitalWrite(ledon, LOW);

    }
    }

transmitter code ----

    //Include RadioHead Amplitidue shift keying library
    #include <RH_ASK.h>
    // Include dependatnt ISP library
    #include <SPI.h>

    //create Ampitude shift keying object
    RH_ASK rf_driver;

    void setup() {
     // intialize ASK objct
    rf_driver.init();

    Serial.begin(9600);

      //if(!rf_driver.init())
          //Serial.print("init failed");

    }

    void loop()
    {

      const char *pass= "123456789";
    rf_driver.send((uint8_t *)pass, strlen(pass));
    rf_driver.waitPacketSent();
    delay(5000);

    const char *ID= "A00034732";

    rf_driver.send((uint8_t *)ID, strlen(ID));
    rf_driver.waitPacketSent();
    delay(5000);

    //const char *pass= "12345678";
    //rf_driver.send((uint8_t *)pass, strlen(pass));
    //rf_driver.waitPacketSent();
    //delay(5000);

    }

title: Arduino transmitter and receiver

Answers: 1

body:
You're not comparing strings - you're comparing addresses of strings.  Use [`strcmp()`](https://www.tutorialspoint.com/c_standard_library/c_function_strcmp.htm).

    while (
        (strcmp(userid, "A00034732") == 0) &&
        (strcmp(password, "123456789") == 0)
    ) {


body:
For the following program. Compiles and runs. I start the Serial Monitor (shown following code) and it asks me to input the Blink Rate. This runs in setup. Then it enters the loop and prints to the serial monitor the rate and starts the >Serial.println("the bl    And it hangs! I can exit the serial monitor and restart it and it does the same thing. So the program/sketch seems to be running fine but somehow the serial communication hangs?  Others have tried it and it works for them?  Using an Alien Aurora R5 running Win10 64bit Home.  Added some delays after another person tried it and it hung on them before adding delay and then ran for them.  They are using Win10 32bit and when tried on their 64bit laptop it hangs.

    //Testing the Serial Port

    #include <TimerOne.h>

    int state = 0;
    int value;
    long int newtime;

    void setup() {
      Serial.begin(9600);
      pinMode(13, OUTPUT);
      digitalWrite(13, state);
      Serial.println("Enter the Blink Rate: ");
    }

    void loop() {
      if (Serial.available()) {
        value = Serial.parseInt();
        delay(100);
        Serial.print("the blink rate is: ");
        Serial.println(value);
        Serial.println("Enter a new blink rate: ");
        newtime = value * 1000000;
        Timer1.initialize(newtime);
        Timer1.attachInterrupt(blinkme);
        delay(500);
      }
    }

    void blinkme() {
      state = !state;
      digitalWrite(13, state);
      delay(100);
    }

[![Serial Monitor][1]][1]

  [1]: https://i.stack.imgur.com/8ge1i.jpg

title: TimerOne Hanging

Answers: 2

body: If you enter 1 in Serial Monitor and you have line ends selected, the Serial Monitor sends "1\r\n". parseInt() reads 1 and in next loop \r or \n is available and parses as 0. You then set the Timer to 0. The Serial can't finish printing because the Timer fires without a pause.

body:
Change io 13 to (suggestion) 10 and attach led + 1k resister to io 10.
13 seems to be in use. Also No line end in Serial.


body:
my project about automated system I am using stepper motor to open and close the gate but my point is I want my code be like when the gate opened it stays 5 seconds then check the sensor if there is a motion the gate should not close and stay open when there is no motion the gate should close and if the gate is closing and there is a motion , motion should interrupt closing the gate and reopening the gate I am using Arduino uno

the code is :
<!-- language: c++ -->

    #include <RH_ASK.h>//include radioHead ASK library
    #include <SPI.h> // include dependant SPI libray
    #include <Stepper.h> // Include the Arduino Stepper.h library:
    // Define number of steps per rotation:

    RH_ASK rf_driver; // create ASK object
    int ledon = 13;
    int ledoff = 5;
    int sensor = 3;

    const int stepsPerRevolution = 2048;// Define number of steps per rotation:

    // Wiring:
    // Pin 8 to IN1 on the ULN2003 driver
    // Pin 9 to IN2 on the ULN2003 driver
    // Pin 10 to IN3 on the ULN2003 driver
    // Pin 11 to IN4 on the ULN2003 driver
    // Create stepper object called 'myStepper', note the pin order:
    Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

    void setup() {

      rf_driver.init(); //initialize ASK object

      // Begin Serial communication at a baud rate of 9600:
      Serial.begin(9600);

      // Set the speed to 5 rpm:
      myStepper.setSpeed(5);
      pinMode(ledon, OUTPUT);
      pinMode(ledoff, OUTPUT);

    }

    void loop() {

      //set buffer to size of expected message
      //uint8_t buf[8];
      // uint8_t buflen =sizeof(buf);

      //check if recevied packet is correct size
      //  if (rf_driver.recv(buf,&buflen))
      //{
      // int i;
      // message received with valid checksum
      // Serial.print("id: ");
      // Serial.println((char*)buf);
      // String userid =(char*)buf;
      // Serial.println(userid);

      // }

      //delay(5000);

      // uint8_t buf2[8];
      // uint8_t buflen2 = sizeof(buf2);

      // if (rf_driver.recv(buf,&buflen))

      // {

      //  int i;
      // message received with valid checksum
      // Serial.print("password: ");
      // Serial.println((char*)buf);
      // String password = (char*)buf;
      //  Serial.println(password);

      // }
      // delay(5000);

      String pass = "1234";
      String id = "A00036757";

      if (pass == "1234" ) {
        Serial.print("car exists");
        digitalWrite(ledon, HIGH);
        delay(300);
        myStepper.step(stepsPerRevolution / 3); //clockwise -OPEN GATE
        delay(10000);

        //if(digitalRead(sensor) == HIGH){
        delay(500);
      }

      if (digitalRead(sensor) == LOW) {

        digitalWrite(ledon, LOW);
        delay(300);

        digitalWrite(ledoff, HIGH);
        delay(300);
        myStepper.step(-stepsPerRevolution / 3); // CLOSE AFTER 5s COUNTERCLOCKWISE -  close gate
        digitalWrite(ledoff, LOW);
      }
      else {
        Serial.print("NO CAR");
      }

title: I am using Arduino stepper motor and pir sensor

Answers: 0


body:
If you want to have functions within a library that only the library itself should be able to use or variables that shouldn't be accessed from outside, you usually make them private by writing this in the header file:

```c++
class Lib{
  public:
    // All these can be accessed from outside
    void function1();
    void function2();
    int someNumber;
  private:
    // These two can't be accessed from outside
    void secretFunction();
    int secretNumber;
};
```
My question is this:

I want to write this library without using classes. How do I protect things from being accessed from anywhere in this case?

title: Protecting variables and functions within a library that has no class

Answers: 1

body:
If your library is implemented in a single .cpp file, you can define these
variables and functions within that file, and give them the `static`
qualifier:

```c++
static int my_private_variable = 42;

static void my_private_function()
{
    ...
}
```

Obviously, there should be no mention of them in the .h file.

Note also that we are talking about global variables. Local variables
are already hidden within the defining function.


body:
I am building a box that will start a genset. It has two buttons, run and stop.
I would like button run to be able to start (and remain constant) until pressed a second time, I have sussed this bit so far, but this is where I get stuck.
I would like the stop button to only stop the the engine (as a single function)
So my question is how do I integrate the second button (stop) to carry out this one task?

    int LEDYelState=0;
    int LEDRedState=0;
    int LEDGrnState=0;
    int RELAYRedState=0;
    int RELAYYelState=0;
    int RELAYGrnState=0;
    int LEDRedPin=10;
    int LEDYelPin=9;
    int LEDGrnPin=8;
    int RELAYRedPin=7;
    int RELAYYelPin=6;
    int RELAYGrnPin=5;
    int buttonPin=13;
    int buttonNew;
    int buttonOld=1;
    int dt=100;
    int buttonOff;
    int buttonPinOff=12;
    void setup() {
      // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(LEDRedPin, OUTPUT);
    pinMode(buttonPin, INPUT);
    pinMode (LEDYelPin,OUTPUT);
    pinMode (LEDGrnPin, OUTPUT);
    pinMode (RELAYRedPin, OUTPUT);
    pinMode (RELAYYelPin, OUTPUT);
    pinMode (RELAYGrnPin, OUTPUT);
    pinMode (buttonPinOff, INPUT);
    }
    void loop() {
    buttonNew=digitalRead(buttonPin);
    buttonOff=digitalRead(buttonPin);
    if(buttonOld==0 && buttonNew==1){
      if (LEDRedState==0){
        digitalWrite(LEDRedPin,HIGH);
        LEDRedState=1;
        digitalWrite(RELAYRedPin,LOW);
        RELAYRedState=1;

        digitalWrite(LEDYelPin, HIGH);
        LEDYelState=1;
        digitalWrite(RELAYYelPin, LOW);
        RELAYYelState=1;
        delay (8000);
        digitalWrite(LEDYelPin,LOW);
        digitalWrite(RELAYYelPin,HIGH);

        digitalWrite (LEDGrnPin,HIGH);
        LEDGrnState=1;
        digitalWrite (RELAYGrnPin, LOW);
        RELAYGrnState=1;
        delay(2000);
        digitalWrite  (LEDGrnPin,LOW);
        digitalWrite (RELAYGrnPin,HIGH);
        RELAYGrnState=1;
      }
      else{
        digitalWrite(LEDRedPin, LOW);
        LEDRedState=0;
        digitalWrite(RELAYRedPin, HIGH);
        RELAYRedState=0;
        digitalWrite(LEDYelPin,LOW);
        LEDYelState=0;

      }
    }
    buttonOld=buttonNew;
    delay(dt);

    }

title: Arduino uno toggle switch help

Answers: 1

body:
A general hint first: indent your code correctly. It makes it much easier to read and easier to spot logical errors.

Another improvement would be to name the pins with the same names as you name them when explaining the problem to us. I expected to find a `int buttonRunPin` and `int buttonStopPin`.

The first issue I see is:

    buttonNew=digitalRead(buttonPin);
    buttonOff=digitalRead(buttonPin);

This reads the same button twice. You probably wanted to read two different buttons: the "run" button and the "stop" button.

The next issue I see is:

    delay(8000);
    delay(2000);

During these 10 seconds, you can press and let go the button many times. But since there is no `digitalRead()` during that time, the button press will not be recognized.

The same applies to

    int dt=100;
    delay(dt);

If you press the button within these 100 ms, it will not be noticed.

Unfortunately, to fix that, you need to learn a completely new concept: [interrupts](https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/). And even worse, not all pins support interrupts. On the Arduino Uno, it's only pin 2 and pin 3, which means you would need to change your hardware setup (because you use pin 12 and 13). Put both buttons from the pin to ground, so that it closes when pushed.

You would then prepare the interrupt in the `setup()` routine:

    pinMode(buttonPin, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(buttonPin), toggleRun, CHANGE);
    pinMode(buttonPinOff, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(buttonPinOff), toggleStopped, CHANGE);

You also define global variables for the state of the buttons:

    volatile bool running = false;
    volatile bool stopped = false;

`volatile` is needed here to prevent the compiler from optimizing too much. The compiler does not know about the interrupts and thus can't know when the variable changes.

Next, you need two methods that are being executed whenever an interrupt occurs, i.e. you press a button:

    void toggleRun() {
        running = !running;
    }
    void toggleStopped() {
        stopped = !stopped;
    }

Note: the above `x = !x;` pattern is a short and efficient form of

    if (x == false) {
        x = true;
    }
    else if (x == true) {
       x = false;
    }

Once you have all that, you don't need the two `digitalRead()`s any more.

I'm afraid I haven't understood what your code's supposed to do. You have a lot of state variables that seem to have no use and especially they don't correspond to the motors. E.g. once `RELAYGrnState` is set to 1, it never changes back to 0.

This is what I have in the end:

    int LEDYelState=0;
    int LEDRedState=0;
    int LEDGrnState=0;
    int RELAYRedState=0;
    int RELAYYelState=0;
    int RELAYGrnState=0;
    int LEDRedPin=10;
    int LEDYelPin=9;
    int LEDGrnPin=8;
    int RELAYRedPin=7;
    int RELAYYelPin=6;
    int RELAYGrnPin=5;
    int buttonPin=13;
    int buttonNew;
    int buttonOld=1;
    int dt=100;
    int buttonOff;
    int buttonPinOff=12;

    volatile bool running = false;
    void toggleRun() {
        running = !running;
    }

    volatile bool stopped = false;
    void toggleStopped() {
        stopped = !stopped;
    }

    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      pinMode(LEDRedPin, OUTPUT);
      pinMode (LEDYelPin,OUTPUT);
      pinMode (LEDGrnPin, OUTPUT);
      pinMode (RELAYRedPin, OUTPUT);
      pinMode (RELAYYelPin, OUTPUT);
      pinMode (RELAYGrnPin, OUTPUT);

      pinMode(buttonPin, INPUT_PULLUP);
      attachInterrupt(digitalPinToInterrupt(buttonPin), toggleRun, CHANGE);
      pinMode(buttonPinOff, INPUT_PULLUP);
      attachInterrupt(digitalPinToInterrupt(buttonPinOff), toggleStopped, CHANGE);
    }

    void doSomething() {
      digitalWrite(LEDRedPin,HIGH);   // red LED is on
      LEDRedState=1;
      digitalWrite(RELAYRedPin,LOW);  // red motor off? others unclear
      RELAYRedState=1;

      digitalWrite(LEDYelPin, HIGH);  // yellow LED and red LED are on
      LEDYelState=1;
      digitalWrite(RELAYYelPin, LOW);  // yellow motor off?
      RELAYYelState=1;
      delay (8000);
      digitalWrite(LEDYelPin,LOW);     // red LED on
      digitalWrite(RELAYYelPin,HIGH);  // yellow motor on

      digitalWrite (LEDGrnPin,HIGH);  // red and green LED are on
      LEDGrnState=1;
      digitalWrite (RELAYGrnPin, LOW);  // green motor off
      RELAYGrnState=1;
      delay(2000);
      digitalWrite  (LEDGrnPin,LOW);    // red LED on
      digitalWrite (RELAYGrnPin,HIGH);  // green motor on
      RELAYGrnState=1;
    }

    void doLess() {
      digitalWrite(LEDRedPin, LOW);     // red LED off
      LEDRedState=0;
      digitalWrite(RELAYRedPin, HIGH);  // red motor on
      RELAYRedState=0;
      digitalWrite(LEDYelPin,LOW);      // yellow LED off
      LEDYelState=0;
    }

    void loop() {
      if(running){
        if (!stopped){
          doSomething();
        }
        else{
          doLess();
        }
      }
      delay(dt);
    }


body:
I have recently purchased two 7.4V, 1A, Planetary Gear Unipolar Stepper Motors as well as two Cytron 3A 4-16V Dual Channel DC Motor Drivers. I was told that I would need these to run the motors off an Arduino board. The question I forgot to ask was: what size power supply I would need for something like this?

I am just looking to learn how to code these arduino boards. I was hoping to get something that I could plug into a wall to save me from buying multiple batteries.

title: Determine what size power supply I need to run stepper motors

Answers: 1

body:
You can't run these off the Arduino board for several reasons:

0. the Arduino board does not provide 7.4V on any pin, only 5V (model dependent, but never 7.4 V)
0. the Arduino board can provide about 20mA per pin, never 1A or higher
0. even if the board would only need to pass the voltage on, the total current were >2A. This would possibly fry the board.

So, what you need is: a power supply with constant 7.4V or a regulated one where 7.4V is within the range. From this power supply you will power 3 devices only:

0. one arduino board via the Vin pin (accepts 7 to 12 V, so 7.4V is ok)
0. two Dual Channel DC Motor Drivers (accepts 4 to 16V, so 7.4V is ok)

From each motor driver, you will power

0. one Planetary Gear Unipolar Stepper Motors (designed for 7.4V)

Now, let's sum of the currents:

0. Arduino Uno board without any peripherals: ~45 mA
0. two Stepper motors: 1000 mA each
0. two motor drivers: hard to say. In theory, the motor driver would not consume power by itself, just forward it to the motors. In practice, it cannot forward everything. The driver will get hot and thus consume some power itself. The [datasheet](https://www.robotshop.com/media/files/content/c/cyt/pdf/cytron-3a-4-16v-dual-channel-dc-motor-driver-datasheet.pdf) is not specific about the power consumption. Let's assume a 70% efficiency = 30% loss. 30% of 1000mA is 300mA each.

The total current needed for this setup is 2645mA. Depending on your budget you could buy a 3A or 5A power supply. At constant 7.4V, that's 23W or 37W. For a regulated 0V to 20V power supply, go for 60W or 100W.

A cheap regulated one should be at ~50 USD. Expect those to be loud because of bad cooling / fan noise.


body: I am brand new to electronics. I am trying to use a seven segment display breakout module with my arduino uno. My problem is that the display has a common positive instead of negative common. How do I make this work? As far as I am aware, all the arduino pins output positive with the exception of the ground, which is the negative common.

title: 7 segment display with common anode

Answers: 1

body:
This answer assumes Arduino Uno. For other types, refer to the documentation.

Ardino pins are not positive per se: you can change the voltage with `digitalWrite()` to either 0V (`LOW`, equal to the GND pin) or 5V (`HIGH`, equal to VCC).

The difference between a common cathode or common anode will be the flow of the current. With a common cathode (negative), the pins will need to provide current ("source" current), with a common anode, the pins will need to receive current ("sink" current).

There is a [description](https://playground.arduino.cc/Main/ArduinoPinCurrentLimitations/) for the limits of sourcing and sinking:

> Pin SOURCE Current Limitations:
>
> 20 mA at VCC = 5 V
>
> Pin SINK Current Limitations:
>
> 20 mA at VCC = 5 V

Please also read about the maximum total of 150 mA sourcing and 100 mA sinking.

You'll need to compare those current limits with the current requirements of your 7 segment display. My guess is that your a 7 segment display has 1 VCC pin and 7 output pins that you connect to the Arduino. The limiting factor is the total maximum here. The Arduino can handle 100 mA/7 = 14mA in the worst case. If that's enough for your 7 segment, it should work.

For example, [this one](https://cdn-reichelt.de/documents/datenblatt/A500/SA39-11#KIN.pdf) works with 10 mA, so it would be compatible with Arduino. Make sure you have resistors in place.


body:
I've been having some issues with my Arduino Mega Board. I built a PCB that would sense LM35 reading, low-pass filter it and send it to A0 into the Arduino. This is the input for a PID controller based on Brett Beauregard library. The schematics is really simple, a voltage divider after de PWM output, that polarizes the base of a TIP 122, causing current to close the circuit for a wound wire resistor.

1)
I was feeding the PCB board with 12V 2A switching supply (but not the arduino). On the other side, my PC was connected to a USB-C / USB mini dock to the Arduino, and the Arduino conected to the PCB board ( LM35 Output and PWM Input).
While using it my computer lagged a lot, but I didn't do anything, untill it killed my mini dock's USB port.( the power supply GND was connected to the Arduino's GND)

2) I did a new PCB board, filtering even more the LM35 signal, and doing some extra changes. While doing some examinations for the filter (succesfully) and using a lab's regulated power supply for the PCB (12V), everything went okay...Untill I wanted to examine if the PWM signal was causing any noise into the LM35 reading, so I started apply the PWM signal to a header pin in the PCB. After a while my computer stopped recognizing the Arduino and finally killed a second USB mini dock.

I'm pretty sure there's not a shortcircuit or any stupid mistake... but I cannot find whats going on.

[![Schematics: the 2nd pin of the P1 socket was not being used, neither the fan one in P2. Wire wound resistor was not connected in the respective header pin ][1]][1]

  [1]: https://i.stack.imgur.com/lNYTz.png

title: Arduino Killing USB-C Mini Dock

Answers: 0


body:
I bought this 2.8" OLED from Aliexpress a few weeks ago: https://www.aliexpress.com/item/32988174566.html?spm=a2g0s.9042311.0.0.72304c4dAWcHG8

And after a ridiculous amount of searching for a datasheet, I came across this one that seems to match the board I bought: https://www.buydisplay.com/download/manual/ER-OLEDM028-1_Series_Datasheet.pdf

Wiring up pins 1 and 2 to ground and 3.3V on a breadboard, I'd expect something to happen with the display, but I get nothing. The display is in 8080 mode, so I wire everything up to a standard UNO board and power everything on. Still nothing. Try changing the power to 5V, no joy.

During my testing, I noticed the back of the display is getting hot. Not sure if that's a good thing or not yet.

So what's the best way to 1) determine if the datasheet I found is correct? 2) check if the OLED is just broken? I don't have a ton of experience with these displays yet, so I'm not sure if just powering the thing on should net some visual response.

title: New OLED seems dead, how can I be sure?

Answers: 1

body:
The datasheet you have found is not for the same display. Yes, it's similar, and yes, it has the same actual OLED display unit on the board, but the PCB is different. So you cannot assume that the pinout is the same.

The fact that it's getting hot tells me that you have probably wired something wrong and you are injecting voltage into it somewhere where voltage doesn't want to be injected.

To find if an OLED is working you have to actively wire it up.  With an LCD you can just give it power and you should be able to see some visual indication that it's working (back light, some shadowing of the display matrix, etc). But with an OLED you can't do that.  An OLED is made up of a matrix of LEDs which are either on or off. By default they are off, and when they are off it's no different to there being no power. That's the big benefits of OLED displays - low power consumption and true black.

To get any kind of indication that the display works you both need to wire it 100% correctly and program the Arduino in the right way to actively drive it by displaying something on the screen.  My usual test program when working with a new screen is to simply print `millis()` in the top left corner.


body:
I am new to programming and I thought a simple project to do would be to create an ammo counter.
I have been troubleshooting this code for several hours now, and can not figure out why my code is riddled with errors. Below is my program. Please give it a glance and let me know what mistake I have made. I will post the error report beneath my program. I apologize for my bad programming in advance and hope that there is still hope for me with the proper tutelage.
The program worked just fine when I ran a test using only one saved function, "twentyBullets()". After I added a 30 additional functions and created a chain of if-else-if conditions, the program began to report all sorts of errors.

     /*
        7-SEGMENT DISPLAY HANDLING CODE!
        The below code handles the 7-segment display for the digital ammo counter.

         A
        ___
      F|   |B
       G---G
      E|___|C
         D

     Above is the alphabet letter assignment for the different segments of
     the B07BMPPNQY display. Digital ammo counter project will use common pins, L3 and L4.
     */
      // Display pin declaration.
      // P_: Where P indicates the pin output for the segment of the display to be illuminated followed by a lower case letter
      // which indicates which specific led in the segment to illuminate.
      // ten: Where ten indicates the ten's place on the 7 segment display.
      // one: Where one indicates the one's place on the 7 segement display.

    int Pa = 0;
    int Pb = 1;
    int Pc = 2;
    int Pd = 3;
    int Pe = 4;
    int Pf = 5;
    int Pg = 6;
    int ten = 7;
    int one = 8;
    int ammo = 10;

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

    pinMode(Pa, OUTPUT);
    pinMode(Pb, OUTPUT);
    pinMode(Pc, OUTPUT);
    pinMode(Pd, OUTPUT);
    pinMode(Pe, OUTPUT);
    pinMode(Pf, OUTPUT);
    pinMode(Pg, OUTPUT);
    pinMode(ten, OUTPUT);
    pinMode(one, OUTPUT);

    }

    void loop(){
      // put your main code here, to run repeatedly:
      if (ammo == 1) {
      oneBullet();
      }
      else if (ammo == 2) {
      twoBullets();
      }
      else if (ammo == 3) {
       threeBullets();
      }
      else if (ammo == 4) {
        fourBullets();
      }
      else if (ammo == 5) {
        fiveBullets();
      }
      else if (ammo == 6) {
        sixBullets();
      }
      else if (ammo == 7) {
        sevenBullets();
      }
      else if (ammo == 8) {
        eightBullets();
      }
      else if (ammo == 9) {
        nineBullets();
      }
      else if (ammo == 10) {
        tenBullets();
      }
      else if (ammo == 11) {
        elevenBullets();
      }
      else if (ammo == 12) {
        twelveBullets();
      }
      else if (ammo == 13) {
        thirteenBullets();
      }
      else if (ammo == 14) {
        fourteenBullets();
      }
      else if (ammo == 15) {
        fifteenBullets();
      }
      else if (ammo == 16) {
        sixteenBullets();
      }
      else if (ammo == 17) {
        seventeenBullets();
      }
      else if (ammo == 18) {
        eighteenBullets();
      }
      else if (ammo == 19) {
        nineteenBullets();
      }
      else if (ammo == 20) {
       twentyBullets();
      }
      else if (ammo == 21) {
       twentyoneBullets();
      }
      else if (ammo == 22) {
        twentytwoBullets();
      }
      else if (ammo == 23) {
        twentythreeBullets();
      }
      else if (ammo == 24) {
        twentyfourBullets();
      }
      else if (ammo == 25) {
        twentyfiveBullets();
      }
      else if (ammo == 26) {
        twentysixBullets();
      }
      else if (ammo == 27) {
       twentysevenBullets();
      }
      else if (ammo == 28) {
       twentyeightBullets();
      }
      else if (ammo == 29) {
       twentynineBullets();
      }
      else if (ammo == 30){
       thirtyBullets();
      }
      else {
        zeroBullets();
      }
    }
    void zeroBullets()
               //0
    { digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);

            //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void oneBullet()
              //1
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }

    void twoBullets()
              //2
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void threeBullets()
              //6
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void fourBullets()
              //4
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void fiveBullets()
              //5
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, HIGH);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void sixBullets()
              //6
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, HIGH);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void sevenBullets()
              //7
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void eightBullets()
              //8
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void nineBullets()
                  //9
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);

              //0
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void tenBullets()
                  //0
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void elevenBullets()
                  //1
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void twelveBullets()
                 //2
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void thirteenBullets()
              //3
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void fourteenBullets()
              //4
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void fifteenBullets()
              //5
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, HIGH);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void sixteenBullets()
              //6
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, HIGH);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void seventeenBullets()
              //7
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void eighteenBullets()
              //8
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void nineteenBullets()
              //9
    {  digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //1
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);
    }
    void twentyBullets()
            //0
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentyoneBullets()
            //1
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentytwoBullets()
            //2
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentythreeBullets()
            //3
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentyfourBullets()
            //4
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, HIGH);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentyfiveBullets()
            //5
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, HIGH);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentysixBullets()
            //6
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, HIGH);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentysevenBullets()
            //7
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, HIGH);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentyeightBullets()
            //8
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }
    void twentynineBullets()
          //9
    {  digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, HIGH);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, LOW);
      delay(10);

              //2
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, HIGH);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }

    void thirtyBullets()
            //0
      digitalWrite(one, LOW);
      digitalWrite(ten, HIGH);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, LOW);
      digitalWrite(Pf, LOW);
      digitalWrite(Pg, HIGH);
      delay(10);

              //3
      digitalWrite(one, HIGH);
      digitalWrite(ten, LOW);
      digitalWrite(Pa, LOW);
      digitalWrite(Pb, LOW);
      digitalWrite(Pc, LOW);
      digitalWrite(Pd, LOW);
      digitalWrite(Pe, HIGH);
      digitalWrite(Pf, HIGH);
      digitalWrite(Pg, LOW);
      delay(10);
    }

THE ERROR REPORT:

    Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

    Digital_Ammo_Counter.ino: In function 'void loop()':

    sketch_Digital_Ammo_Counter:138:4: error: 'thirtyBullets' was not declared in this scope

        thirtyBullets();

        ^~~~~~~~~~~~~

    sketch_Digital_Ammo_Counter.ino:138:4: note: suggested alternative: 'twentyBullets'

        thirtyBullets();

        ^~~~~~~~~~~~~

        twentyBullets

    sketch_Digital_Ammo_Counter.ino: At global scope:

    sketch_Digital_Ammo_Counter:898:3: error: expected initializer before 'digitalWrite'

       digitalWrite(one, LOW);

       ^~~~~~~~~~~~

    sketch_Digital_Ammo_Counter:899:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(ten, HIGH);

                   ^

    sketch_Digital_Ammo_Counter:900:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pa, LOW);

                   ^

    sketch_Digital_Ammo_Counter:901:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pb, LOW);

                   ^

    sketch_Digital_Ammo_Counter:902:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pc, LOW);

                   ^

    sketch_Digital_Ammo_Counter:903:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pd, LOW);

                   ^

    sketch_Digital_Ammo_Counter:904:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pe, LOW);

                   ^

    sketch_Digital_Ammo_Counter:905:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pf, LOW);

                   ^

    sketch_Digital_Ammo_Counter:906:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pg, HIGH);

                   ^

    sketch_Digital_Ammo_Counter:907:8: error: expected constructor, destructor, or type conversion before '(' token

       delay(10);

            ^

    sketch_Digital_Ammo_Counter:910:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(one, HIGH);

                   ^

    sketch_Digital_Ammo_Counter:911:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(ten, LOW);

                   ^

    sketch_Digital_Ammo_Counter:912:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pa, LOW);

                   ^

    sketch_Digital_Ammo_Counter:913:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pb, LOW);

                   ^

    sketch_Digital_Ammo_Counter:914:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pc, LOW);

                   ^

    sketch_Digital_Ammo_Counter:915:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pd, LOW);

                   ^

    sketch_Digital_Ammo_Counter:916:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pe, HIGH);

                   ^

    sketch_Digital_Ammo_Counter:917:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pf, HIGH);

                   ^

    sketch_Digital_Ammo_Counter:918:15: error: expected constructor, destructor, or type conversion before '(' token

       digitalWrite(Pg, LOW);

                   ^

    sketch_Digital_Ammo_Counter:919:8: error: expected constructor, destructor, or type conversion before '(' token

       delay(10);

            ^

    sketch_Digital_Ammo_Counter:920:1: error: expected declaration before '}' token

     }

     ^

    exit status 1
    'thirtyBullets' was not declared in this scope

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

title: My code seems to be a train wreck

Answers: 4

body:
The error cascade is caused by the missing opening curly bracket `{` at the start of the `thirtyBullets()` function. This causes the function name to be not declared and also the following function calls to `digitalWrite()` to fail. Putting in this missing opening curly bracket should fix all the errors (though I cannot test it since I don't have a compiler at hand currently).

Besides that, your code can be made way shorter with a trick. Currently you use one function for every number, where you write the corresponding digital pins. So the situation is, that you always need to write to the same pins, just different values depending on a simple unsigned integer number. So I suggest, that you define the pin patterns for the digits in a 2 dimensional array. Then you can use only 1 function to output any of them. I will give you an example:

    uint8_t led_pattern[10][7]= {
        {0, 0, 0, 0, 0, 0, 1}, // pattern for the digit 0
        {1, 0, 0, 1, 1, 1, 1}, // pattern for the digit 1
        {0, 0, 1, 0, 0, 1, 0}, // pattern for the digit 2
        ...
        {0, 0, 0, 0, 1, 0, 0}}; // pattern for the digit 9

    void display_digit(uint8_t position, uint8_t digit){
        digitalWrite(one, position); // Writes low (aka zero) to pin one, when position is zero, else high
        digitalWrite(ten, !position); // Writes low to pin ten, when position is greater than zero, else high

        for(uint8_t i=0; i<7; i++){
            digitalWrite(i, led_pattern[digit][i]);
        }
        delay(10);
    }

    void display_number(uint8_t number){
        display_digit(0, number % 10);
        display_digit(1, number / 10);
    }

    void loop(){
        display_number(ammo);
    }

**So, what is happening here?**

First we define the LED patterns in a 2 dimensional array. It's first index is the digit, that we want to display; it's second index is the number of the LED to light. The value then is the state of the corresponding LED. I wrote `1` and `0`, because it is short. You could also write `HIGH` and `LOW` (since these are also only defines for `1` and `0`). So the pattern `{1, 0, 0, 1, 1, 1, 1}` means, that only the segments b and c output low, thus are turned on.

Then we define a function to display one digit. It takes the position of the digit and the actual digit (0 to 9) as parameters. We write the two outputs for our position directly with the variable. This is a very short way to do it and it doesn't work, when you have more than 2 digits. If you want to extend your counter one day, you can replace these 2 lines by a different construct (for example a switch case statement). Then we do a for loop from 0 to 6, so that we go through all the digits. In your case you use the pin numbers 0 to 6, so we can directly use `i` as pin number. (If you want to use other pins, you could save those pins in an array and reference the values in the array with `i`). In every iteration of the for loop, we write the value for the corresponding digit and LED to the corresponding output pin. After that, we only delay a short time and leave the function.

To make it easier, I also defined the function `display_number()`, which will display the complete number, by displaying the it's digits successively on the corresponding positions. If you are a beginnner, you might not recognize, what calculations I made there. The modulo operator `%` returns the rest of an integer division. So if I take `23 % 10` this would return `3` (integer division `23 / 10` is 2 and the rest is 3). This gives us the first (least significant) digit. We can then get the second digit by simply doing an integer division with 10, as it will cut the part after the decimal point. If you want to display numbers greater than 99 one day, you have to change both functions to accomodate for that.

Note, that I used `uint8_t` as type everywhere. This is just the smallest unsigned number type (8 bit wide). I used the smallest, since you don't need greater numbers here and it saves a bit of memory. When you want to extend your display to show values greater than 255, you need to change the type of the `number` parameter in the `display_number()` function to a greater type, for example `unsigned int` (which is 16 bits wide).

Also note, that I have not tested this code, since I don't have a compiler or Arduino at hand currently.

---

So now, you can display a number on your digit with just one function call and you don't need nearly 1000 lines of code for it.

When extending your code to do more things, than displaying numbers, you can easily get to the point, where using `delay()` is a bad thing, since the Arduino cannot do anything else during that time. Then you need to rewrite your code to avoid `delay()` and use the `millis()` function instead to make it unblocking. There are tons of tutorials out there for this and I just wanted to mention it.

body:
You've found the bug, but how could you have found it easier?

The most important step mentally is to accept that _you_ did something wrong. We don't know yet what, but it is exceedingly unlikely that the compiler complains about correct code. So the question is: What did you do wrong?

The compiler complained about a function "thirtyBullets". It didn't complain about "twentynineBullets". It doesn't realise that there is a function "thirtyBullets". The first thing is to check the spelling. If you named the function "thirrtyBullets" by mistake, that would explain things. But the name is right.

Then you see that the compiler complains about the line immediately after the start of the function. Hard to figure out what the compiler is complaining about, so something you did just before confused it. So now you check the line "void thirtyBullets()", that's Ok, the next line "digitalWrite(one, LOW);" looks Ok but something MUST be wrong here, and that's where you hopefully figure out the missing "{".

body:
Just to add to the idea of using an array—since C does not care about whitespace you can quite easily format your data like this:

    uint8_t led_pattern[10][7]= {
          {0,  // pattern for the digit 0
         0,  0,
           0,
         0,  0,
           0},

          {0, // pattern for the digit 1
         0,  1,
           0,
         0,  1,
           0},

          {1, // pattern for the digit 2
         0,  1,
           1,
         1,  0,
           1},
          ...
    };

This is an example of the "good habit" of making your code about your _intent_ rather than about _instructing_ the machine. You can spend 50% more time making your code clear, or spend 500% more time debugging it. As the saying goes,

> There are two ways to develop software: Make it so simple that there are obviously no bugs, or so complex that there are no obvious bugs.

**Note:** The above code will give you your digitalOut values in a different order to your pins (so chrisl's `for` loop won't work.) You can just manually do 7 digitalWrites to the correct pins when displaying the `digit`.

    digitalWrite( <pin number> , led_pattern[digit][ <led position> ]);

body:
Your code actually isn't bad. There aren't very many good ways of doing this sort of pin mapping, and the few that are have their own downsides as well. The main issue was the missing bracket, which I found by checking the drawThirty function since it was mentioned specifically and had cascading errors implying a missed semicolon or bracket.

One further tweak is that your code will only work on Arduino (so you're fine, but a different IDE may get mad at you). C does not search the whole file for function names, so if you declare/define the function after you use it, it will error out. Arduino uses a special pre-parser to fix this for you.

The proper way is to forward-declare the function as follows:
```
int returnAPieceOfData(byte x, char c, int i);//Now C knows it exists somewhere and won't error.

void foo(){

//somewhere in here you need returnAPieceOfData
}

int returnAPieceOfData(byte x, char c, int i){
//You now define the function after it's used, but have no errors!

}
```
This usually results in a C file where all the functions are declared at the top, and then the function definitions below can use them in any order without problems. It also makes it easier to tell if the file has a function, and if you add them in the same order, where it is.

---------

I will mention a potentially-useful method of alternately implementing the array lookup table for writing the pins. The above are very good suggestions, especially the shaped whitespace, but that approach will use a lot of extra memory because it uses full bytes per pixel.

If you are willing to accept a format that is somewhat harder to visualize, you could encode the entire space into a single byte, which I'll show below. You can also put the **pin numbers** into an array so that you *can* use a FOR loop.

Essentially, you have two options when writing this sort of system. You can go for code complexity, which is what your example did, or you can go for memory/data complexity, which I'm showing here. The downsides to THIS technique are that the data is somewhat arcane and hard to modify (since it's encoded and there's kinda a lot of it), and that it uses extra memory to hold that data.

```
void drawAllSegments(byte ammo_ct){
  byte hi=ammo_ct/10;
  byte lo=ammo_ct;
  drawLowSegments(lo);
  drawHighSegments(hi);
}

byte lpinNums[]={apin,bpin,cpin,dpin,epin,fpin,gpin};//pins for 0s display
byte hpinNums[]={apin,bpin,cpin,dpin,epin,fpin,gpin};//pins for 10s display
byte numbers[]={0b00111111,0b01111001,...};
//Format the "numbers" as 0bXGFEDCBA, where X is a don't-care
//(its value is never used and can be either 0 or 1)
//My example may be wrong. I think it's negative logic, but could also have made an error on top of that.

void drawLowSegments(byte ammo_ct){
  digitalWrite(one, HIGH);//set up the display select
  digitalWrite(ten, LOW);
  for (byte i=0;i<7;i++){//then draw!
    byte state=(numbers[ammo_ct]>>i)&0x01;//decompress the state of that segment
    digitalWrite(lpinNums[i],state);
  }
}

void drawHighSegments(byte ammo_ct){
  digitalWrite(one, HIGH);//set up the display select
  digitalWrite(ten, LOW);
  for (byte i=0;i<7;i++){//then draw!
    byte state=(numbers[ammo_ct]>>i)&0x01;//decompress the state of that segment
    digitalWrite(hpinNums[i],state);
  }
}
```
The advantages of this approach is that the code is just as compact as the array system, but that it uses 1/8 the RAM for that array. I don't imagine you are doing something that uses a whole lot of RAM, but it's still a good idea to minimize it where possible. In this case it also is much further expandable, since you can fit more numbers in before you run out of RAM.

You can also switch to PROGMEM, but reading that is a bit weird in some ways and it's easy to forget to read it in the first place (which results in reads of random RAM). In this case it should be small enough that further such optimization isn't required.

One last note is that, if you ever do something for which a byte is too small, you can use larger numbers up to the uint32_t, which is 32 bits of useful pixels, or potentially the uint64_t, which is 64 bits but may not be supported on the Arduino (I've never tried the latter).


body:
I make an automatic light that's triggered from a Visitor Counter. I use an LCD to show the actual counter state. The LCD does not anly show the actual count but also the numbers before. For Example:

If the counter is actual 2, it blinks between 1 and 2.

This behavior does not occur in the original project where the correct number is shown.

Please, can I know why, and how to fix it? Thank you!

![My Setup](https://i.stack.imgur.com/aFn45.jpg)

This is the code:

    //Visitors Counter and Automatic Room Light
    //Viral Science  www.youtube.com/c/viralscience

    #include<LiquidCrystal.h>
    LiquidCrystal lcd(13,12,11,10,9,8);

    #define in 14
    #define out 19
    #define relay 2

    int count=0;

    void IN()
    {
        count++;
        lcd.clear();
        lcd.print("Person In Room:");
        lcd.setCursor(0,1);
        lcd.print(count);
        delay(1000);
    }

    void OUT()
    {
      count--;
        lcd.clear();
        lcd.print("Person In Room:");
        lcd.setCursor(0,1);
        lcd.print(count);
        delay(1000);
    }

    void setup()
    {
      lcd.begin(16,2);
      lcd.print("Visitor Counter");
      delay(2000);
      pinMode(in, INPUT);
      pinMode(out, INPUT);
      pinMode(relay, OUTPUT);
      lcd.clear();
      lcd.print("Person In Room:");
      lcd.setCursor(0,1);
      lcd.print(count);
    }

    void loop()
    {

      if(digitalRead(in))
      IN();
      if(digitalRead(out))
      OUT();

      if(count<=0)
      {
        lcd.clear();
        digitalWrite(relay, LOW);
        lcd.clear();
        lcd.print("Nobody In Room");
        lcd.setCursor(0,1);
        lcd.print("Light Is Off");
        delay(200);
      }

      else
        digitalWrite(relay, HIGH);

    }

title: Arduino Uno - Can' get LCD Display work crrectly

Answers: 0


body:
my project about automated system I am using stepper motor to open and close the gate

I want my code be like when the gate opened it stays 5 seconds

then check the sensor, if there is a motion the gate should not close and stay open, when there is no motion the gate should close

if the gate is closing and there is a motion, motion should interrupt closing the gate and reopening the gate

I am using Arduino uno

the code is :

    #include <RH_ASK.h>//include radioHead ASK library
    #include <SPI.h> // include dependant SPI libray
    #include <Stepper.h> // Include the Arduino Stepper.h library:
    // Define number of steps per rotation:

    RH_ASK rf_driver; // create ASK object
    int ledon = 13;
    int ledoff = 5;
    int sensor = 3;

    const int stepsPerRevolution = 2048;// Define number of steps per rotation:

    // Wiring:
    // Pin 8 to IN1 on the ULN2003 driver
    // Pin 9 to IN2 on the ULN2003 driver
    // Pin 10 to IN3 on the ULN2003 driver
    // Pin 11 to IN4 on the ULN2003 driver
    // Create stepper object called 'myStepper', note the pin order:
    Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);

    void setup() {

      rf_driver.init(); //initialize ASK object

      // Begin Serial communication at a baud rate of 9600:
      Serial.begin(9600);

      // Set the speed to 5 rpm:
      myStepper.setSpeed(5);
      pinMode(ledon, OUTPUT);
      pinMode(ledoff, OUTPUT);

    }

    void loop() {

      //set buffer to size of expected message
      //uint8_t buf[8];
      // uint8_t buflen =sizeof(buf);

      //check if recevied packet is correct size
      //  if (rf_driver.recv(buf,&buflen))
      //{
      // int i;
      // message received with valid checksum
      // Serial.print("id: ");
      // Serial.println((char*)buf);
      // String userid =(char*)buf;
      // Serial.println(userid);

      // }

      //delay(5000);

      // uint8_t buf2[8];
      // uint8_t buflen2 = sizeof(buf2);

      // if (rf_driver.recv(buf,&buflen))

      // {

      //  int i;
      // message received with valid checksum
      // Serial.print("password: ");
      // Serial.println((char*)buf);
      // String password = (char*)buf;
      //  Serial.println(password);

      // }
      // delay(5000);

      String pass = "1234";
      String id = "A00036757";

      if (pass == "1234" ) {
        Serial.print("car exists");
        digitalWrite(ledon, HIGH);
        delay(300);
        myStepper.step(stepsPerRevolution / 3); //clockwise -OPEN GATE
        delay(10000);

        //if(digitalRead(sensor) == HIGH){
        delay(500);
      }

      if (digitalRead(sensor) == LOW) {

        digitalWrite(ledon, LOW);
        delay(300);

        digitalWrite(ledoff, HIGH);
        delay(300);
        myStepper.step(-stepsPerRevolution / 3); // CLOSE AFTER 5s COUNTERCLOCKWISE -  close gate
        digitalWrite(ledoff, LOW);
      }
      else {
        Serial.print("NO CAR");
      }

title: automated parking system (sir sensor+ stepper motor)

Answers: 1

body:
When you use `delay()`, your code stops and dont check anything at all until the delay is over, if you want to check for sensors during a timer, you have to use `millis()`

There is a lot of documentation and tutorials you can find to replace delay with millis when you know what you are searching for


body:
Good morning,
I am coding an alarm clock on arduino by using a DS3231 and a TM1638.
The code works and the time updates in the serial monitor,although the time doesn't update on the tm1638.
I'll attach the code here:

    #include <DS3231.h>
    #include <TM1638.h>
    #include <Streaming.h>
    #include <SPI.h>
    #include <Wire.h>
    #include <InvertedTM1638.h>
    #include <TM1638.h>
    #include <TM1638QYF.h>
    #include <TM1640.h>
    #include <TM16XX.h>
    #include <TM16XXFonts.h>
    byte buttons;
    #define TM1638_STB D5
    #define TM1638_CLK D6
    #define TM1638_DIO D7

    TM1638 module(TM1638_DIO, TM1638_CLK, TM1638_STB);
    // DS3231 uses I2C - device ID 0x68
    // on Wemos mini pins SDA -> D1 and SCL -> D2
    DS3231 rtc;
    int hours;
    int minutes;
    int seconds;
    bool h12;
    bool PM;
    int data;
    RifTime t;
    char buffer[24];

    void setup()
    {
      // set up the 7-segment display
      module.clearDisplay();
      module.setupDisplay(true, 2);
      Wire.begin();
      Serial.begin(115200);

      Serial.println(F("\nDS3231 Hi Precision Real Time Clock"));

      // Fill these variables with the date and time.
      int seconds, minutes, hours, dayofweek, dayofmonth, month, year;

      // Example for april 15, 2013, 10:08, monday is 2nd day of Week.
      // Set your own time and date in these variables.
      // dayofweek = 4; // Day of week, any day can be first, counts 1...7
      hours = 14;
      minutes = 30;
      seconds = 0;
      year = 2019;
      month = 8; // month 1...12
      dayofmonth = 28; // Day of month, 1...31

      data=( hours * 10000 + minutes * 100 + seconds * 1 );

      rtc.setClock(year,month,dayofmonth,hours,minutes,seconds);
    }

    void loop()
    {
      rtc.getTime(t);
      Serial << rtc.toString(buffer) << endl;

      delay(1000); // do nothing

      module.setDisplayToDecNumber(data,4,false);

      if(seconds==60)
      {
        seconds=00;
        minutes++;
      }
      if(minutes==60)
      {
        minutes=0;
        hours++;
      }

      if(hours==24)
      {
        data=00000000;
      }

      if((data)==143000)
      {
        module.setLEDs(0x0001);
      }
      else
      {
        module.setLEDs(0x0000);
      }

    }

title: Arduino ds3231to TM1638 problems,alarm clock project

Answers: 1

body:
You set the variable `data` only in the setup function.

You also do not print out `data` to `Serial` but the output of `rtc.toString(buffer)`.

If data is not updated in the `loop` method, the display constantly shows the time you initially set in the setup method.