Bouton poussoir -> Bouton On / Off

Bonjour je n'ai pas de bouton On / Off alors j'aimerais en créer un à l'aide d'un bouton poussoir, j'aimerais qu'un LED s'allume en appuyant un fois et qu'elle s'éteigne en rappuyant dessus.
J'ai utilisé une digital de ma carte Arduino UNO en Entré et une digital en sortie...
Mais le problème est qu'elle ne s'allume pas du tout :slightly_frowning_face:

voici mon code:

void setup()
{
pinMode(3, OUTPUT); //3 est une broche de sortie
pinMode(7, INPUT); // 7 est une broche d'entree
}

void loop()
{
int pin7 = digitalRead(7); // Lecture de l'entree 7 et sockage du résultats dans test

if(pin7 == HIGH and 3, OUTPUT == LOW) // Si pin7 est à l'état haut et pin3 est à l'état bas
{
  digitalWrite(3, HIGH); // Allumer pin3
}
if(pin7 == HIGH and 3, OUTPUT == HIGH) // Si pin7 est à l'état haut et pin3 est à l'état haut
{
  digitalWrite(3, LOW); // Eteindre pin3
}
}

Voici un exemple tiré du dossier "Exemple" dispo dans l'IDE :

/*
  Button
 
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 2. 
 
 
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 30 Aug 2011
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/Button
 */

// 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

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
}

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) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}

Merci d'avoir répondu mais la LED reste allumé uniquement lorsque je maintient le bouton poussoir enfoncé, je voudrait quelle reste allumé en appuyant une fois sur le bouton et qu'elle s'éteigne en rappuyant une nouvelle fois sur ce bouton.

Faudrait étudier les circuits de base ... La ton pin est flottant quand y'a pas d'appui

Oui, je me suis trompé dans le câblage mais le code ne fonctionne toujours pas...

Avec celui de jean-françois ?

Avec le code de Jean-françois, la LED reste allumé uniquement lorsque je maintient le bouton poussoir enfoncé, je voudrait quelle reste allumé en appuyant une fois sur le bouton et qu'elle s'éteigne en rappuyant une nouvelle fois sur ce bouton.

celui la
Fonctionne

const int buttonPin  = 2;    
const int ledPin     = 13;   
 
int buttonState      = 0;    
int lastButtonState  = 0;     
int ledState         = 0;   
 
void setup() {
  pinMode(buttonPin, INPUT); 
  pinMode(ledPin, OUTPUT);  
}
 
void loop() {

  buttonState = digitalRead(buttonPin);
 

  if (buttonState != lastButtonState) {
    

    if (buttonState == 1) { 
      if(ledState==1) ledState=0;
      else            ledState=1;         
    }
    

    lastButtonState = buttonState;
  }
  

  digitalWrite(ledPin, ledState);
  

  delay(20);
}