Using an initial loop to count rotation and subsequent loop to copy the value.

Hi all.. I'm new to programming and need some help with sub loops.

I want to wind tape onto a reel to various diameters. The idea is to run an initial loop with a counter till I get the required size then store the value to use in a sub loop for production.
I would need a manual input pin when the correct size is obtained to store the count and a second input pin to run the second loop for production as a reset.

I have the basic counter setup as shown below but now stumped..

/*

  • Counter
    */
    int ledPin = 13; // choose the pin for the LED
    int switchPin =A5; // choose the input pin (for a pushbutton)
    int val = 0; // variable for reading the pin status
    int counter = 0;
    int currentState = 0;
    int previousState = 0;

#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// 1-neg,2-pos,3-var/pos,4-12,5-neg,6-11,11-d5,12-d4,13-d3,14-d2

void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(switchPin, INPUT); // declare pushbutton as input
Serial.begin(115200);
lcd.begin(20, 4); //lcd.begin(columns, rows)
lcd.setCursor(2,0); // Position cursor on line x=3,y=1

}

void loop()
{
val = digitalRead(switchPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, HIGH); // turn LED on
currentState = 1;
}
else
{
digitalWrite(ledPin, LOW); // turn LED off
currentState = 0;
}
{
if(currentState != previousState)
if(currentState == 1){
counter = counter + 1;
lcd.print("Revolutions");
lcd.setCursor(5,2);
lcd.print(counter);
delay(2000);
lcd.clear();
}
{
previousState = currentState;

}

}}

Where are the code tags you were supposed to use?

Why
does
all
of
your
code
start
in
column
one?

Your silly use of currentState, which exactly mirrors the value in val, is pointless.

The name switchPin is meaningless. OK. It tells us that there is a switch attached to that pin. But, so what? We have no idea what the switch is for.

Your poorly indented, improperly posted code does something. You forgot to say what it actually does.

You expect it to do something. What that is is not clear.

First time user so expect the worst. Managed to get the thing to count and display and will work on cleaning it up and re post.
What is the direction for creating the sub loops.

What is the direction for creating the sub loops.

You need to explain this question better.

What causes the initial number of rotations to be counted? If that happens in setup(), and loop() isn't called until that happens, then loop() already does all the looping needed.

If that happens in loop(), how, on any given pass through loop(), with the Arduino know whether it is winding the initial reel, and counting rotations, or winding a subsequent reel, rotating it n number of times?

What is driving the reel? Is it a stepper motor?

What, exactly, are you counting? What IS connected to the switchPin?

I have a fixed 180 rpm motor winding tape to a reel. The counter is a IR switch energised when a white band passes on the black pulley indicating each revolution.
The tape is measured from the inside of the reel to the OD of the tape being wound up which is the critical width and at the start of each job the first one is vernier measured.
At this point I would want the counts to be recorded once I have reached the required size possibly using a manual push button..
The second part is to push a start button duplicating the counts for the number of units I require for that particular size tape.

It sounds like you need to organize your code to recognize different states. Use a variable to record which state you are in - either counting turns or using an existing count. Maybe have a variable called windingState that could have the value 'C' for counting or 'P' for production.

When in the counting state the system will keep incrementing a value until it is told to stop. When in the production state it should take a copy of the count and decrement it until it reaches 0.

...R

That will work methinks... sounds logical..
Thanks for the input.