reestructuracion completa

pendientes verificar links, otros
This commit is contained in:
jp.av.dev 2022-04-04 14:40:51 -04:00
parent b6bc7991dc
commit 4956fda212
35 changed files with 982 additions and 215 deletions

View File

@ -1,6 +1,6 @@
# EEPROM # EEPROM
*** Electrically Erasable Programmable Read-Only Memory*** ***Electrically Erasable Programmable Read-Only Memory***
### Funciones ### Funciones
@ -14,33 +14,33 @@
#define VAR2 2 #define VAR2 2
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
delay(2000); delay(2000);
Serial.print("Capacidad de memoria"); Serial.print("Capacidad de memoria");
Serial.println(EEPROM.length()); Serial.println(EEPROM.length());
delay(500); delay(500);
Serial.print("Valor almacenado en direccion 0: "); Serial.print("Valor almacenado en direccion 0: ");
Serial.println(EEPROM.read(dirVAR)); //read(direccion) Serial.println(EEPROM.read(dirVAR)); //read(direccion)
delay(500); delay(500);
Serial.println("Guardando 39 en direccion 0"); Serial.println("Guardando 39 en direccion 0");
EEPROM.write(dirVAR, VAR); //Write(direccion, valor) EEPROM.write(dirVAR, VAR); //Write(direccion, valor)
delay(500); delay(500);
Serial.println("Guardando 32767 en direccion 1"); Serial.println("Guardando 32767 en direccion 1");
EEPROM.write(dirVAR1, VAR1); //Write(direccion, valor) EEPROM.write(dirVAR1, VAR1); //Write(direccion, valor)
delay(500); delay(500);
Serial.println("Guardando 2 en direccion 2"); Serial.println("Guardando 2 en direccion 2");
EEPROM.write(dirVAR2, VAR2); //Write(direccion, valor) EEPROM.write(dirVAR2, VAR2); //Write(direccion, valor)
delay(500); delay(500);
} }
void loop() { void loop() {
Serial.print("Valor en direccion 0: "); Serial.print("Valor en direccion 0: ");
Serial.println(EEPROM.read(dirVAR)); Serial.println(EEPROM.read(dirVAR));
Serial.print("Valor en direccion 1: "); Serial.print("Valor en direccion 1: ");
Serial.println(EEPROM.read(dirVAR1)); Serial.println(EEPROM.read(dirVAR1));
Serial.print("Valor en direccion 3: "); Serial.print("Valor en direccion 3: ");
Serial.println(EEPROM.read(dirVAR2)); Serial.println(EEPROM.read(dirVAR2));
delay(500); delay(500);
} }
``` ```

108
README.md
View File

