Hi Folks,
i’ve received my Arduino Uno yesterday and i’m in my testing period ^^
I’ve tested basic sketch and all working fine. for fun i’ve created a sketch on mjy own and i’m in front of a little problem in term of usablility.
I’ve mounted on my bread board a little button with a pull-up resistor (5.6kohm ) and i’ve used this code :
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int NbFlash = 0;
String Serialtext = "un de plus : {0}";
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
//Ajouter un Flash à la lumière;
NbFlash++;
Serial.println(Serialtext.replace("{0}",NbFlash));
}
Flashleslumiere();
delay(500);
}
void Flashleslumiere()
{
for(int i = 0; i < NbFlash; i++)
{
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(50);
}
}
My problem at this point, is that i have to hold the button for a second to repond. Ok Fine i undertsand it’s all about the delay i’ve put here but how could i code this tiny blink code for behing more responsive.
( the idea with the code i’ve writed , is that for each button press the light will blink one time more and have a break and continue )
Thanks in advance,
Kim