Diferencia entre revisiones de «Taller de Arduino»
Sin resumen de edición |
Sin resumen de edición |
||
| (No se muestran 6 ediciones intermedias de 2 usuarios) | |||
| Línea 18: | Línea 18: | ||
===Código 2=== | ===Código 2=== | ||
< | <syntaxhighlight lang="c++" line copy> | ||
#include <SoftwareSerial.h> | #include <SoftwareSerial.h> | ||
| Línea 31: | Línea 31: | ||
delay(1000); | delay(1000); | ||
} | } | ||
</ | </syntaxhighlight> | ||
===Código 3=== | ===Código 3=== | ||
< | <syntaxhighlight lang="c++" line copy> | ||
#include <SoftwareSerial.h> | #include <SoftwareSerial.h> | ||
| Línea 57: | Línea 57: | ||
delay(50); | delay(50); | ||
} | } | ||
</ | </syntaxhighlight> | ||
===Código 4=== | ===Código 4=== | ||
< | <syntaxhighlight lang="c++" line copy> | ||
#define USE_TIMER_1 true | #define USE_TIMER_1 true | ||
| Línea 88: | Línea 88: | ||
void loop() { | void loop() { | ||
} | } | ||
</ | </syntaxhighlight> | ||
===Código 5=== | |||
<syntaxhighlight lang="c++" line copy> | |||
#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() { | |||
} | |||
</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 == | |||
[[File:Arduino-UNO-pinout-high-resolution.png|500px]] | |||