Diferencia entre revisiones de «Taller de Arduino»
Sin resumen de edición |
|||
| Línea 115: | Línea 115: | ||
===Codigo 6=== | ===Codigo 6=== | ||
<syntaxhighlight lang="c++" line copy> | <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 INPUT_PIN = 2; | ||
const int TIMER1_INTERVAL_MS = 200; | |||
void ToggleOutput() { | |||
const bool x = digitalRead(OUTPUT_PIN); | |||
digitalWrite(OUTPUT_PIN, !x); | |||
} | |||
void | void ProcessPinChange() { | ||
const int input_pin_val = digitalRead(INPUT_PIN); | const int input_pin_val = digitalRead(INPUT_PIN); | ||
digitalWrite(LED_BUILTIN, input_pin_val); | digitalWrite(LED_BUILTIN, input_pin_val); | ||
| Línea 123: | Línea 137: | ||
void setup() { | void setup() { | ||
ITimer1.init(); | |||
ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, ToggleOutput); | |||
pinMode(OUTPUT_PIN, OUTPUT); | |||
pinMode(INPUT_PIN, INPUT_PULLUP); | pinMode(INPUT_PIN, INPUT_PULLUP); | ||
pinMode(LED_BUILTIN, OUTPUT); | pinMode(LED_BUILTIN, OUTPUT); | ||
const int interrupt_number = digitalPinToInterrupt(INPUT_PIN); | const int interrupt_number = digitalPinToInterrupt(INPUT_PIN); | ||
attachInterrupt(interrupt_number, | attachInterrupt(interrupt_number, ProcessPinChange, CHANGE); | ||
} | } | ||