-1
I don’t know why, but the leds light up even if I don’t press the button.
int button = 12;
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
int buttonState = 0;
long randNumber;
void setup(){
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(button, INPUT);
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop(){
if (digitalRead(button) == HIGH){
buttonState = 1;
randNumber = random(1, 7);
delay(100);
Serial.println(randNumber);
if (randNumber == 6){
seis();
}
if (randNumber == 5){
cinco();
}
if (randNumber == 4){
quatro();
}
if (randNumber == 3){
tres();
}
if (randNumber == 2){
dois();
}
if (randNumber == 1){
um();
}
delay(5000);
zero();
buttonState = 0;
}
else{
zero();
buttonState = 0;
}
}
void seis()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
}
void cinco()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
}
void quatro()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
void tres()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
}
void dois()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
}
void um(){
digitalWrite(led1, HIGH);
}
void zero(){
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}