@ -10,21 +10,97 @@ alguna solución a una futura necesidad.
Implementaciones : Implementaciones :
- [Buzzers/Speakers](./buzzer/README.md) - [Comunicación Serial](./serialCom/README.md)
- [BlueTooth](./bluetooth/README.md) - [EEPROM](./EEPROM/README.md)
- [Comunicación Serial](./serialCom/README.md) - [Buzzers/Speakers](./buzzer/README.md)
- [EEPROM](./EEPROM/README.md) - [PWM](./pwm/README.md)
- [grbl](./grblUpload/README.md) - [Leds](./leds/README.md)
- [LCDs](./lcd/README.md) - [Led Dimmer](./leds/dimmer_led/dimmer_led.ino)
- [Leds](./leds/README.md) - [Leds PWM](./leds/led_pwm/led_pwm.ino)
- [Motores](./motores/README.md) - [Leds PWM 1](./leds/leds_pwm/leds_pwm.ino)
-[DC](./motores/dc/README.md) - [Leds PwM 2](./leds/leds_pwm2/leds_pwm2.ino)
-[Servo](./motores/servo/README.md) - [Potenciomentro y Led](./leds/potenciomentro_led/potenciomentro_led.ino)
-[Brushless](./motores/brushless/README.md) - [RGB](./leds/rgb/rgb.ino)
-[Paso a paso (stepper)](./motores/pap/README.md) - [RGB 2](./leds/rgb2/rgb2.ino)
- [PWM](./pwm/README.md) - [RGB 3](./leds/rgb3/rgb3.ino)
- [Real Time Clock](./RTC/README.md) - [Semaforo](./leds/semaforo/semaforo.ino)
- [Sensores](./sensores/README.md) - [Serial Leds](./leds/serial_leds/serial_leds.ino)
- [Otros](./tests/README.md) - [Sensores](./sensores/README.md)
- Temperatura y Humedad
- [DHT-11](./sensores/dht11/dht11.ino)
- [DHT-21](./sensores/dht21/dht21.ino)
- Distancia
- [GP2Y0A21YK0F](./sensores/distancia_gp2y0a21yk0f/distancia_gp2y0a21yk0f.ino)
- [HC-SR04](./sensores/distancia_hc-sr04/distancia_hc-sr04.ino)
- Humedad Suelo
- [Humedad](./sensores/humedad/humedad/humedad.ino)
- [Humedad LCD](./sensores/humedad/humedad_lcd/humedad_lcd.ino)
- IR
- [Control remoto](./sensores/ir/control_remoto_IR/control_remoto_IR.ino)
- [Repector IR](./sensores/ir/ir_receiver/ir_receiver.ino)
- [Repector IR 2](./sensores/ir/ir_receiver2/ir_receiver2.ino)
- Proximidad
- [Movimiento](./sensores/proximidad/sensor_mov/sensor_mov.ino)
- [Movimiento 2](./sensores/proximidad/sensor_mov2/sensor_mov2.ino)
- [LCDs](./lcd/README.md)
- [Autoscroll](./lcd/autoscrol./lcd/autoscroll.ino)
- [Caracter Personalizado](./lcd/caracter_personalizad./lcd/caracter_personalizado.ino)
- [Contador loops](./lcd/contador_loop./lcd/contador_loops.ino)
- [i2c](./lcd/i2./lcd/)
- [I2C 20x4](./lcd/i2./lcd/i2c_20x./lcd/i2c_20x4.ino)
- [I2C Scan](./lcd/i2./lcd/i2c_sca./lcd/i2c_scan.ino)
- [Metodo de 8 bits](./lcd/metodo_8bit./lcd/metodo_8bits.ino)
- [Texto en Movimiento](./lcd/texto_en_movimient./lcd/texto_en_movimiento.ino)
- [Real Time Clock](./RTC/README.md)
- [Ejm Básico](./RTC/README.md#funciones-para-hora-y-fecha)
- [Ajuste Hora y Fecha](./RTC/README.md#ajuste-hora-y-fecha)
- [Ajuste Hora y Fecha según tiempo de compilación](./RTC/README.md#set-hora-y-fecha-segun-datos-de-compilacion)
- [Conexiones](./RTC/README.md#conexiones)
- [RTC LCD y Bluetooth](./RTC/README.md#rtc-lcd-y-bluetooth)
- [Motores](./motores/README.md)
- [DC](./motores/README.md#dc)
- [9v](./motores/README.md#bateria-9v)
- [L298N y Joystick](./motores/README.md#l298n-y-joystick)
- [Puente H](./motores/README.md#puente-h)
- [Puente H ISR](./motores/README.md#puente-h-isr)
- [Servo](./motores/README.md#servo)
- [Servo Joystick](./motores/README.md#servo-joystick)
- [Servo Led](./motores/README.md#servo-led)
- [Servo Termo](./motores/README.md#servo-termo)
- [Servos y potenciometros](./motores/README.md#servos-y-potenciometros)
- [Brushless](./motores/README.md#brushless)
- [Serial ESC](./motores/README.md#serial-esc.ino)
- [Paso a paso](./motores/README.md#paso-a-paso)
- [Control PaP](./motores/README.md#control-pap)
- [Ajuste velocidad PaP](./motores/README.md#ajuste_velocidad-pap)
- [PaP](./motores/README.md#pap)
- [PaP 5v](./motores/README.md#pap-5v)
- [Stepper KeyStudio](./motores/README.md#stepper-keystudio)
- [BlueTooth](./bluetooth/README.md)
- [grbl](./grblUpload/README.md)
- [Pruebas](./tests/README.md)
- **OK**
- [RealTimeClock](./tests/ok_rtc/ok_rtc.ino)
- [Joystick map Serial](./tests/ok_map_joystick_serial/ok_map_joystick_serial.ino)
- [4 Relay](./tests/ok_relay_x4/ok_relay_x4.ino)
- [lcd 2004](./tests/ok_lcd_2004/ok_lcd_2004.ino)
- [lcd DHT](./tests/ok_lcd_dht/ok_lcd_dht.ino)
- [lcd RTC](./tests/ok_lcd_rtc/ok_lcd_rtc.ino)
- [lcd 4 RTC](./tests/ok_lcd_rtc_x4/ok_lcd_rtc_x4.ino)
- [Mod](./tests/ok_mod/ok_mod.ino)
- [RTC DHT](./tests/ok_rtc_dht/ok_rtc_dht.ino)
- [SD read-write](./tests/ok_sd_read_write/ok_sd_read_write.ino)
- [RTC SD write](./tests/ok_sd_write_rtc/ok_sd_write_rtc.ino)
- [Oled-0.91 Graphs](./tests/ok_oled_0.91_graphs/ok_oled_0.91_graphs.ino)
- [ESP01](./tests/ok_esp01/ok_esp01.ino)
- [ESP php](./tests/ok_esp_php/ok_esp_php.ino)
- **Test**
- [ESP8266](./tests/test_esp8266/test_esp8266.ino)
- [ESP php](./tests/test_esp_php/test_esp_php.ino)
- [ArduinoMega](./tests/test_mega/test_mega.ino)
- [Mega ESP helloServer](./tests/test_mega_esp_helloServer/test_mega_esp_helloServer.ino)
- [Datos a puerto Serial](./tests/test_serial_datos_a_serie/test_serial_datos_a_serie.ino)
- [Serial a datos](./tests/test_serial_serie_a_datos/test_serial_serie_a_datos.ino)
- [UART ESP helloServer](./tests/test_uart_esp_helloServer/test_uart_esp_helloServer.ino)

View File

@ -0,0 +1,11 @@
## LCDs
- [Autoscroll](./autoscroll/autoscroll.ino)
- [Caracter Personalizado](./caracter_personalizado/caracter_personalizado.ino)
- [Contador loops](./contador_loops/contador_loops.ino)
- [i2c](./i2c/)
- [I2C 20x4](./i2c/i2c_20x4/i2c_20x4.ino)
- [I2C Scan](./i2c/i2c_scan/i2c_scan.ino)
- [Metodo de 8 bits](./metodo_8bits/metodo_8bits.ino)
- [Texto en Movimiento](./texto_en_movimiento/texto_en_movimiento.ino)

View File

@ -4,159 +4,144 @@ int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};// use array to select pin for bus
int Enable = 2; int Enable = 2;
void LcdCommandWrite(int value) { void LcdCommandWrite(int value) {
// define all pins int i = 0;
int i = 0; // assign value for bus
for (i=DB[0]; i <= DI; i++) // assign value for bus for (i=DB[0]; i <= DI; i++) {
{ // for 1602 LCD, it uses D7-D0( not D0-D7) for signal identification;
digitalWrite(i,value & 01);// for 1602 LCD, it uses D7-D0( not D0-D7) for signal identification; here, its used for signal inversion. // here, its used for signal inversion.
value >>= 1; digitalWrite(i,value & 01);
} value >>= 1;
digitalWrite(Enable,LOW); }
delayMicroseconds(1); digitalWrite(Enable,LOW);
digitalWrite(Enable,HIGH); delayMicroseconds(1);
delayMicroseconds(1); // wait for 1ms digitalWrite(Enable,HIGH);
digitalWrite(Enable,LOW); delayMicroseconds(1); // wait for 1ms
delayMicroseconds(1); // wait for 1ms digitalWrite(Enable,LOW);
delayMicroseconds(1); // wait for 1ms
} }
void LcdDataWrite(int value) { void LcdDataWrite(int value) {
// initialize all pins // initialize all pins
int i = 0; int i = 0;
digitalWrite(DI, HIGH); digitalWrite(DI, HIGH);
digitalWrite(RW, LOW); digitalWrite(RW, LOW);
for (i=DB[0]; i <= DB[7]; i++) { for (i=DB[0]; i <= DB[7]; i++) {
digitalWrite(i,value & 01); digitalWrite(i,value & 01);
value >>= 1; value >>= 1;
} }
digitalWrite(Enable,LOW); digitalWrite(Enable,LOW);
delayMicroseconds(1); delayMicroseconds(1);
digitalWrite(Enable,HIGH); digitalWrite(Enable,HIGH);
delayMicroseconds(1); delayMicroseconds(1);
digitalWrite(Enable,LOW); digitalWrite(Enable,LOW);
delayMicroseconds(1); // wait for 1ms delayMicroseconds(1); // wait for 1ms
} }
void setup (void) { void setup (void) {
int i = 0; int i = 0;
for (i=Enable; i <= DI; i++) { for (i=Enable; i <= DI; i++) {
pinMode(i,OUTPUT); pinMode(i,OUTPUT);
} }
delay(100); delay(100);
// initialize LCD after a brief pause // initialize LCD after a brief pause
// for LCD control // for LCD control
LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size
delay(64); delay(64);
LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size
delay(50); delay(50);
LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size
delay(20); delay(20);
LcdCommandWrite(0x06); // set input mode LcdCommandWrite(0x06); // set input mode
// auto-increment, no display of shifting // auto-increment, no display of shifting
delay(20); delay(20);
LcdCommandWrite(0x0E); // display setup LcdCommandWrite(0x0E); // display setup
// turn on the monitor, cursor on, no flickering // turn on the monitor, cursor on, no flickering
delay(20); delay(20);
LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0
delay(100); delay(100);
LcdCommandWrite(0x80); // display setup LcdCommandWrite(0x80); // display setup
// turn on the monitor, cursor on, no flickering // turn on the monitor, cursor on, no flickering
delay(20); delay(20);
} }
void loop (void) { void loop (void) {
LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0
delay(10); delay(10);
LcdCommandWrite(0x80+3); LcdCommandWrite(0x80+3);
delay(10); delay(10);
// write in welcome message // write in welcome message
LcdDataWrite('F'); LcdDataWrite('F');
delay(50); delay(50);
LcdDataWrite('u'); LcdDataWrite('u');
delay(50); delay(50);
LcdDataWrite('z'); LcdDataWrite('z');
delay(50); delay(50);
LcdDataWrite('a'); LcdDataWrite('a');
delay(50); delay(50);
LcdDataWrite('n'); LcdDataWrite('n');
delay(50); delay(50);
LcdDataWrite(' '); LcdDataWrite(' ');
delay(50); delay(50);
LcdDataWrite('T'); LcdDataWrite('T');
delay(50); delay(50);
LcdDataWrite('o'); LcdDataWrite('o');
delay(50); delay(50);
LcdDataWrite('k'); LcdDataWrite('k');
delay(50); delay(50);
LcdDataWrite('o'); LcdDataWrite('o');
delay(50); delay(50);
LcdCommandWrite(0xc0+0); // set cursor position at second line, second position LcdCommandWrite(0xc0+0); // set cursor position at second line, second position
delay(10); delay(10);
LcdDataWrite('*'); LcdDataWrite('*');
LcdDataWrite('*');delay(70); LcdDataWrite('*');delay(70);
LcdDataWrite('T');delay(90); LcdDataWrite('A');delay(90);
LcdDataWrite('U');delay(110); LcdDataWrite('R');delay(110);
LcdDataWrite('R');delay(130); LcdDataWrite('D');delay(130);
LcdDataWrite('B');delay(150); LcdDataWrite('U');delay(150);
LcdDataWrite('O');delay(170); LcdDataWrite('I');delay(170);
LcdDataWrite('-');delay(200); LcdDataWrite('N');delay(200);
LcdDataWrite('M');delay(170); LcdDataWrite('O');delay(170);
LcdDataWrite('A');delay(150); LcdDataWrite('-');delay(150);
LcdDataWrite('S');delay(130); LcdDataWrite('L');delay(130);
LcdDataWrite('T');delay(110); LcdDataWrite('E');delay(110);
LcdDataWrite('E');delay(90); LcdDataWrite('A');delay(90);
LcdDataWrite('R');delay(70); LcdDataWrite('R');delay(70);
LcdDataWrite('*'); LcdDataWrite('N');delay(70);
LcdDataWrite('*'); LcdDataWrite('*');
delay(3000); LcdDataWrite('*');
LcdCommandWrite(0x01); // clear the screen, cursor returns to 0 delay(3000);
delay(10); LcdCommandWrite(0x01); // clear the screen, cursor returns to 0
LcdDataWrite('A'); delay(10);
LcdDataWrite('p'); LcdDataWrite('A');
LcdDataWrite('r'); LcdDataWrite('p');
LcdDataWrite('e'); LcdDataWrite('r');
LcdDataWrite('n'); LcdDataWrite('e');
LcdDataWrite('d'); LcdDataWrite('n');
LcdDataWrite('e'); LcdDataWrite('d');
LcdDataWrite(' '); LcdDataWrite('e');
LcdDataWrite('a'); LcdDataWrite(' ');
LcdDataWrite(' '); LcdDataWrite(' ');
LcdDataWrite('u'); LcdDataWrite('c');
LcdDataWrite('s'); LcdDataWrite('r');
LcdDataWrite('a'); LcdDataWrite('e');
LcdDataWrite('r'); LcdDataWrite('a');
LcdDataWrite(' '); LcdDataWrite(' ');
LcdDataWrite(' '); LcdDataWrite(' ');
LcdCommandWrite(0xc0); LcdCommandWrite(0xc0);
LcdDataWrite(' '); delay(2000);
LcdDataWrite('T'); // set mode as new characters replay old ones,
LcdDataWrite('E'); // where there is no new ones remain the same
LcdDataWrite('R'); LcdCommandWrite(0xc02);
LcdDataWrite('M'); delay(10);
LcdDataWrite('U'); // set cursor position at first line, sixth position
LcdDataWrite('X'); LcdCommandWrite(0xc80+6);
LcdDataWrite(','); delay(10);
LcdDataWrite(' '); LcdDataWrite('o');
LcdDataWrite('d'); LcdDataWrite('p');
LcdDataWrite('e'); LcdDataWrite('e');
LcdDataWrite('s'); LcdDataWrite('n');
LcdDataWrite('p'); LcdDataWrite(' ');
LcdDataWrite('u'); LcdDataWrite('s');
LcdDataWrite('e'); delay(3000);
LcdDataWrite('s');
delay(2000);
LcdCommandWrite(0xc02); // set mode as new characters replay old ones, where there is no new ones remain the same
delay(10);
LcdCommandWrite(0xc80+6); // set cursor position at first line, sixth position
delay(10);
LcdDataWrite('S');
LcdDataWrite('s');
LcdDataWrite('h');
LcdDataWrite(' ');
LcdDataWrite(' ');
LcdDataWrite(' ');
delay(3000);
} }

View File

@ -0,0 +1,14 @@
## Leds
- [Led Dimmer](./dimmer_led/dimmer_led.ino)
- [Leds PWM](./led_pwm/led_pwm.ino)
- [Leds PWM 1](./leds_pwm/leds_pwm.ino)
- [Leds PwM 2](./leds_pwm2/leds_pwm2.ino)
- [Potenciomentro y Led](./potenciomentro_led/potenciomentro_led.ino)
- [RGB](./rgb/rgb.ino)
- [RGB 2](./rgb2/rgb2.ino)
- [RGB 3](./rgb3/rgb3.ino)
- [Semaforo](./semaforo/semaforo.ino)
- [Serial Leds](./serial_leds/serial_leds.ino)

View File

@ -0,0 +1,597 @@
## Motores
- [DC](#dc)
- [9v](#bateria-9v)
- [L298N y Joystick](#l298n-y-Joystick)
- [Puente H](#puente-h)
- [Puente H ISR](#puente-h-isr)
- [Servo](#servo)
- [Servo Joystick](#servo-joystick)
- [Servo Led](#servlo-led)
- [Servo Termo](#servo-termo)
- [Servos y potenciometros](#servos-y-potenciometros)
- [Brushless](#brushless)
- [Serial ESC](#serial-esc.ino)
- [Paso a paso](#paso-a-paso)
- [Control PaP](#control-pap)
- [Ajuste velocidad PaP](#ajuste_velocidad-pap)
- [PaP](#pap)
- [PaP 5v](#pap-5v)
- [Stepper KeyStudio](#stepper-keystudio)
----
## DC
### Bateria 9v
```c
int MOTOR=3;
int i;
byte velocidad = 1;
int pausa = 12000;
void setup(){
pinMode(MOTOR, OUTPUT);
//Serial.begin(115200);
analogWrite(MOTOR, 0);
}
void loop(){
/*
for(i=150; i<=255; i++){
analogWrite(MOTOR, i);
//Serial.print(" "+String(i));
delay(velocidad);
}
//Serial.println("");
delay(pausa);
for(i=255; i>=150; i--){
analogWrite(MOTOR, i);
//Serial.print(" "+String(i));
delay(velocidad);
}
//Serial.println("");
*/
analogWrite(MOTOR, 215);
delay(pausa);
analogWrite(MOTOR, 0);
delay(5000);
analogWrite(MOTOR, 235);
delay(pausa);
analogWrite(MOTOR, 0);
delay(5000);
analogWrite(MOTOR, 255);
delay(pausa);
/*
analogWrite(MOTOR, 255);
delay(pausa);
analogWrite(MOTOR, 0);
delay(velocidad);
*/
}
```
### L298N y Joystick
```c
#define motor1 13
#define motor2 12
#define EnA 11
#define JoyX A0
#define JoyY A1
//boolean sentido = true;
int espera = 500;
void setup() {
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(EnA, OUTPUT);
}
//Valor JoyX a la Izq de 524 a 0
//Valor JyY a la Der de 526 a 1023
void giro() {
int ejeX = analogRead(JoyX);
if(ejeX < 525) {
digitalWrite(motor2, LOW);
digitalWrite(motor1, HIGH);
analogWrite(EnA,map(ejeX,524,0,0,255));
} else if(ejeX > 525) {
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);
analogWrite(EnA,map(ejeX,526,1023,0,255));
} else {
detener();
}
}
void detener() {
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
void loop() {
giro();
}
```
### Puente H
```c
int motor1 = 6;
int motor2 = 7;
boolean sentido = true;
int espera = 500;
void setup() {
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
}
void giro() {
if(sentido) {
digitalWrite(motor2, LOW);
digitalWrite(motor1, HIGH);
} else if(!sentido) {
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);
} else {
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
}
void detener() {
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
void loop() {
detener();
delay(espera);
sentido = true;
giro();
delay(5000);
detener();
delay(espera);
sentido = false;
giro();
delay(5000);
}
```
### Puente H ISR
```c
int motor1 = 6;
int motor2 = 7;
int cambio = 2; // Pin ligado a interrupcion 0
volatile boolean sentido = true;
int espera = 500;
void setup() {
//pinMode(cambio, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
attachInterrupt(0, cambioGiro, RISING);
}
void giro() {
if(sentido) {
digitalWrite(motor2, LOW);
digitalWrite(motor1, HIGH);
} else if(!sentido) {
digitalWrite(motor1, LOW);
digitalWrite(motor2, HIGH);
} else {
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
}
void cambioGiro() {
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
sentido = !sentido;
}
void detener() {
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
}
void loop() {
detener();
delay(espera);
giro();
delay(5000);
}
```
-----
## Servo
### Servo Joystick
```c
#include <Servo.h>
Servo myservo_X;
void setup() {
myservo_X.attach(9);
Serial.begin(115200);
}
void loop() {
/*
for (byte j=20; j<140; j++){
myservo_X.write(j);
Serial.print("up j=");
Serial.println(j);
delay(25);
}
for (byte i=140; i>20; i--) {
myservo_X.write(i);
Serial.print("down i= ");
Serial.println(i);
delay(25);
}
*/
myservo_X.write(115);
delay(1000);
myservo_X.write(45);
delay(1000);
}
```
### Servo Led
```c
#include <Servo.h>
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // LED pin
boolean algo; // true si hay algo en rango
int i, j;
int maximumRange = 50; // Distancia maxima
int minimumRange = 10; // Distancia minima
long duration, distance; // Duración utílizada para calcular la distancia
Servo myservo; // instancia objero Servo
void setup() {
Serial.begin (9600);
myservo.attach(9); // pin asociado al objeto Servo
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT);
}
void loop() {
sensar();
accion();
if(!algo) {
while(i<171) {
for (i=j; i<=170; i++) { // giro sentido antihorario
myservo.write(i); // mueve el servo a la posición indicada
sensar();
accion();
j = i;
if(algo) break;
}
}
}
while(i>10) {
if(!algo) {
for (j=i; j>=10; j--) { // giro sentido horario
myservo.write(j); // mueve el servo a la posición indicada
sensar();
accion();
i=j;
if(algo) break;
}
}
sensar();
accion();
}
}
void accion() {
if (distance >= maximumRange || distance <= minimumRange){
Serial.println("Nada por aquí");
digitalWrite(LEDPin, LOW);
algo = false;
} else {
algo = true;
Serial.print("Objeto a: ");
Serial.print(distance);
Serial.println(" cm.");
digitalWrite(LEDPin, HIGH);
}
}
void sensar() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH); // demora del eco, para cálculo de distancia
distance = duration/58.2;
}
```
### Servo Termo
```c
#include <Servo.h>
Servo myservo_X;
bool estado_termo;
byte medio;
void setup() {
myservo_X.attach(9);
Serial.begin(9600);
}
void loop() {
/* Movimiento Servo, accion On (120) - Off (45)
* mitad real (75?)
* actuar a 3 etapas por lado
myservo_X.write(120);
delay(1000);
Serial.println("ON");
myservo_X.write(45);
delay(1000);
Serial.println("OFF");
*/
termo(estado_termo);
}
void termo(bool estado) {
if (!estado) {
Serial.println("ON");
myservo_X.write(120);
delay(500);
myservo_X.write(110);
delay(500);
myservo_X.write(120);
delay(500);
myservo_X.write(110);
delay(500);
myservo_X.write(120);
delay(2000);
estado_termo = !estado_termo;
} else {
Serial.println("OFF");
myservo_X.write(45);
delay(500);
myservo_X.write(62);
delay(500);
myservo_X.write(45);
delay(500);
myservo_X.write(62);
delay(500);
myservo_X.write(45);
delay(2000);
estado_termo = !estado_termo;
}
}
```
### Servos y potenciometros
```c
#include <Servo.h>
#define srv1 3
#define srv2 4
#define potX A0
#define potY A1
Servo srX;
Servo srY;
void setup() {
srX.attach(srv1);
srY.attach(srv2);
}
void loop() {
srX.write(map(analogRead(potX), 0, 1023, 0, 180));
delay(50);
srY.write(map(analogRead(potY), 0, 1023, 0, 180));
delay(50);
}
```
----
## Brushless
### Serial ESC
```c
#include <Servo.h>
Servo Esc;
#define pinEsc 9
int pwm_esc = 0;
void setup() {
Serial.begin(9600);
Esc.attach(pinEsc);
Esc.writeMicroseconds(1000);
Serial.println("iniciando");
delay(2000);
}
void loop() {
while(Serial.available() > 0) {
pwm_esc = Serial.parseInt();
if(Serial.read()=='\n') {
Esc.writeMicroseconds(pwm_esc);
Serial.print("Valor ESC: ");
Serial.println(pwm_esc);
}
delay(20);
}
}
//SOLO Nueva Linea /n
//Caviar min=1150/max=1900
//Para disco duro test1
//min 1620
//max 1900
```
----
## Paso a Paso
### Control PaP
```c
// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}
```
### Ajuste velocidad PaP
```c
// Defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
int customDelay,customDelayMapped; // Defines variables
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayMapped);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
int customDelay = analogRead(A0); // Reads the potentiometer
// Convert read values of pots from 0 to 1023 into
// desireded delay values (300 to 4000)
int newCustom = map(customDelay, 0, 1023, 300,4000);
return newCustom;
}
```
### PaP
Simple Stepper Motor Control Exaple Code
```c
// defines pins numbers
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000);
}
```
### PaP 5v
```c
#include <Stepper.h>
#define STEPS 100
Stepper stepper(STEPS, 8, 9, 10, 11);
int previous = 1;
void setup() {
stepper.setSpeed(90);
}
void loop() {
int val = analogRead(100);
stepper.step(val - previous);
previous = val;
delay(200);
}
```
### Stepper KeyStudio
```c
#include <Stepper.h>
#define STEPS 100
Stepper stepper(STEPS, 8, 9, 10, 11);
int previous = 0;
void setup() {
stepper.setSpeed(120);
Serial.begin(9600);
}
void loop() {
int val = analogRead(0);
Serial.println(val);
stepper.step(val - previous);
previous = val;
}
```

View File

View File

@ -1 +0,0 @@

View File

@ -0,0 +1,32 @@
## PWM
***Pulse Width Modulation*** / Modulación por ancho de pulso
[Arduino.cc](https://docs.arduino.cc/learn/microcontrollers/analog-output)
| Placa | Pines PWM | Frecuencia PWM |
| - | - | - |
| Uno, Nano, Mini | 3, 5, 6, 10, 11 | 490Hz (pines 5 y 6:980 Hz) |
| Mega | 2 -13, 44-46 | 490Hz (pines 4 y 13:980 Hz) |
| Micro | 3, 5, 6, 9, 10, 11, 13 | 490Hz (pines 3 y 11:980 Hz) |
[Arduino.cc](https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/)
#### PWM pin 9
```c
#define LED 9
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
for (byte i=20; i<255; i++) {
analogWrite(LED, i);
delay(5);
}
for (byte i=255; i>20; i--) {
analogWrite(LED, i);
delay(5);
}
}
```

20
sensores/README.md Normal file
View File

@ -0,0 +1,20 @@
## Sensores
- Temperatura y Humedad
- [DHT-11](./dht11/dht11.ino)
- [DHT-21](./dht21/dht21.ino)
- Distancia
- [GP2Y0A21YK0F](./distancia_gp2y0a21yk0f/distancia_gp2y0a21yk0f.ino)
- [HC-SR04](./distancia_hc-sr04/distancia_hc-sr04.ino)
- Humedad Suelo
- [Humedad](./humedad/humedad/humedad.ino)
- [Humedad LCD](./humedad/humedad_lcd/humedad_lcd.ino)
- IR
- [Control remoto](./ir/control_remoto_IR/control_remoto_IR.ino)
- [Repector IR](./ir/ir_receiver/ir_receiver.ino)
- [Repector IR 2](./ir/ir_receiver2/ir_receiver2.ino)
- Proximidad
- [Movimiento](./proximidad/sensor_mov/sensor_mov.ino)
- [Movimiento 2](./proximidad/sensor_mov2/sensor_mov2.ino)

26
tests/README.md Normal file
View File

@ -0,0 +1,26 @@
## Pruebas
- **OK**
- [RealTimeClock](./ok_rtc/ok_rtc.ino)
- [Joystick map Serial](./ok_map_joystick_serial/ok_map_joystick_serial.ino)
- [4 Relay](./ok_relay_x4/ok_relay_x4.ino)
- [lcd 2004](./ok_lcd_2004/ok_lcd_2004.ino)
- [lcd DHT](./ok_lcd_dht/ok_lcd_dht.ino)
- [lcd RTC](./ok_lcd_rtc/ok_lcd_rtc.ino)
- [lcd 4 RTC](./ok_lcd_rtc_x4/ok_lcd_rtc_x4.ino)
- [Mod](./ok_mod/ok_mod.ino)
- [RTC DHT](./ok_rtc_dht/ok_rtc_dht.ino)
- [SD read-write](./ok_sd_read_write/ok_sd_read_write.ino)
- [RTC SD write](./ok_sd_write_rtc/ok_sd_write_rtc.ino)
- [Oled-0.91 Graphs](./ok_oled_0.91_graphs/ok_oled_0.91_graphs.ino)
- [ESP01](./ok_esp01/ok_esp01.ino)
- [ESP php](./ok_esp_php/ok_esp_php.ino)
- **Test**
- [ESP8266](./test_esp8266/test_esp8266.ino)
- [ESP php](./test_esp_php/test_esp_php.ino)
- [ArduinoMega](./test_mega/test_mega.ino)
- [Mega ESP helloServer](./test_mega_esp_helloServer/test_mega_esp_helloServer.ino)
- [Datos a puerto Serial](./test_serial_datos_a_serie/test_serial_datos_a_serie.ino)
- [Serial a datos](./test_serial_serie_a_datos/test_serial_serie_a_datos.ino)
- [UART ESP helloServer](./test_uart_esp_helloServer/test_uart_esp_helloServer.ino)

View File

@ -112,3 +112,4 @@ String getHora(char var) {
} }
} }
} }

33
tests/ok_mod/ok_mod.ino Normal file
View File

@ -0,0 +1,33 @@
int x;
int z;
int y;
char temp;
void setup() {
Serial.begin(19200);
delay(4900);
Serial.println("|MOD : % |");
Serial.println("|x % y = z|");
Serial.println("-----------");
x=0;
z=0;
y=5;
}
void loop() {
while(x<11){
z=x%y;
Serial.print(" ");
Serial.print(x);
Serial.print(" % ");
Serial.print(y);
Serial.print(" = ");
Serial.println(z);
x++;
z=0;
//delay(10);
}
Serial.println("-----------");
delay(100);
setup();
}

View File

@ -1,27 +0,0 @@
int x;
int z;
int y;
char temp;
void setup() {
Serial.begin(9600);
delay(2000);
Serial.println("X % Y = Z");
x=0;
z=0;
y=10;
}
void loop() {
z=x%y;
Serial.print(" MOD : ");
Serial.print(x);
Serial.print(" % ");
Serial.print(y);
Serial.print(" = ");
Serial.println(z);
x++;
z=0;
delay(300);
}