I'm new to Arduino, trying to make a random number generator with pushbutton.
My questions are:
1.How can I do that,if I press the pushbutton once, then I will get one random number between 0 and 1024. After that, I want to loop from 0 to the random number and then back to 0.
2.How can I debounce the pushbutton
void setup(){
Serial.begin(57600);
pinMode(2,INPUT_PULLUP);
attachInterrupt(0,randomnumber,FALLING);
}
void randomnumber(){
int number=random(0,1024);
for(int x=0;x<=number; x++){
Serial.println(x);
delay(1000);
}
for(int y=number;y>=0; y--){
Serial.println(y);
delay(1000);
}
} void loop(){
}
Any good suggestion?
Aucun commentaire:
Enregistrer un commentaire