Arduino Switch (cas) l'état, utilisé avec entrée série

An if statement allows you to choose between two discrete options, TRUE or FALSE. When there are more than two options, you can use multiple if statements, or you can use the switch statement. Switch allows you to choose between several discrete options.

Arduino Switch (case2) Statement

This guide demonstrates how to utilize a switch to activate one of multiple LEDs depending on a received byte of data through serial communication. The drawing pays attention to serial input and activates a separate LED for the letters a, b, c, d, or e.

Circuit

Five LEDs are attached to digital pins 2, 3, 4, 5, and 6 in series through 220 ohm resistors.

To make this sketch work, your Arduino must be connected to your computer. Open the Serial Monitor, and send the characters a, b, c, d, or e, or anything else.

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:

Arduino Switch (case2) Statement schematic

Code

/*
Switch statement  with serial input

Demonstrates the use of a switch statement.  The switch
statement allows you to choose from among a set of discrete values
of a variable.  It’s like a series of if statements.

To see this sketch in action, open the Serial monitor and send any character.
The characters a, b, c, d, and e, will turn on LEDs.  Any other character will turn
the LEDs off.

Major Components in Project

Hardware Required

  • Arduino Board
  • (5) LEDs
  • (5) 220 ohm resistors
  • breadboard
  • hook-up wire

For more detail: Arduino Switch (cas) l'état, utilisé avec entrée série


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut