diff --git a/EEPROM/README.md b/EEPROM/README.md index 82dabeb..d48fd66 100644 --- a/EEPROM/README.md +++ b/EEPROM/README.md @@ -1,6 +1,6 @@ # EEPROM -*** Electrically Erasable Programmable Read-Only Memory*** +***Electrically Erasable Programmable Read-Only Memory*** ### Funciones @@ -14,33 +14,33 @@ #define VAR2 2 void setup() { - Serial.begin(9600); - delay(2000); - Serial.print("Capacidad de memoria"); - Serial.println(EEPROM.length()); - delay(500); - Serial.print("Valor almacenado en direccion 0: "); - Serial.println(EEPROM.read(dirVAR)); //read(direccion) - delay(500); - Serial.println("Guardando 39 en direccion 0"); - EEPROM.write(dirVAR, VAR); //Write(direccion, valor) - delay(500); - Serial.println("Guardando 32767 en direccion 1"); - EEPROM.write(dirVAR1, VAR1); //Write(direccion, valor) - delay(500); - Serial.println("Guardando 2 en direccion 2"); - EEPROM.write(dirVAR2, VAR2); //Write(direccion, valor) - delay(500); + Serial.begin(9600); + delay(2000); + Serial.print("Capacidad de memoria"); + Serial.println(EEPROM.length()); + delay(500); + Serial.print("Valor almacenado en direccion 0: "); + Serial.println(EEPROM.read(dirVAR)); //read(direccion) + delay(500); + Serial.println("Guardando 39 en direccion 0"); + EEPROM.write(dirVAR, VAR); //Write(direccion, valor) + delay(500); + Serial.println("Guardando 32767 en direccion 1"); + EEPROM.write(dirVAR1, VAR1); //Write(direccion, valor) + delay(500); + Serial.println("Guardando 2 en direccion 2"); + EEPROM.write(dirVAR2, VAR2); //Write(direccion, valor) + delay(500); } void loop() { - Serial.print("Valor en direccion 0: "); - Serial.println(EEPROM.read(dirVAR)); - Serial.print("Valor en direccion 1: "); - Serial.println(EEPROM.read(dirVAR1)); - Serial.print("Valor en direccion 3: "); - Serial.println(EEPROM.read(dirVAR2)); - delay(500); + Serial.print("Valor en direccion 0: "); + Serial.println(EEPROM.read(dirVAR)); + Serial.print("Valor en direccion 1: "); + Serial.println(EEPROM.read(dirVAR1)); + Serial.print("Valor en direccion 3: "); + Serial.println(EEPROM.read(dirVAR2)); + delay(500); } ``` diff --git a/README.md b/README.md index 991da4a..10447bb 100644 --- a/README.md +++ b/README.md @@ -10,21 +10,97 @@ alguna solución a una futura necesidad. Implementaciones : - - [Buzzers/Speakers](./buzzer/README.md) - - [BlueTooth](./bluetooth/README.md) - - [Comunicación Serial](./serialCom/README.md) - - [EEPROM](./EEPROM/README.md) - - [grbl](./grblUpload/README.md) - - [LCDs](./lcd/README.md) - - [Leds](./leds/README.md) - - [Motores](./motores/README.md) - -[DC](./motores/dc/README.md) - -[Servo](./motores/servo/README.md) - -[Brushless](./motores/brushless/README.md) - -[Paso a paso (stepper)](./motores/pap/README.md) - - [PWM](./pwm/README.md) - - [Real Time Clock](./RTC/README.md) - - [Sensores](./sensores/README.md) - - [Otros](./tests/README.md) +- [Comunicación Serial](./serialCom/README.md) +- [EEPROM](./EEPROM/README.md) +- [Buzzers/Speakers](./buzzer/README.md) +- [PWM](./pwm/README.md) +- [Leds](./leds/README.md) + - [Led Dimmer](./leds/dimmer_led/dimmer_led.ino) + - [Leds PWM](./leds/led_pwm/led_pwm.ino) + - [Leds PWM 1](./leds/leds_pwm/leds_pwm.ino) + - [Leds PwM 2](./leds/leds_pwm2/leds_pwm2.ino) + - [Potenciomentro y Led](./leds/potenciomentro_led/potenciomentro_led.ino) + - [RGB](./leds/rgb/rgb.ino) + - [RGB 2](./leds/rgb2/rgb2.ino) + - [RGB 3](./leds/rgb3/rgb3.ino) + - [Semaforo](./leds/semaforo/semaforo.ino) + - [Serial Leds](./leds/serial_leds/serial_leds.ino) +- [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) diff --git a/lcd/README.md b/lcd/README.md index e69de29..dbeb999 100644 --- a/lcd/README.md +++ b/lcd/README.md @@ -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) + diff --git a/lcd/metodo_8bits/metodo_8bits.ino b/lcd/metodo_8bits/metodo_8bits.ino index 439cbb9..fe88979 100755 --- a/lcd/metodo_8bits/metodo_8bits.ino +++ b/lcd/metodo_8bits/metodo_8bits.ino @@ -4,159 +4,144 @@ int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};// use array to select pin for bus int Enable = 2; void LcdCommandWrite(int value) { -// define all pins -int i = 0; -for (i=DB[0]; i <= DI; i++) // assign value for bus -{ - digitalWrite(i,value & 01);// for 1602 LCD, it uses D7-D0( not D0-D7) for signal identification; here, it’s used for signal inversion. - value >>= 1; -} -digitalWrite(Enable,LOW); -delayMicroseconds(1); -digitalWrite(Enable,HIGH); -delayMicroseconds(1); // wait for 1ms -digitalWrite(Enable,LOW); -delayMicroseconds(1); // wait for 1ms + int i = 0; + // assign value for bus + for (i=DB[0]; i <= DI; i++) { + // for 1602 LCD, it uses D7-D0( not D0-D7) for signal identification; + // here, it’s used for signal inversion. + digitalWrite(i,value & 01); + value >>= 1; + } + digitalWrite(Enable,LOW); + delayMicroseconds(1); + digitalWrite(Enable,HIGH); + delayMicroseconds(1); // wait for 1ms + digitalWrite(Enable,LOW); + delayMicroseconds(1); // wait for 1ms } void LcdDataWrite(int value) { -// initialize all pins -int i = 0; -digitalWrite(DI, HIGH); -digitalWrite(RW, LOW); -for (i=DB[0]; i <= DB[7]; i++) { - digitalWrite(i,value & 01); - value >>= 1; -} -digitalWrite(Enable,LOW); -delayMicroseconds(1); -digitalWrite(Enable,HIGH); -delayMicroseconds(1); -digitalWrite(Enable,LOW); -delayMicroseconds(1); // wait for 1ms + // initialize all pins + int i = 0; + digitalWrite(DI, HIGH); + digitalWrite(RW, LOW); + for (i=DB[0]; i <= DB[7]; i++) { + digitalWrite(i,value & 01); + value >>= 1; + } + digitalWrite(Enable,LOW); + delayMicroseconds(1); + digitalWrite(Enable,HIGH); + delayMicroseconds(1); + digitalWrite(Enable,LOW); + delayMicroseconds(1); // wait for 1ms } void setup (void) { -int i = 0; -for (i=Enable; i <= DI; i++) { - pinMode(i,OUTPUT); -} -delay(100); -// initialize LCD after a brief pause -// for LCD control -LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size -delay(64); -LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size -delay(50); -LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size -delay(20); -LcdCommandWrite(0x06); // set input mode - // auto-increment, no display of shifting -delay(20); -LcdCommandWrite(0x0E); // display setup - // turn on the monitor, cursor on, no flickering -delay(20); -LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 -delay(100); -LcdCommandWrite(0x80); // display setup - // turn on the monitor, cursor on, no flickering + int i = 0; + for (i=Enable; i <= DI; i++) { + pinMode(i,OUTPUT); + } + delay(100); + // initialize LCD after a brief pause + // for LCD control + LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size + delay(64); + LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size + delay(50); + LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size + delay(20); + LcdCommandWrite(0x06); // set input mode + // auto-increment, no display of shifting + delay(20); + LcdCommandWrite(0x0E); // display setup + // turn on the monitor, cursor on, no flickering + delay(20); + LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 + delay(100); + LcdCommandWrite(0x80); // display setup + // turn on the monitor, cursor on, no flickering -delay(20); + delay(20); } void loop (void) { - LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 - delay(10); - LcdCommandWrite(0x80+3); - delay(10); - // write in welcome message - LcdDataWrite('F'); - delay(50); - LcdDataWrite('u'); - delay(50); - LcdDataWrite('z'); - delay(50); - LcdDataWrite('a'); - delay(50); - LcdDataWrite('n'); - delay(50); - LcdDataWrite(' '); - delay(50); - LcdDataWrite('T'); - delay(50); - LcdDataWrite('o'); - delay(50); - LcdDataWrite('k'); - delay(50); - LcdDataWrite('o'); - delay(50); - LcdCommandWrite(0xc0+0); // set cursor position at second line, second position - delay(10); - LcdDataWrite('*'); - LcdDataWrite('*');delay(70); - LcdDataWrite('T');delay(90); - LcdDataWrite('U');delay(110); - LcdDataWrite('R');delay(130); - LcdDataWrite('B');delay(150); - LcdDataWrite('O');delay(170); - LcdDataWrite('-');delay(200); - LcdDataWrite('M');delay(170); - LcdDataWrite('A');delay(150); - LcdDataWrite('S');delay(130); - LcdDataWrite('T');delay(110); - LcdDataWrite('E');delay(90); - LcdDataWrite('R');delay(70); - LcdDataWrite('*'); - LcdDataWrite('*'); - delay(3000); - LcdCommandWrite(0x01); // clear the screen, cursor returns to 0 - delay(10); - LcdDataWrite('A'); - LcdDataWrite('p'); - LcdDataWrite('r'); - LcdDataWrite('e'); - LcdDataWrite('n'); - LcdDataWrite('d'); - LcdDataWrite('e'); - LcdDataWrite(' '); - LcdDataWrite('a'); - LcdDataWrite(' '); - LcdDataWrite('u'); - LcdDataWrite('s'); - LcdDataWrite('a'); - LcdDataWrite('r'); - LcdDataWrite(' '); - LcdDataWrite(' '); - LcdCommandWrite(0xc0); - LcdDataWrite(' '); - LcdDataWrite('T'); - LcdDataWrite('E'); - LcdDataWrite('R'); - LcdDataWrite('M'); - LcdDataWrite('U'); - LcdDataWrite('X'); - LcdDataWrite(','); - LcdDataWrite(' '); - LcdDataWrite('d'); - LcdDataWrite('e'); - LcdDataWrite('s'); - LcdDataWrite('p'); - LcdDataWrite('u'); - LcdDataWrite('e'); - 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); + LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 + delay(10); + LcdCommandWrite(0x80+3); + delay(10); + // write in welcome message + LcdDataWrite('F'); + delay(50); + LcdDataWrite('u'); + delay(50); + LcdDataWrite('z'); + delay(50); + LcdDataWrite('a'); + delay(50); + LcdDataWrite('n'); + delay(50); + LcdDataWrite(' '); + delay(50); + LcdDataWrite('T'); + delay(50); + LcdDataWrite('o'); + delay(50); + LcdDataWrite('k'); + delay(50); + LcdDataWrite('o'); + delay(50); + LcdCommandWrite(0xc0+0); // set cursor position at second line, second position + delay(10); + LcdDataWrite('*'); + LcdDataWrite('*');delay(70); + LcdDataWrite('A');delay(90); + LcdDataWrite('R');delay(110); + LcdDataWrite('D');delay(130); + LcdDataWrite('U');delay(150); + LcdDataWrite('I');delay(170); + LcdDataWrite('N');delay(200); + LcdDataWrite('O');delay(170); + LcdDataWrite('-');delay(150); + LcdDataWrite('L');delay(130); + LcdDataWrite('E');delay(110); + LcdDataWrite('A');delay(90); + LcdDataWrite('R');delay(70); + LcdDataWrite('N');delay(70); + LcdDataWrite('*'); + LcdDataWrite('*'); + delay(3000); + LcdCommandWrite(0x01); // clear the screen, cursor returns to 0 + delay(10); + LcdDataWrite('A'); + LcdDataWrite('p'); + LcdDataWrite('r'); + LcdDataWrite('e'); + LcdDataWrite('n'); + LcdDataWrite('d'); + LcdDataWrite('e'); + LcdDataWrite(' '); + LcdDataWrite(' '); + LcdDataWrite('c'); + LcdDataWrite('r'); + LcdDataWrite('e'); + LcdDataWrite('a'); + LcdDataWrite(' '); + LcdDataWrite(' '); + LcdCommandWrite(0xc0); + delay(2000); + // set mode as new characters replay old ones, + // where there is no new ones remain the same + LcdCommandWrite(0xc02); + delay(10); + // set cursor position at first line, sixth position + LcdCommandWrite(0xc80+6); + delay(10); + LcdDataWrite('o'); + LcdDataWrite('p'); + LcdDataWrite('e'); + LcdDataWrite('n'); + LcdDataWrite(' '); + LcdDataWrite('s'); + delay(3000); } - diff --git a/leds/README.md b/leds/README.md index e69de29..363cba2 100644 --- a/leds/README.md +++ b/leds/README.md @@ -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) + + diff --git a/motores/README.md b/motores/README.md index e69de29..339a471 100644 --- a/motores/README.md +++ b/motores/README.md @@ -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 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 +#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 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 +#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 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 +#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 +#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; +} +``` + diff --git a/motores/brushless/README.md b/motores/brushless/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/motores/dc/README.md b/motores/dc/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/motores/pap/README.md b/motores/pap/README.md deleted file mode 100644 index 8d1c8b6..0000000 --- a/motores/pap/README.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/motores/servo/README.md b/motores/servo/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/pwm/README.md b/pwm/README.md index e69de29..016727f 100644 --- a/pwm/README.md +++ b/pwm/README.md @@ -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); + } +} +``` diff --git a/sensores/README.md b/sensores/README.md new file mode 100644 index 0000000..45aa7ee --- /dev/null +++ b/sensores/README.md @@ -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) + + diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..dca9bbf --- /dev/null +++ b/tests/README.md @@ -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) + diff --git a/tests/OK_ESP01/OK_ESP01.ino b/tests/ok_esp01/ok_esp01.ino similarity index 100% rename from tests/OK_ESP01/OK_ESP01.ino rename to tests/ok_esp01/ok_esp01.ino diff --git a/tests/OK_ESP_php/OK_ESP_php.ino b/tests/ok_esp_php/ok_esp_php.ino similarity index 100% rename from tests/OK_ESP_php/OK_ESP_php.ino rename to tests/ok_esp_php/ok_esp_php.ino diff --git a/tests/OK_LCD-2004/OK_LCD-2004.ino b/tests/ok_lcd_2004/ok_lcd_2004.ino similarity index 100% rename from tests/OK_LCD-2004/OK_LCD-2004.ino rename to tests/ok_lcd_2004/ok_lcd_2004.ino diff --git a/tests/OK_DHT_LCD/OK_DHT_LCD.ino b/tests/ok_lcd_dht/ok_lcd_dht.ino similarity index 99% rename from tests/OK_DHT_LCD/OK_DHT_LCD.ino rename to tests/ok_lcd_dht/ok_lcd_dht.ino index fb4abbc..60c08c6 100755 --- a/tests/OK_DHT_LCD/OK_DHT_LCD.ino +++ b/tests/ok_lcd_dht/ok_lcd_dht.ino @@ -111,4 +111,5 @@ String getHora(char var) { return (String)fecha.second();break; } } -} +} + diff --git a/tests/OK_RTC_LCD/OK_RTC_LCD.ino b/tests/ok_lcd_rtc/ok_lcd_rtc.ino similarity index 100% rename from tests/OK_RTC_LCD/OK_RTC_LCD.ino rename to tests/ok_lcd_rtc/ok_lcd_rtc.ino diff --git a/tests/OK_RTCx4_LCD/OK_RTCx4_LCD.ino b/tests/ok_lcd_rtc_x4/ok_lcd_rtc_x4.ino similarity index 100% rename from tests/OK_RTCx4_LCD/OK_RTCx4_LCD.ino rename to tests/ok_lcd_rtc_x4/ok_lcd_rtc_x4.ino diff --git a/tests/OK_Serial_Joystick_map/OK_Serial_Joystick_map.ino b/tests/ok_map_joystick_serial/ok_map_joystick_serial.ino similarity index 100% rename from tests/OK_Serial_Joystick_map/OK_Serial_Joystick_map.ino rename to tests/ok_map_joystick_serial/ok_map_joystick_serial.ino diff --git a/tests/ok_mod/ok_mod.ino b/tests/ok_mod/ok_mod.ino new file mode 100644 index 0000000..fc81af2 --- /dev/null +++ b/tests/ok_mod/ok_mod.ino @@ -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(); +} diff --git a/tests/OK_Oled-0.91_Graphs/OK_Oled-0.91_Graphs.ino b/tests/ok_oled_0.91_graphs/ok_oled_0.91_graphs.ino similarity index 100% rename from tests/OK_Oled-0.91_Graphs/OK_Oled-0.91_Graphs.ino rename to tests/ok_oled_0.91_graphs/ok_oled_0.91_graphs.ino diff --git a/tests/OK_Relay_x4/OK_Relay_x4.ino b/tests/ok_relay_x4/ok_relay_x4.ino similarity index 100% rename from tests/OK_Relay_x4/OK_Relay_x4.ino rename to tests/ok_relay_x4/ok_relay_x4.ino diff --git a/tests/OK_RTC/OK_RTC.ino b/tests/ok_rtc/ok_rtc.ino similarity index 100% rename from tests/OK_RTC/OK_RTC.ino rename to tests/ok_rtc/ok_rtc.ino diff --git a/tests/OK_RTC_DHT/OK_RTC_DHT.ino b/tests/ok_rtc_dht/ok_rtc_dht.ino similarity index 100% rename from tests/OK_RTC_DHT/OK_RTC_DHT.ino rename to tests/ok_rtc_dht/ok_rtc_dht.ino diff --git a/tests/OK_SD_rd_wr/OK_SD_rd_wr.ino b/tests/ok_sd_read_write/ok_sd_read_write.ino similarity index 100% rename from tests/OK_SD_rd_wr/OK_SD_rd_wr.ino rename to tests/ok_sd_read_write/ok_sd_read_write.ino diff --git a/tests/OK_RTC_SD_wr/OK_RTC_SD_wr.ino b/tests/ok_sd_write_rtc/ok_sd_write_rtc.ino similarity index 100% rename from tests/OK_RTC_SD_wr/OK_RTC_SD_wr.ino rename to tests/ok_sd_write_rtc/ok_sd_write_rtc.ino diff --git a/tests/prueba_mod/prueba_MOD.ino b/tests/prueba_mod/prueba_MOD.ino deleted file mode 100755 index fa6961a..0000000 --- a/tests/prueba_mod/prueba_MOD.ino +++ /dev/null @@ -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); -} diff --git a/tests/TEST_ESP8266/TEST_ESP8266.ino b/tests/test_esp8266/test_esp8266.ino similarity index 100% rename from tests/TEST_ESP8266/TEST_ESP8266.ino rename to tests/test_esp8266/test_esp8266.ino diff --git a/tests/TEST_ESP_php/TEST_ESP_php.ino b/tests/test_esp_php/test_esp_php.ino similarity index 100% rename from tests/TEST_ESP_php/TEST_ESP_php.ino rename to tests/test_esp_php/test_esp_php.ino diff --git a/tests/TEST_Mega/TEST_Mega.ino b/tests/test_mega/test_mega.ino similarity index 100% rename from tests/TEST_Mega/TEST_Mega.ino rename to tests/test_mega/test_mega.ino diff --git a/tests/TEST_MegaESP_helloServer/TEST_MegaESP_helloServer.ino b/tests/test_mega_esp_helloServer/test_mega_esp_helloServer.ino similarity index 100% rename from tests/TEST_MegaESP_helloServer/TEST_MegaESP_helloServer.ino rename to tests/test_mega_esp_helloServer/test_mega_esp_helloServer.ino diff --git a/tests/TEST_SerialCom-1_datos_a_serie/TEST_SerialCom-1_datos_a_serie.ino b/tests/test_serial_datos_a_serie/test_serial_datos_a_serie.ino similarity index 100% rename from tests/TEST_SerialCom-1_datos_a_serie/TEST_SerialCom-1_datos_a_serie.ino rename to tests/test_serial_datos_a_serie/test_serial_datos_a_serie.ino diff --git a/tests/TEST_SerialCom-2_serie_a_datos/TEST_SerialCom-2_serie_a_datos.ino b/tests/test_serial_serie_a_datos/test_serial_serie_a_datos.ino similarity index 100% rename from tests/TEST_SerialCom-2_serie_a_datos/TEST_SerialCom-2_serie_a_datos.ino rename to tests/test_serial_serie_a_datos/test_serial_serie_a_datos.ino diff --git a/tests/TEST_UART_ESP01_helloServer/TEST_UART_ESP01_helloServer.ino b/tests/test_uart_esp_helloServer/test_uart_esp_helloServer.ino similarity index 100% rename from tests/TEST_UART_ESP01_helloServer/TEST_UART_ESP01_helloServer.ino rename to tests/test_uart_esp_helloServer/test_uart_esp_helloServer.ino