Questions tagged [loop]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
24 views

How can I assign a variable to a function output in Arduino?

I'm trying to assign the output of my function (which adjusts a DAC output) to a variable so I can print and display it in my serial monitor. Here's the code #include <Wire.h> #include <...
0
votes
1answer
14 views

Wire SlaveReceiver : will the registered function in onRecieve interrupt/conflict with loop block?

I am currently researching on I2C, and I made a configuration that has MasterWriter that transmits data to a SlaveReceiver that will store the data received from Master, into an SD card, and then ...
0
votes
1answer
28 views

What features of the Arduino framework will fail if I use my own infinite loop in favor of the standard loop()?

I have a strong urge to replace the framework-provided loop() function with my own like so: __attribute__((always_inline)) inline void fastLoop() { } void setup() { // Performing setup here... ...
0
votes
0answers
20 views

Accel Multi Stepper - Array for timelapse operation

I am trying to run 2 cameras for timelapse. I can do this with a single stepper: void doSteps(long steps) { calcSpeedStepper(); digitalWrite(sleepPIN, HIGH); stepper1.setCurrentPosition(0); ...
0
votes
0answers
27 views

Arduino and NodeMCU problem with wifi conecction

Hello guys I am beginner with micro controllers but I am trying to make a simple IoT with Arduino and NodeMCU as WiFi. I was using this tutorial and code https://www.electronicshub.org/wifi-controlled-...
2
votes
1answer
37 views

LED dimmer not fading out

I'm trying to make an LED go from no brightness to max and back down on a loop and I've encountered a problem I can't seem to crack. The LED will go to maximum brightness steadily as it should but ...
0
votes
0answers
24 views

Loop failure after unset amount of time

I am building an art piece that takes in input from three rotary encoders and two buttons. and outputs data to a large neopixel display and 2 large 4 digit seven segment displays. The displays are ...
0
votes
1answer
48 views

Arduino programming with multiple loops

I was trying to program my Arduino (along with a connected motor controller) to switch from cycle to cycle with this program. It doesn't seem to work however. There's still plenty of storage space ...
0
votes
1answer
24 views

There's an error I don't know how to fix

I basically have a bread board with an rgb led and a peizo buzzer with a photocell. I have the codes for both. If I put a code for the rgb, it works. If I put the code for the peizo, it works. Once I ...
0
votes
1answer
53 views

Passing variables for a PID in an interrupt

I'm needing to pass variables from my timerIsr() function to my loop() function. I have little experience with the Arduino language, I'm mostly familiar with Python so this has been quite difficult ...
0
votes
1answer
44 views

Class help - Same Object types seem to mix values with each other

I'm having issues with two objects of the same class type. I have a LED class, which has functions to fade in and out, a LED. In my code, I create two objects of this class, and on the board, I fade ...
0
votes
1answer
47 views

Run function when triggered

I'm trying to create a motion/fall sensing device. I have a sensor that continuously checks if motion and fall is detected in void loop(). If both motion and fall are detected, then I'd like to send ...
-1
votes
2answers
78 views

Setting a pin to a continous wave output

Is there any way in Arduino to set a particular pin(pwm or not) to just generate a square wave out of the desired pin? For instance, I want to have two pins on my Arduino Uno that output two square ...
0
votes
1answer
61 views

How to write a more compact ANDed conditions with if statement?

I'm working on the rfid module and found an example that do it well. But it has a long testing the 5 bytes of the rfid received bytes, and I've tried to write it in a more compact way. I did it with ...
0
votes
2answers
43 views

Blinking LED's at changing rate

I am trying to blink two LED's, starting at slow rate then increasing to fast s follows: 1 on, 1&2 on, 2 on, 1&2 on, 1 on, etc. The blinks go through the loop twice then speed up and repeat ...
1
vote
2answers
61 views

How do you make a switch case run until another serial input is detected?

I am trying to create a Traffic Light Controller. There are three modes to the controller: Mode 1 - the traffic light operates RED-YELLOW-GREEN-YELLOW and should repeat * (The other modes are not ...
0
votes
0answers
52 views

Does not execute code on loop;only run code of set up

only display this: ARDUMOTIVE ArduinoBased compassn.Compass Michalis Vas. nothing else. I tried another Arduino Uno, Mega, Nano, but execute only set up. Display is working.No compiler errors.Sketch ...
0
votes
1answer
61 views

Weird problem with arduino

I wrote the code below and the result is not what I expected at all! I'm not sure why it's happening! void setup() { // put your setup code here, to run once: Serial.begin(9600); } const uint8_t ...
-1
votes
2answers
42 views

I need help makeing a light flash while a stepper is constantly moving

The starter code. #include <Stepper.h> const int stepsPerRevolution = 120; // change this to fit the number // for your motor of steps per revolution // initialize the stepper library on ...
3
votes
5answers
1k views

Simultanous button reading?

I'm currently working on a project that requires that I simultanously check the state of two buttons. Each button HIGH state is assigned to one if loop. Here's the basic concept: void loop() { ...
0
votes
2answers
1k views

Reading Multiple Analog Input Pins

I am having a bit of trouble trying to read multiple Analog Input Pins (A0 and A3, in this instance). I am using a Pololu A-Star 32U4 LV Robot Controller (https://www.pololu.com/product/3116), and am ...
0
votes
1answer
33 views

How can I pulse a stepper motor whilst also wanting to handle other tasks?

A Polulo A4988 driver board listens for a LOW -> HIGH pulse on a digital pin to step a stepper motor. A simple way to pulse this with a delay of say 100μs, is to use the delayMicroseconds function:...
-1
votes
2answers
49 views

Confusion between switch and if?

Following code is to control two LEDs for on and off by two dedicated push buttons. I have used if() for each condition and I was not comfortable writing this code, as I could feel, it can be better ...
0
votes
1answer
167 views

ESP32 stops looping after 2 loops

My code: https://pastebin.com/UmdK33U2 I made a menu so I can send commands. First I connect to the wifi and then I send the command to send a request. Then when it detects the key datos(); goes ...
0
votes
3answers
40 views

If a condition is ever met I want to run a loop permanently

I am trying to run an LED to do SOS in morse code if a temperature is over 20 C and motion is detected, but I want it to continue doing SOS even after the motion goes away or the temperature comes ...
0
votes
1answer
42 views

Global Variable does not Change when Value is set within Boolean Function

I have a boolean function which contains a string. In my main project this string is extracted from a website using an ESP8266 which is compatible with the Arduino IDE. I need to convert this string ...
0
votes
1answer
66 views

If/Else Statements on Arduino not executing

I have a bit of code below, the problem is only the first 'if' statement will execute when called on. When I call on u, q, or any of the other if statements it will go straight to the else and not ...
1
vote
2answers
246 views

Button to exit a running loop

I have a very basic circuit setup: A button connected to pin 2 An LED connected to pin 9 Desired Functionality: When the button is pressed, the user can toggle through 4 LED patterns. The ...
0
votes
4answers
77 views

help with a loop

I recently got into programing and I'm making an alarm. I cant figure out how to make a buzzer loop. I have two blinking LED's and two fading ones. Now I plan to have sound and it won't work. It only ...
1
vote
4answers
116 views

for() loop doesn't seem to break?

So I'm quite new to the whole Arduino coding but constructed a sketch that does work, but I think it doesn't work properly. So I'd love to get some advice on how to improve it. This script is ...
0
votes
2answers
62 views

For loop broken? [closed]

This is a pseudo code from my LED cube project void loop(){ //switch( map(constrain(analogRead(pt),10,1020),10,1020,1,4)); - for select pattern //show(1); for(lp=128;lp>=1;lp = lp/2){ ...
3
votes
1answer
85 views

Correct way of having loop end when required?

I'm brand new to Arduinos. I'm currently trying to modify a script from here which at the moment, simply turns an LED on or off depending on which HTTP GET request it receives. However, I want to ...
0
votes
1answer
26 views

Variable that holds the users input doesn't empty itself, so the program only works once

This code seems to function, but only works once before I need to press the reset button. Otherwise, it repeats the same error message. It might have something to do with emptying the String variable. ...
0
votes
2answers
812 views

Arduino - Button to start / stop loop

So basically I'm trying to create a device where when I push a button it starts a loop. When I push this button again, it stops the loop. Right now I have it logged to serial. It starts up correctly ...
0
votes
1answer
439 views

ESP8266 Stops Working After A While (Unknown Problem)

have an esp8266. i'm trying to create a DDNS updater. it has to wait 5 min then do a GET request to a URL. Here's my code: /* Code For DNS Updater.*/ #include <ESP8266WiFi.h> #include <...
0
votes
1answer
64 views

Averaging input from multiple input over a fixed amount of time (estimated)

I am trying to average input values for a number of inputs and have it then store those averages into a string to write to a txt doc on a sd card. I am using: // read 6 sensors and append to the ...
0
votes
2answers
242 views

Arduino Switching Between Loops IR Remote

I've been working on an LED strip project. However, I've come to a stand still at the moment. Within the program I am wanting to assign different lighting effects to each button on my IR remote. I am ...
0
votes
1answer
106 views

How to stop sending the last received char of UART echo function?

I developed a code for uart based ISR with linear buffers, the problem is that it keep sending the last received char in Arduino IDE. Here's the application code: #include "uart_new.h" void setup() ...
0
votes
1answer
280 views

Breaking out of a while loop using IR remote for neopixel

I've been piecing together various lighting effects. I am wanting to have each lighting effect loop until another button is pressed to trigger another lighting effect. I've come to a bit of ...
0
votes
1answer
69 views

Optimal and Save Water Pump Control

I'm using an Arduino Micro, a 12 V water pump and a print relay to water a plant. A water level switch monitors the the water tank to make sure the water pump does not run dry. I tried different ...
1
vote
2answers
247 views

How can I loop my code? For example after 30 minutes?

So I have this code which records the temperature and humidity using a DHT22 sensor. After it get's the values it then sends it to a webpage using PHP $_GET method, where that gets imported into a DB ...
0
votes
1answer
60 views

Should I use a loop instead of an If statement?

I have a simple sketch that tests input from 2 touch sensors and outputs to 2 relays (if a sensor is touched, trigger the respective momentary relay). It has been a bit quirky to say the least. ...
1
vote
1answer
358 views

How to stop a loop when using attachInterrupt to catch the change of a button

This what the program does: There is 1 button to start/stop the engine, when the motor is running the green LED will go on, when stopped the red LED is on. The second button is used to change ...
1
vote
2answers
27 views

put_index = (put_index + 1) % 100; [closed]

Can someone interpret the code in the Title line for me? Specifically the function of the "%" sign? It is a line having to do with a 100 element circular buffer.
1
vote
0answers
71 views

Storing random and different values of millis() while inside a loop? [closed]

Is it possible to store a value of time while you're inside a loop? Entertain the condition: if (condition && value > 0) { timeTrans = millis() + 2000; timeTrans - millis() = value; } ...
0
votes
2answers
95 views

Is a variable declaration inside a loop static declaration or dynamic?

while(condition){ Object object = new Object(); } So my question is, will each iteration would create a different object in different memory location or it will overwrite the once created object ...
1
vote
2answers
212 views

What's wrong with infinite loops inside loop()?

I wanted to run the following code as something similar to Tone or pwm. However for some reason that I am unable to seek it doesn't work. #define WAIT 3200UL void setup() { DDRB |= B00000001; // ...
0
votes
1answer
98 views

Problem with action that should happen in loop(continuously)

I’m using WeMos D1 R2 and latest Blynk library and app. I am also using Arduino IDE 1.6.13. I am trying to read a button from the app, which works fine, but i want to read it continuously. Through the ...
0
votes
0answers
141 views

Loop being restarted before it finishes?

I have a Loop process that does various I/O and delay operations and also logs to the serial port so that we can review the activity. We what I think is the loop being interrupted. Normally the ...