Diferencia entre revisiones de «Taller de Arduino»

Sin resumen de edición
Sin resumen de edición
 
(No se muestran 2 ediciones intermedias del mismo usuario)
Línea 110: Línea 110:


void loop() {
void loop() {
}
</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>
</syntaxhighlight>