First Step in Arduino

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

Kim,

To get you started, here are two topics for you to research in the wonderful world of Arduino:

[debounce

[interrrupt

In addition to those pages, I suggest you research those two topics throughout the Reference, Tutorial, and Playground sections of the Arduino website.

Have Fun,

Eric ](http://www.arduino.cc/en/Reference/AttachInterrupt)](http://www.arduino.cc/en/Tutorial/Debounce)

Exactly what i’ve needed,

Thanks Eric !

You’re welcome!

It’s a pleasure helping people who are looking for a hint or a nudge in a useful direction and are willing to do their own legwork. :smiley: You’re certainly welcome to ask the next time you’re stuck.

It’s the folks who post requests that are basically “Here’s this crazy idea I had, now you folks owe it to me to do the design and coach me intensively through the build, so I don’t have to do anything but play and whine.” that bug me.

It is not, BTW, the amount of work I do that’s the important factor. If you poke around the SparkFun fora, you’ll find several threads where I’ve spent hours trying to help folks. What matters to me is that hobby electronics is a (sometimes difficult) learning process. I enjoy helping people who accept that and are looking for teaching. I, too was a beginner once (years before most of the folks here were born, I concede :wink: The “81” is my username is the year I completed my SB, not the year I was born.) and there are still many things I have yet to learn.

People who want someone on the forum to provide them with a schematic and a bill of materials should go buy themselves a kit. :roll:

Eric