Diferencia entre revisiones de «Taller de Arduino»

De fabwiki
Ir a la navegación Ir a la búsqueda
Sin resumen de edición
Sin resumen de edición
 
(No se muestran 3 ediciones intermedias de 2 usuarios)
Línea 111: Línea 111:
void loop() {
void loop() {
}
}
</syntaxhighlight
</syntaxhighlight>
 
===Código 6===
<syntaxhighlight lang="c++" line copy>
// pin2: RX
// pin3: TX
 
#define USE_TIMER_1 true
 
#include "TimerInterrupt.h"
 
const int OUTPUT_PIN = 3;
const int INPUT_PIN = 2;
const int TIMER1_INTERVAL_MS = 200;
 
void ToggleOutput() {
  const bool x = digitalRead(OUTPUT_PIN);
  digitalWrite(OUTPUT_PIN, !x);
}
 
void ProcessPinChange() {
  const int input_pin_val = digitalRead(INPUT_PIN);
  digitalWrite(LED_BUILTIN, input_pin_val);
}
 
void setup() {
  ITimer1.init();
  ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, ToggleOutput);
  pinMode(OUTPUT_PIN, OUTPUT);
  pinMode(INPUT_PIN, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
 
  const int interrupt_number = digitalPinToInterrupt(INPUT_PIN);
  attachInterrupt(interrupt_number, ProcessPinChange, CHANGE);
}
 
void loop() {
}
</syntaxhighlight>
 
===Código 7===
<syntaxhighlight lang="c++" line copy>
// Receives from the hardware serial, sends to software serial.
// Receives from software serial, sends to hardware serial.
 
#include <SoftwareSerial.h>
 
const int RX_PIN = 10;
const int TX_PIN = 11;
 
SoftwareSerial soft_serial(RX_PIN, TX_PIN);
 
void setup() {
  Serial.begin(9600);
 
  // wait for serial port to connect. Needed for native USB port only
  while (!Serial) { }
 
  soft_serial.begin(9600);
}
 
void loop() {
  if (soft_serial.available()) {
    const int char_para_copiar = soft_serial.read();
    Serial.write(char_para_copiar);
  }
 
  if (Serial.available()) {
    const int char_para_copiar = Serial.read();
    soft_serial.write(char_para_copiar);
  }
}
</syntaxhighlight>


== Esquema de pines (pinout) Arduino UNO ==
== Esquema de pines (pinout) Arduino UNO ==
[[File:Arduino-UNO-pinout-high-resolution.png|500px]]
[[File:Arduino-UNO-pinout-high-resolution.png|500px]]

Revisión actual - 15:33 1 ago 2026

Temas a tratar en el taller de Arduino:

  • ¿Qué es Arduino?
  • ¿De dónde viene el concepto del Arduino?
  • ¿Cuál es el propósito del Arduino?
  • ¿Cuál es la relación de Arduino con el PC, Raspberry Pi, y otros dispositivos similares?
  • ¿Cuáles son las versiones de Arduino?
  • ¿El Arduino es código abierto?
  • ¿Qué podemos hacer con un Arduino? ¿Que no es posible?
  • ¿Qué ventajas tiene construir sistemas con Arduino en lugar de circuitos analógicos u otros chips digitales?
  • Vamos a jugar con algunos ejemplos.
  • ¿Como podemos analizar un sistema que contiene un Arduino para corregir errores? ¿Cuáles son las herramientas y técnicas para ayudar?
  • Vamos a construir un sistema nuevo usando un Arduino.

https://github.com/contrem/arduino-timer

Ejemplos

Mini horno

Código 2

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  mySerial.begin(300);
}

void loop() {
    mySerial.print("h");
    delay(1000);
}

Código 3

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {
  mySerial.begin(300);
  pinMode(13, OUTPUT);
}

void loop() {
  if (mySerial.available()) {
    char c = mySerial.read();
    if (c == 'h') {
      digitalWrite(13, HIGH);
      delay(100);
      digitalWrite(13, LOW);
      delay(100);
    }
  }
  delay(50);
}

Código 4

#define USE_TIMER_1     true

#include "TimerInterrupt.h"

unsigned int outputPin1 = LED_BUILTIN;

#define TIMER1_INTERVAL_MS    300

void TimerHandler1(unsigned int outputPin = LED_BUILTIN) {
  static bool toggle1 = false;
  static bool started = false;

  if (!started) {
    started = true;
    pinMode(outputPin, OUTPUT);
  }
  
  digitalWrite(outputPin, toggle1);
  toggle1 = !toggle1;
}

void setup() {
  ITimer1.init();
  ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, outputPin1);
}

void loop() {
}

Código 5

#include <SPI.h>
#include <SD.h>

File f;

void setup() {
  pinMode(A5, OUTPUT);
  SD.begin(4);
  f = SD.open("data.txt", FILE_READ);
  int x = f.parseInt();
  for (int i = 0; i < x; i++) {
    digitalWrite(A5, HIGH); delay(300);
    digitalWrite(A5, LOW);  delay(300);
  }
}

void loop() {
}

Código 6

// pin2: RX
// pin3: TX

#define USE_TIMER_1 true

#include "TimerInterrupt.h"

const int OUTPUT_PIN = 3;
const int INPUT_PIN = 2;
const int TIMER1_INTERVAL_MS = 200;

void ToggleOutput() {
  const bool x = digitalRead(OUTPUT_PIN);
  digitalWrite(OUTPUT_PIN, !x);
}

void ProcessPinChange() {
  const int input_pin_val = digitalRead(INPUT_PIN);
  digitalWrite(LED_BUILTIN, input_pin_val);
}

void setup() {
  ITimer1.init();
  ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, ToggleOutput);
  pinMode(OUTPUT_PIN, OUTPUT);
  pinMode(INPUT_PIN, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  
  const int interrupt_number = digitalPinToInterrupt(INPUT_PIN);
  attachInterrupt(interrupt_number, ProcessPinChange, CHANGE);
}

void loop() {
}

Código 7

// Receives from the hardware serial, sends to software serial.
// Receives from software serial, sends to hardware serial.

#include <SoftwareSerial.h>

const int RX_PIN = 10;
const int TX_PIN = 11;

SoftwareSerial soft_serial(RX_PIN, TX_PIN);

void setup() {
  Serial.begin(9600);

  // wait for serial port to connect. Needed for native USB port only
  while (!Serial) { }

  soft_serial.begin(9600);
}

void loop() {
  if (soft_serial.available()) {
    const int char_para_copiar = soft_serial.read();
    Serial.write(char_para_copiar);
  }

  if (Serial.available()) {
    const int char_para_copiar = Serial.read();
    soft_serial.write(char_para_copiar);
  }
}

Esquema de pines (pinout) Arduino UNO