Arduino Uno R3 Shield Template 31vK
Controls
Properties
Availability & Pricing
Distributor | Qty 1 |
---|
Assets
id=Arduino UNO 3D
id=Arduino UNO R3 shield - Shape
id=Arduino Uno R3 Shield Template-removebg-preview
Simulation
if (Serial.available()) {
char ch=Serial.read();
if(ch >= '0' && ch <= '9')
{
valor=(valor*10) + (ch-'0');
Serial.print(ch);
}
else if (ch==10 || ch==13)
{
analogWrite(7,valor);
velocidad = (motor, map(ch, 0, 1023, 0, 100));
Serial.println(" ");
Serial.print("INTRODUCE VALOR DEL PWM (0% - 100%");
valor=0;
}
int valorPot = analogRead(pinPotenciometro);
velocidad = (motor, map(valorPot, 0, 1023, 0, 100));
if
condition: The statement if (modoTeclado = 1)
sets modoTeclado
to 1
instead of checking if it's 1
. Use ==
for comparison.map
function is currently misused. The line velocidad = (motor, map(ch, 0, 1023, 0, 100));
tries to map the character ch
, which doesn't make sense here since map
requires a numeric value.analogWrite
and map
: Ensure you are using the map
function properly to scale input values correctly for PWM.valor
to accumulate digits from the serial input is correct; however, clearer resetting of valor
might help reduce errors.Key Changes:Cpp
const int pinSelector = 4; const int pinLedVerde = 13; const int pinLedRojo = 12; const int pinPotenciometro = A0; const int motor = 7; int velocidad = 0; int valor = 0; void setup() { pinMode(pinSelector, INPUT); pinMode(pinLedVerde, OUTPUT); pinMode(pinLedRojo, OUTPUT); pinMode(motor, OUTPUT); Serial.begin(9600); Serial.println("INTRODUCE VALOR DEL PWM (0% - 100%)"); } void loop() { bool modoTeclado = digitalRead(pinSelector); if (modoTeclado == 1) { if (Serial.available()) { char ch = Serial.read(); if (ch >= '0' && ch <= '9') { valor = (valor * 10) + (ch - '0'); Serial.print(ch); } else if (ch == 10 || ch == 13) { // Ensure the value is between 0 and 255 for PWM int pwmValue = map(valor, 0, 100, 0, 255); analogWrite(motor, pwmValue); velocidad = valor; Serial.println(" "); Serial.println("INTRODUCE VALOR DEL PWM (0% - 100%)"); valor = 0; } } } else { int valorPot = analogRead(pinPotenciometro); // Map 0-1023 to 0-100 and then scale to 0-255 for PWM. velocidad = map(valorPot, 0, 1023, 0, 100); } if (velocidad > 0) { digitalWrite(pinLedVerde, HIGH); digitalWrite(pinLedRojo, LOW); } else { digitalWrite(pinLedVerde, LOW); digitalWrite(pinLedRojo, HIGH); } analogWrite(motor, map(velocidad, 0, 100, 0, 255)); delay(250); }
if
statement if (modoTeclado == 1)
.map
function correctly to translate inputs to PWM values.valor
correctly and resets it after processing.Serial.println()
to ensure user clarity.if (Serial.available()) {
char ch=Serial.read();
if(ch >= '0' && ch <= '9')
{
valor=(valor*10) + (ch-'0');
Serial.print(ch);
}
else if (ch==10 || ch==13)
{
analogWrite(7,valor);
velocidad = (motor, map(ch, 0, 1023, 0, 100));
Serial.println(" ");
Serial.print("INTRODUCE VALOR DEL PWM (0% - 100%");
valor=0;
}
int valorPot = analogRead(pinPotenciometro);
velocidad = (motor, map(valorPot, 0, 1023, 0, 100));
Key Changes:Cpp
const int pinSelector = 4; const int pinLedVerde = 13; const int pinLedRojo = 12; const int pinPotenciometro = A0; const int motor = 7; int velocidad = 0; int valor = 0; void setup() { pinMode(pinSelector, INPUT); pinMode(pinLedVerde, OUTPUT); pinMode(pinLedRojo, OUTPUT); pinMode(motor, OUTPUT); Serial.begin(9600); Serial.println("INTRODUCE VALOR DEL PWM (0% - 100%)"); } void loop() { bool modoTeclado = digitalRead(pinSelector); if (modoTeclado == 1) { // Compare using '==' if (Serial.available()) { char ch = Serial.read(); if (ch >= '0' && ch <= '9') { valor = (valor * 10) + (ch - '0'); Serial.print(ch); } else if (ch == 10 || ch == 13) { // Newline or carriage return if (valor >= 0 && valor <= 100) { // Ensure PWM percentage range int pwmValue = map(valor, 0, 100, 0, 255); analogWrite(motor, pwmValue); velocidad = valor; } Serial.println(" "); Serial.print("INTRODUCE VALOR DEL PWM (0% - 100%)"); valor = 0; } } } else { int valorPot = analogRead(pinPotenciometro); velocidad = map(valorPot, 0, 1023, 0, 100); analogWrite(motor, map(velocidad, 0, 100, 0, 255)); } // Set LED states based on velocidad if (velocidad > 0) { digitalWrite(pinLedVerde, HIGH); digitalWrite(pinLedRojo, LOW); } else { digitalWrite(pinLedVerde, LOW); digitalWrite(pinLedRojo, HIGH); } delay(250); }
==
for condition checking instead of =
.valor
is within the 0–100 range before setting the PWM; this avoids incorrect values being applied.analogWrite
out of the if-block to ensure motor speed is always updated based on $velocidad$.Cpp
const int pinIncrementar = 2; const int pinDecrementar = 3; const int pinSelector = 4; const int pinLedVerde = 5; const int pinLedRojo = 6; int velocidad = 0; // Velocidad del motor: 0-100 void setup() { pinMode(pinIncrementar, INPUT); pinMode(pinDecrementar, INPUT); pinMode(pinSelector, INPUT); pinMode(pinLedVerde, OUTPUT); pinMode(pinLedRojo, OUTPUT); Serial.begin(9600); } void loop() { bool modoBotones = digitalRead(pinSelector); if (modoBotones) { // Modo de control por botones if (digitalRead(pinIncrementar) && velocidad < 100) { velocidad += 10; delay(200); // Anti rebote } if (digitalRead(pinDecrementar) && velocidad > 0) { velocidad -= 10; delay(200); // Anti rebote } } else { // Modo de control por teclado (Serie) if (Serial.available()) { char c = Serial.read(); if (c == '+' && velocidad < 100) { velocidad += 10; } else if (c == '-' && velocidad > 0) { velocidad -= 10; } } } // Control de LEDs if (velocidad > 0) { digitalWrite(pinLedVerde, HIGH); digitalWrite(pinLedRojo, LOW); } else { digitalWrite(pinLedVerde, LOW); digitalWrite(pinLedRojo, HIGH); } // Aquí deberías añadir el código para controlar el motor según la `velocidad` }
Descripción del CódigoCpp
const int pinSelector = 4; const int pinLedVerde = 5; const int pinLedRojo = 6; const int pinPotenciometro = A0; int velocidad = 0; // Velocidad del motor: 0-100 void setup() { pinMode(pinSelector, INPUT); pinMode(pinLedVerde, OUTPUT); pinMode(pinLedRojo, OUTPUT); Serial.begin(9600); } void loop() { bool modoTeclado = digitalRead(pinSelector); if (modoTeclado) { // Modo de control por teclado numérico if (Serial.available()) { int nuevaVelocidad = Serial.parseInt(); if (nuevaVelocidad >= 0 && nuevaVelocidad <= 100) { velocidad = nuevaVelocidad; } } } else { // Modo de control por potenciómetro int valorPot = analogRead(pinPotenciometro); velocidad = map(valorPot, 0, 1023, 0, 100); } // Control de LEDs if (velocidad > 0) { digitalWrite(pinLedVerde, HIGH); digitalWrite(pinLedRojo, LOW); } else { digitalWrite(pinLedVerde, LOW); digitalWrite(pinLedRojo, HIGH); } // Aquí deberías añadir el código para controlar el motor según la `velocidad` }
Explicación del CódigoCpp
const int pinSelector = 4; const int pinLedVerde = 5; const int pinLedRojo = 6; const int pinPotenciometro = A0; const int pinMotorPWM = 9; // Pin PWM para el control de velocidad del motor const int pinMotorDir1 = 7; // Primer pin para el control de dirección const int pinMotorDir2 = 8; // Segundo pin para el control de dirección int velocidad = 0; // Velocidad del motor: 0-255 (PWM) void setup() { pinMode(pinSelector, INPUT); pinMode(pinLedVerde, OUTPUT); pinMode(pinLedRojo, OUTPUT); pinMode(pinMotorPWM, OUTPUT); pinMode(pinMotorDir1, OUTPUT); pinMode(pinMotorDir2, OUTPUT); Serial.begin(9600); } void loop() { bool modoTeclado = digitalRead(pinSelector); if (modoTeclado) { // Modo de control por teclado numérico if (Serial.available()) { int nuevaVelocidad = Serial.parseInt(); if (nuevaVelocidad >= 0 && nuevaVelocidad <= 100) { velocidad = map(nuevaVelocidad, 0, 100, 0, 255); // Mapear a 0-255 para PWM } } } else { // Modo de control por potenciómetro int valorPot = analogRead(pinPotenciometro); velocidad = map(valorPot, 0, 1023, 0, 255); // Mapear a 0-255 para PWM } // Control del motor usando PWM analogWrite(pinMotorPWM, velocidad); digitalWrite(pinMotorDir1, HIGH); // Establecer dirección, por ejemplo, hacia adelante digitalWrite(pinMotorDir2, LOW); // Control de LEDs if (velocidad > 0) { digitalWrite(pinLedVerde, HIGH); digitalWrite(pinLedRojo, LOW); } else { digitalWrite(pinLedVerde, LOW); digitalWrite(pinLedRojo, HIGH); } }
map()
.analogWrite()
para enviar la señal PWM al controlador de motor. Los pines de dirección se configuran para definir si el motor se mueve en una dirección específica.Explicaciones:Plaintext
// Inicialización del sistema configurar_pin_entrada(boton_encendido, pull_up) configurar_pin_entrada(boton_apagado, pull_down) configurar_pin_salida(motor) estado_motor = APAGADO mientras (verdadero) { si (leer_pin(boton_encendido) == PRESIONADO) { estado_motor = ENCENDIDO } si (leer_pin(boton_apagado) == PRESIONADO) { estado_motor = APAGADO } si (estado_motor == ENCENDIDO) { encender_pin(motor) } sino { apagar_pin(motor) } }
Consideraciones Técnicas:Plaintext
// Inicialización configurar_pin_entrada(boton_encendido, pull_up) configurar_pin_entrada(boton_apagado, pull_down) configurar_pin_entrada(boton_subida_velocidad, pull_up) configurar_pin_entrada(boton_bajada_velocidad, pull_up) configurar_pin_entrada(selector, pull_down) configurar_pin_salida(motor) configurar_pin_salida(led_verde) configurar_pin_salida(led_rojo) estado_motor = APAGADO velocidad = 0 mientras (verdadero) { // Control de encendido/apagado del motor si (leer_pin(boton_encendido) == PRESIONADO) { estado_motor = ENCENDIDO } si (leer_pin(boton_apagado) == PRESIONADO) { estado_motor = APAGADO } // Indicadores LED si (estado_motor == ENCENDIDO) { encender_pin(led_verde) apagar_pin(led_rojo) } sino { apagar_pin(led_verde) encender_pin(led_rojo) } // Control de velocidad si (estado_motor == ENCENDIDO) { si (leer_pin(selector) == MODO_BOTONES) { si (leer_pin(boton_subida_velocidad) == PRESIONADO) y (velocidad < 100) { velocidad += 1 // Incrementa la velocidad } si (leer_pin(boton_bajada_velocidad) == PRESIONADO) y (velocidad > 0) { velocidad -= 1 // Decrementa la velocidad } } sino si (leer_pin(selector) == MODO_TECLADO) { entrada_teclado = leer_teclado() si (entrada_teclado == '+') y (velocidad < 100) { velocidad += 1 // Incrementar velocidad } si (entrada_teclado == '.') y (velocidad > 0) { velocidad -= 1 // Decrementar velocidad } } establecer_velocidad_motor(velocidad) // Función para PWM o control de velocidad } sino { establecer_velocidad_motor(0) // Motor apagado } }
Explicación del Código:Cpp
// Definición de pines const int botonEncendidoPin = 2; const int botonApagadoPin = 3; const int botonSubidaVelPin = 4; const int botonBajadaVelPin = 5; const int selectorPin = 6; const int motorPin = 9; // Pin de PWM const int ledVerdePin = 7; const int ledRojoPin = 8; // Variables de estado bool motorEncendido = false; int velocidad = 0; void setup() { pinMode(botonEncendidoPin, INPUT_PULLUP); pinMode(botonApagadoPin, INPUT_PULLDOWN); pinMode(botonSubidaVelPin, INPUT_PULLUP); pinMode(botonBajadaVelPin, INPUT_PULLUP); pinMode(selectorPin, INPUT_PULLDOWN); pinMode(motorPin, OUTPUT); pinMode(ledVerdePin, OUTPUT); pinMode(ledRojoPin, OUTPUT); Serial.begin(9600); // Inicialización de comunicación serial para teclado } void loop() { // Control de encendido/apagado if (digitalRead(botonEncendidoPin) == LOW) { // Botón presionado motorEncendido = true; } if (digitalRead(botonApagadoPin) == HIGH) { // Botón presionado motorEncendido = false; } // Indicadores LED if (motorEncendido) { digitalWrite(ledVerdePin, HIGH); digitalWrite(ledRojoPin, LOW); } else { digitalWrite(ledVerdePin, LOW); digitalWrite(ledRojoPin, HIGH); } // Control de velocidad if (motorEncendido) { if (digitalRead(selectorPin) == LOW) { // Control por botones if (digitalRead(botonSubidaVelPin) == LOW && velocidad < 255) { velocidad++; delay(50); // Debounce } if (digitalRead(botonBajadaVelPin) == LOW && velocidad > 0) { velocidad--; delay(50); // Debounce } } else { // Control por teclado if (Serial.available()) { char comando = Serial.read(); if (comando == '+' && velocidad < 255) { velocidad++; } if (comando == '.' && velocidad > 0) { velocidad--; } } } analogWrite(motorPin, velocidad); // Ajusta la velocidad del motor } else { analogWrite(motorPin, 0); // Motor apagado } delay(10); // Retardo pequeño para estabilidad del loop }
INPUT_PULLUP
y INPUT_PULLDOWN
para gestionar los estados de los botones evitando conexiones flotantes.analogWrite
se usa para aplicar PWM al pin del motor, ajustando su velocidad.Image
Descripción del FuncionamientoCpp
#define LIGHT_SENSOR_PIN A0 // Pin del primer potenciómetro #define SENSITIVITY_PIN A1 // Pin del segundo potenciómetro #define RELAY_PIN 13 // Pin del relé void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); // Inicia con la luz apagada } void loop() { int lightSensorValue = analogRead(LIGHT_SENSOR_PIN); int sensitivityValue = analogRead(SENSITIVITY_PIN); // Comparar el valor del sensor de luz con el nivel de sensibilidad ajustado if (lightSensorValue < sensitivityValue) { digitalWrite(RELAY_PIN, HIGH); // Enciende el relé } else { digitalWrite(RELAY_PIN, LOW); // Apaga el relé } delay(1000); // Tiempo de espera antes de la siguiente lectura }
INPUT_PULLUP
, aseguramos externalmente los estados)@copilot can you partner up with me to design a PCB?
@copilot give me a few architecture options for an affordable Al pendant using mermaid diagrams.
@copilot how can I build a schematic with Flux?
Explicación del Código:Cpp
const int ledPin = 13; // Pin donde está el LED const int buttonPin = 2; // Pin donde está conectado el botón bool ledState = LOW; // Estado inicial del LED bool lastButtonState = LOW; // Último estado leído del botón bool buttonState; // Estado actual del botón void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); // Usa la resistencia pull-up interna } void loop() { buttonState = digitalRead(buttonPin); // Verifica si hay un cambio de estado del botón (de no presionado a presionado) if (buttonState != lastButtonState) { if (buttonState == LOW) { // Detecta la bajada del botón ledState = !ledState; // Cambia el estado del LED digitalWrite(ledPin, ledState); } delay(50); // Anti-rebotes } lastButtonState = buttonState; // Actualiza el último estado del botón }
ledState
para llevar el seguimiento del estado del LED (encendido o apagado).lastButtonState
y buttonState
.delay(50);
se utiliza para evitar rebotes en la lectura del botón.Welcome 👋
Flux helps you build PCBs faster with an AI teammate!
To collaborate on this project, get the latest updates,
or fork your own version, sign up now.
fer514
Image
copilot
disp1[]
es un arreglo de enteros que contiene los valores en hexadecimal que se corresponden con los segmentos que deben encenderse para representar los números del 0 al 9 en el display de 7 segmentos.setup
:loop
:impimir
para mostrar el númeroi
actual en el display.impimir
:impimir
toma un númeroval
, consulta el arreglodisp1
para obtener la representación binaria correcta para ese número.aux
para comprobar cada uno de los bits del valor endisp1[val]
.digitalWrite(pin, HIGH)
.digitalWrite(pin, LOW)
.aux
se usa como una máscara de bits, desplazándose a la izquierda (aux = aux << 1
) en cada iteración del buclefor
, para comprobar cada bit del byte.disp1
que mapea números en segmentos del display y ciclos de control para manejar los pines de salida que encenderán los segmentos apropiados del display para mostrar los números del 1 al 9.fer514
copilot
dispLetters
están basados en un display común cátodo. Si estás usando un display común ánodo, tendrías que invertir las señalesHIGH
yLOW
.fer514
Image
copilot
LiquidCrystal
para controlar el display LCD.analogRead(A0)
.voltage = sensorValue * (5.0 / 1023.0)
.fer514
Image
copilot
fer514
copilot
fer514
copilot
fer514
copilot
fer514
copilot
fer514
copilot
fer514
copilot
fer514
copilot
fer514
copilot
fer514
copilot