So, I am recently new to this programing thing and I was doing pretty well, but I ran into an issue.
I am working on a project for my Destination Imagination team where we are trying to turn on a LED strip with a button. I am working on the code, but I am having a hard time.
I decided to hack a simple flashing code, since we are trying to make the strip flash when the button is pushed. While testing different codes and hacks I ran into these problems:
-
The strip kept flashing, and when the button was pushed, it would flash faster
-
When I would leave the flashing without button alone, it would randomly start to flash faster
And the problems I am currently facing:
-
The lights would flash even though I wasn't pressing the button, and when I did nothing happened
-
The lights wouldn't come on in the beginning (yay), but when I pressed the button, they didn't go on (not so yay)
The code I was using for equal amounts of flash without button is this one:
int ledPin = 13;
int button = 2;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(button, INPUT);
}
delay (30000)
void loop(){
int button_status = digitalRead(button);
if (button_status = HIGH){
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
if (button_status = LOW){
digitalWrite(ledPin, LOW);
}
}
And the code from when it wouldn't turn on at all was this:
int ledPin = 13;
int button = 2;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(button, INPUT);
}
void loop(){
int button_status = digitalRead(button);
if (button_status = HIGH){
digitalWrite(ledPin, LOW);
}else{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
}
Can anyone help please???