Chat
Welcome to Flux
Treat Flux like your intern. Tell it what you'd like to build and it'll get to work. You can also ask it questions, brainstorm ideas, and teach it your preferences. Learn More
Ready.
tone() en Arduino para generar sonidos en el buzzer, la función digitalWrite() para encender y apagar los LEDs, y la función digitalRead() para leer el estado de los botones. Es importante recordar que tu placa Arduino necesita estar conectada a tu computadora para que puedas cargar el siguiente código.C
const int Buzzer = [BUZZER_PIN]; // Cambiar [BUZZER_PIN] por el pin real del Buzzer en Arduino Leonardo const int buttonPins[NUM_BUTTONS] = {[SW1_PIN], [SW2_PIN], [SW3_PIN], [SW4_PIN]} ; // Cambiar [SWx_PIN] por los pines reales de cada botón. const int ledPins[NUM_LEDS] = {[D1_PIN], [D10_PIN], [D11_PIN], [D12_PIN]} ; // Cambiar [Dx_PIN] por los pines reales de cada LED. bool buttonStates[NUM_BUTTONS]; // Para almacenar el estado actual de cada botón
setup(), también vamos a tocar la melodía inicial en esta función:C
void setup() { pinMode(Buzzer, OUTPUT); for (int i = 0; i < NUM_LEDS; i++) { pinMode(ledPins[i], OUTPUT); pinMode(buttonPins[i], INPUT_PULLUP); } playStartupMelody(); } void playStartupMelody() { // Ejemplo de melodía de inicio, puedes cambiarla a tu gusto tone(Buzzer, 440, 500); delay(500); tone(Buzzer, 494, 500); delay(500); tone(Buzzer, 523, 500); delay(500); noTone(Buzzer); }
loop(), revisamos el estado de cada botón. Si el botón está presionado, encendemos el LED correspondiente y generamos un sonido en el buzzer. Cuando se libera o no se presionó, apagamos el LED:C
void loop() { for (int i = 0; i < NUM_BUTTONS; i++) { buttonStates[i] = !digitalRead(buttonPins[i]); // Invertir la lectura porque los pull-ups hacen que el estado en reposo sea HIGH if (buttonStates[i]) { digitalWrite(ledPins[i], HIGH); tone(Buzzer, 440 + i * 100); // Genera diferentes tonos para cada botón } else { digitalWrite(ledPins[i], LOW); } } noTone(Buzzer); // Apaga el buzzer cuando no se presiona ningún botón }
[SWx_PIN], [Dx_PIN] y [BUZZER_PIN] con los números de los pines de Arduino Leonardo a los que están conectados tus botones, LEDs y buzzer.buttonPins[0] enciende el LED en ledPins[0] y así sucesivamente.Reviews
Inspect
Obliged Silver P.K.E. Meter
Controls
Properties
Availability & Pricing
| Distributor | Qty 1 | |
|---|---|---|
| Digi-Key | $4.65–$8.59 | |
| LCSC | $4.71 | |
| Mouser | $8.59 | |
Assets
Welcome 👋
Flux helps you build PCBs faster with an AI teammate!
Create your account to collaborate, stay updated, fork your own version, and get instant answers from our AI agent.
juanfelipeah
copilot
juanfelipeah
juanfelipeah