Questions tagged [loop]

The tag has no usage guidance.

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

Stuck in While loop!

I am using 4 LDR To track the sun for solar panels. Not using servos, but linear actuators(a little irrelevant but just to give scope) my code gets stuck in this while loop as soon as it enters it, ...
1
vote
2answers
66 views

Is there a way to make a function take an exact number of clock cycles?

Is it possible to use something like a compiler directive to pad a function with do nothing instructions so that as you add lines of code or take them away it always executes in the same amount of ...
-1
votes
2answers
59 views

How do I run a function every 10th time through a loop?

I currently have a function that poles all my sensors every time through it's loop, but I want to pole one of the sensors only every 10th time. Currently there is a 10 millisecond delay at the ...
0
votes
0answers
33 views

Break a while loop with a push button (AccelStepper.h)

Disclaimer: This is my first Arduino project. Background: I am building a "rapunzel tower" lantern for my daughter: the witch pays a visit to Rapunzel meanwhile my daughter can read a book (or still ...
0
votes
0answers
48 views

While Loop does not stop when condition is false

Here's the code: void loop() { while (1 == 1) { ObsLeft(); while (SeeLeft < 50 || SeeLeft == 50) { Urong(); ObsLeft(); if (SeeLeft > 50) { Hinto; ...
0
votes
2answers
73 views

problem with decrement in a loop

I am trying to write a sketch wherein the led brightness increases in increments of 15 until it reaches 255. At that point I want to make decrements of 15 until it reaches 0. The increment part of the ...
0
votes
1answer
36 views

Servo Program Questions

Hi programming in arduino, I am trying to get a nested for loop inside a for loop with industrial servo which used PUL +- DIR+- (bought motor off amazon). My goal is to get the puls delay to increase....
1
vote
2answers
83 views

Arduino uno wifi rev2 stuck inside loop

It might be a stupid question but I can't figure it out. While running the code below. I want to open the box when the code matches the code in API. This all works. I can even close the box afterwords....
0
votes
5answers
105 views

How can an Arduino do multiple actions in parallel without interfering with each other?

I am working with my son (9) and we are having a great time learning. But, we've run into a problem and could use your help. We have two separate loops that we want to run without interfering with ...
0
votes
2answers
101 views

How to stop loop in the serial monitor?

I want to make a serial program with input from the serial monitor and show each character with its binary and ASCII codes. At the end of the program, I want to show the whole message sent from the ...
0
votes
1answer
41 views

Using the same variable between if-statements within loop()

I wonder if there is a good way to use the same variable value between two different if-statements within the loop(). Within the Servomotor section of the code, I want to use the value from the first ...
0
votes
1answer
26 views

Running in loop or once according to a slide switch position

I have a question. I made a system which includes a servo, a stepper and a wiper motor :) All these parts has one job to do and I can code it. But, I want to make 2 modes in this system Single ...
-1
votes
1answer
27 views

ARDUINO flashing lights

I'm making a circuit with my Arduino so that when it receives a '1' or '2' or 'a' it turns on or off the LEDS. But I wanted the lights to flash and do not know how to do loops in loops or if that's ...
0
votes
1answer
34 views

Receive socket when in loop arduino (Interupt a while loop with a socket)

I'm currently working on an arduino project. Were the arduino is communicating with a NodeJS server via web sockets. The socket connection is working fine and has no problems. But the problem I ...
0
votes
1answer
36 views

Some Blocks of Code gets stuck in a loop, I do not know why

The code below Gets stuck at function "Led Off?" & "Check button". I'm using Blockyduino editor. The check button code was intended as a toggle switch for the lights. When I deleted "Led Off?" and ...
0
votes
0answers
32 views

Stepper motor only rotates once in a loop?

I am quite new to this , I am trying to program two motors , aStepper and bStepper. I want the program to rotate aStepper then rotate the bStepper and when that is done rotate aStepper again , and ...
0
votes
2answers
64 views

while(1) inside if conditional

if (!MDNS.begin("esp8266")) { Serial.println("Error setting up MDNS responder!"); while (1) { delay(1000); } } I know this will result in an infinite loop if the if conditional is ...
0
votes
0answers
55 views

Need sugestion to improve my arduino sketch

I want my code to blynk friendly by avoiding while condition in loop or flood error as mention by blynk. But , i m unable to do so.whenever i try to call function outside loop , it get stuck in first ...
0
votes
0answers
54 views

Stuck in a loop when reading from EEPROM, works if I clear it first

EDIT: The problem was caused by storing a pointer in the EEPROM. Thanks to @KIIV for helping out Sorry for the enormous of wall of text, I'm trying to pare it down a bit. I have two Arduino Megas ...
0
votes
0answers
74 views

analogWrite and For Loop Bug

I wrote the following code that outputs a packet data structure bit by bit. I do this using two for loops. These two for loops should always terminate, but the presence of analogWrite() makes them ...
0
votes
2answers
54 views

Running loop for a specific time period

I currently have a loop that runs without a time condition: unsigned long previousMillis = 0; // will store last time LED was updated int WET=4;//wet line int DRY=5;//dry line int Inhale=1000;...
0
votes
2answers
40 views

Syntax for stopping loop until the condition has made false

I am taking reading from temperature sensor and from that data. I have to control 3 LEDs. Lets consider LED1, LED2, LED3. If temperature range between 0-20 I have to HIGH LED2. else if ...
2
votes
1answer
144 views

Run light sequence function continuously in if statement

My goal - run light sequence function on momentary button press (button 2) continuously until another of the 3 momentary buttons are pressed. /* switch * * Each time the input pin goes ...
0
votes
1answer
37 views

How can I stop a loop when using a servo with a Key input?

How can I stop my following code using a key? Basically the code should run the servo in a loop if "t" is pressed and stop the loop if "s" is pressed. #include <Servo.h> Servo myservo; // ...
0
votes
1answer
49 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
34 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
34 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
31 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
30 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
40 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
25 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
70 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
26 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
311 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
50 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
77 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
154 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
64 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
57 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
123 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
64 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
65 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
96 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 ...
4
votes
5answers
2k views

Simultaneous 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
2k 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
50 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
53 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
302 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
44 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
111 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 ...