Hello All,
I'm trying to understand what is wrong with me and the Input Pullup!
Let me explain, I'm trying to build a dice with LED, it is supposed to start when i Hit the button.
Easy.
I am supposed to use INPUT PULLUP function but when I do the result is always the same : 1 and the Dice restart alone, over and over again with this code :
(Button between GND and Pin No 7)
int ledHautGauche = 2;
int ledBasGauche = 3;
int ledCentre = 4;
int ledHautDroite = 6;
int ledBasDroite = 5;
int buttonPin = 7;
boolean buttonState;
//=================================================
//===================== FONCTION D'INITIALIZATION =
//=================================================
void setup() {
//mise en mode OUTPUT des pins 2 à 6 et positionnement en LOW
for (int t = 2; t < 7 ; t++) {
pinMode(t, OUTPUT);
digitalWrite(t, LOW);
}
pinMode(buttonPin, INPUT_PULLUP);
randomSeed(analogRead(0));
Serial.begin(9600);
setZero();
}
//=================================================
//============================= BOUCLE PRINCIPALE =
//=================================================
void loop() {
int temp = 1;
buttonState = digitalRead(buttonPin);
Serial.print(buttonState);
delay(100);
if (buttonState){ {
int result = random(0, 6);
for (int t = 0; t < 4; t++) {
for (int nb = 0; nb < 6; nb++) {
affichage(nb);//appel de la fonction d'allumage des LEDs
delay(temp * 100);
}
temp = temp + 1;
}
for (int nb1 = 0; nb1 < result; nb1++) {
affichage(nb1);//appel de la fonction d'allumage des LEDs
delay(600);
}
delay(3000);
}
}
}
BUT, if I set the PIN7 as an OUTPUT, it is working! :o Like this :
(Button between 5v and Pin No 7)
//=================================================
//================ DECLARATION VARIABLE GENERALES =
//=================================================
int ledHautGauche = 2;
int ledBasGauche = 3;
int ledCentre = 4;
int ledHautDroite = 6;
int ledBasDroite = 5;
int buttonPin = 7;
boolean buttonState;
//=================================================
//===================== FONCTION D'INITIALIZATION =
//=================================================
void setup() {
//mise en mode OUTPUT des pins 2 à 6 et positionnement en LOW
for (int t = 2; t < 7 ; t++) {
pinMode(t, OUTPUT);
digitalWrite(t, LOW);
}
pinMode(buttonPin, OUTPUT);
randomSeed(analogRead(0));
Serial.begin(9600);
setZero();
}
//=================================================
//============================= BOUCLE PRINCIPALE =
//=================================================
void loop() {
int temp = 1;
buttonState = digitalRead(buttonPin);
Serial.print(buttonState);
delay(100);
if (buttonState){ {
int result = random(0, 6);
for (int t = 0; t < 4; t++) {
for (int nb = 0; nb < 6; nb++) {
affichage(nb);//appel de la fonction d'allumage des LEDs
delay(temp * 100);
}
temp = temp + 1;
}
for (int nb1 = 0; nb1 < result; nb1++) {
affichage(nb1);//appel de la fonction d'allumage des LEDs
delay(600);
}
delay(3000);
}
}
}
I have been working a bit too long on the project, I am not sur if I am confused or it my arduino is damaged...
Thanks for your help!