My code is NOT working, i have no idea why.

So my code, is when you press a button, an RGB LED turns from red to green and a servo moves 0­°, waits 9 seconds, red led, 90° servo.
Code:

#include <Servo.h>
int green = 5;
int red = 6;
int blue;
Servo servo;
void setup() { 
  servo.attach(9);
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  servo.write(90);
  blue = digitalRead(7);
}

void loop() {
  digitalWrite(red, HIGH);
  digitalWrite(green, LOW);
  if (blue = HIGH) {
    digitalWrite(red, LOW);
    delay(1);
    digitalWrite(green, HIGH);
    servo.write(0);
    delay(9);
    digitalWrite(green, LOW);
    delay(1);
    digitalWrite(red, HIGH);
  }
}

Edit: Fixed the way the servo moves, typed it wrong in the actual post, servo starts at 90°.
Edit: Also, i can wait like a bit until the answer, like at most 3 weeks lol

(deleted)

(deleted)

the parameter for delay(9) is in milliseconds, to have a 9 second delay use

delay(9000);

spycatcher2k: Imagine for a moment that we don't know what your code is suppose to do, or what it actually does!

Now explain CLEARLY what you want the code to do, and what it actually does (or not).

I said what my code is supposed to do, try reading, and also, your solution is giving an error...

robtillaart: the parameter for delay(9) is in milliseconds, to have a 9 second delay use

delay(9000);

Yes thanks, I'm used to using 'sleep(seconds)' in lua, thank you

spycatcher2k: blue = digitalRead(7);

Does not belong is SETUP!

Where does it belong then?

Where does it belong then?

You've got two functions and one has been eliminated - try another guess

What is 7? Is it a pin? If so, what mode is it?

It belongs just above where you use the value of blue.

How is your button wired? Do you have an external pulldown?

SkyCrafter: I said what my code is supposed to do,

But you said nothing about what it did do.

(deleted)

MorganS: It belongs just above where you use the value of blue.

How is your button wired? Do you have an external pulldown?

I have my button connected to the 5V pin, connected to pin 7 as an INPUT, idk what a pulldown is, isn't it a resistor across 5V and pin 7?

idk what a pulldown is, isn't it a resistor across 5V and pin 7?

No, that would be a pull-up. (Is it really too much trouble to type "I don't know"?)

The way things work round here is you post a schematic of your circuit. At the moment it sounds like this is wrong.

I have my button connected to the 5V pin, connected to pin 7 as an INPU

That is wrong, it will not work correctly.

Then each time you make a change to the code either from a recommendation from us or you, you post your code again so we can check it. Make a new post do not change existing posts.

GrooveFlotilla:
(Is it really too much trouble to type “I don’t know”?)

Maybe he just wants to limit the responses he gets to only those coming from kids who speak text speak and wants to avoid any answers from people like Sr engineers or anyone who actually knows their stuff and could really help.

I've completely rewrote my code and it works now.