If statement loop and break issues

Hello I am a new poster to this forum but have used it a while. I am a high school engineering teacher and have students working on electric bridges (well not yet I want them to learn the L298N etc first).

GOAL:
I am trying to get a fragment of my code to run the motor (initiated by a button) for a set time at full speed, then hold the code at a lower speed until another trigger (button 2) tells it to go back down. So far I have been able to loop a constant motor speed on full and initiate a stop but I can not seem to get the slower speed to loop properly.

Code is from scratch so I hope I match what I have in the classroom. (enable is hooked up to digital 13, and direction 1 and 2 are 12 and 11).

I have tried using a second loop function but that makes the entire IF statement repeat not ONLY the second part of it

const int speedcontrol = 13;
const int yellowwire = 12;
const int redwire = 11;
const int button = A0;
const int button2 = A1;

void setup(){
//we can assume everything here are the proper inputs and outputs as well as the serial monitor //beginning
}

void loop(){

int bytes = analogRead(button);
int bytes2 = analogRead(button2);

if (bytes == 1023){
analogWrite(speedcontrol, 255);
digitalWrite(yellowwire, HIGH);
digitalWrite(redwire,LOW);
Serial.println("clockwise");
delay(1000);
//HERE IS WHERE I WANT THE THING TO REPEAT with motor at slower speed to just hold bridge in place UNTIL CHANGED)
analogWrite(speedcontrol, 170);
digitalWrite(yellowwire,HIGH);
digitalWrite(redwire,LOW);
//repeat ends here for the loop to hold draw bridge up until other button pushed to allow back down
}

}

Yeah that is the problem I need to not have the code blocked so that the other button can tell the motor to let the bridge back down

//we can assume everything here are the proper inputs and outputs as well as the serial monitor //beginning We can?

Please remember to use code tags when posting code.

Pin 13 is not a PWM pin, on UNO anyway.

the reason some of the names in the code are not there yet is I am building the students up to that stage step by step. They will be renamed up down but I want them to think about how the motor moves to do so and then also my goal essentially is to have one of the motor turns turn the bridge up which occurs at full speed and then hold it up there because gravity pulls it down. If it stays on full speed the bridge keeps moving too far up and will try to break itself apart. (I understand I could use a second set of sensors here to stop and have hold but I want to teach and learn myself how to fully control the motors). Therefore to be put on a lower power from the enable to then keep holding until I say initiate coming down with the other button. Sorry about that and the declarations of the

pinModes for the buttons are all inputs and the 3 on the l298n are outputs (for assuming the setup part)

and thanks for all the help and also recopy of full code with repeat that is in wrong place

const int button = A0;
const int button2 = A1;
const int speedcontrol = 13;
const int yellow = 12;
const int green = 11;

void setup() {
// put your setup code here, to run once:
pinMode(button, INPUT);
pinMode(button2, INPUT);
pinMode(speedcontrol, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int bytes = analogRead(button);
Serial.print(bytes);
Serial.println(" bytes");
int bytes2 = analogRead(button2);
Serial.print(bytes2);
Serial.println(" bytes2");

if (bytes == 1023 and bytes2 < 1023) {

analogWrite(speedcontrol, 255);
digitalWrite(yellow, HIGH);
digitalWrite(green, LOW);
delay(1000);
Serial.print(" clockwise");
analogWrite(speedcontrol, 0);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
delay(1000);
Serial.println(" off");

}

if (bytes2 == 1023) {loop();{
analogWrite(speedcontrol, 255);
digitalWrite(yellow, LOW);
digitalWrite(green, HIGH);
Serial.println("counterclockwise");
delay(1000);
}

}

 if (bytes2 == 1023) {loop();

Recursion.
Bad.

Please remember to use code tags when posting code

Why not
int bunnyRabbits = analogRead(button);?

It makes about as much sense.

Ok so clearly some of you guys do not understand scaffolding. I understand all the conventions mentioned above but for students who are not in a super high level academic school do the best they can. I am not teaching them convention that is supposed to be on a professional level. I understand that buttons are digital and not analog. I also understand the whole aspect of setting them to be reversed to low to activate something. I am simply asking for a second solution for something as this is supposed to peaks students interests to go into this in college.

@Delta_G your arrogance and acting in the manner you do is the reason all of our coders are outsourced from INDIA because people actually want to teach their students in that country instead of put them down.

I WILL NOT BE POSTING HERE EVER AGAIN

sp. "piques"

as far as that last part with the loop it was an experiment and the greater than symbol was an accident that the student made again using the student code but sure blame the teacher who does know what he is doing and does not have all the time in the world for every small symantic and was looking for help.

I thought better of engineers in our country.

ALSO THAT ADC ERROR YOU MENTIONED IS GARBAGE AND I ALSO ALREADY TESTED WITHOUT IT. JUDGING FROM THE LACK OF HELP I WILL GO THE ROUTE OF HOW A 3d PRINTER LOCATES ITS HOME SPOT

AND YES MY MAJOR WAS IN THE ENGINEERING DESIGN PROCESS NOT ARDUINO MAJORLY BUT AS A TEACHER YOU TEACH STUDENTS SOME BASICS OF THINGS YOU MAY NOT KNOW. IF YOU TRULY WANT TO HELP THIS COUNTRY STOP BEING SUCH A CONDESCENDING KNOW IT ALL

AND YOU SHOULD ALLOW STUDENTS TO ASK QUESTIONS WHEN THEY ARE LEGITIMATE YOU SHOULD BE ASHAMED FOR THAT TOO

and I had all these projects be successful last year and forgot one bit of code so lets just be a Donald on here.

sp."semantic"

ALSO THAT ADC ERROR YOU MENTIONED IS GARBAGE

Err, nope.

Like I said this is why all our coding jobs are outsourced to India

Matthew_Sudberg:
Like I said this is why all our coding jobs are outsourced to India

I think I'm beginning to agree.

clearly some of you guys do not understand scaffolding

It should be sturdy, secure and built on firm foundations.
It should be capable of being removed without affecting the edifice constructed.

Matthew_Sudberg:
I WILL NOT BE POSTING HERE EVER AGAIN

Ok.

Matthew_Sudberg:
I thought better of engineers in our country.

Which country might this be? This is a global forum.

Matthew_Sudberg:
Like I said this is why all our coding jobs are outsourced to India

You really do have a short temper for a teacher. And maybe you should think about how you take constructive criticism.