0% found this document useful (0 votes)
37 views

Codigo Arduino

This document contains code to control an LCD display and LED lights. It defines constants for the LCD pins and color pins. In setup, it initializes the LCD and sets pin modes. The main loop fades colors on the LEDs and scrolls text across the LCD in different directions, clearing the display between writes. It uses substrings to progressively show more of a text string on the LCD from left to right and vice versa.

Uploaded by

TIC TAC
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Codigo Arduino

This document contains code to control an LCD display and LED lights. It defines constants for the LCD pins and color pins. In setup, it initializes the LCD and sets pin modes. The main loop fades colors on the LEDs and scrolls text across the LCD in different directions, clearing the display between writes. It uses substrings to progressively show more of a text string on the LCD from left to right and vice versa.

Uploaded by

TIC TAC
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

// Incluímos la libreria externa para poder utilizarla

#include <LiquidCrystal.h> // Entre los símbolos <> buscará en la carpeta de


librerías configurada
#include <Servo.h>
Servo myservo;
// Definimos las constantes
#define COLS 16 // Columnas del LCD
#define ROWS 2 // Filas del LCD
#define VELOCIDAD 300 // Velocidad a la que se mueve el texto
#define BLUE 42
#define GREEN 43
#define RED 44
#define AZUL 45
#define VERDE 46
#define ROJO 47

// Lo primero is inicializar la librería indicando los pins de la interfaz


LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// Textos
String texto_fila = "Feliz Navidad Ha nacido Jesus";

void setup() {
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(BLUE, LOW);
pinMode(ROJO, OUTPUT);
pinMode(VERDE, OUTPUT);
pinMode(AZUL, OUTPUT);
digitalWrite(ROJO, HIGH);
digitalWrite(VERDE, LOW);
digitalWrite(AZUL, LOW);
myservo.attach(3);
myservo.write(0);// move servos to center position -> 90°
// Configuración monitor serie
Serial.begin(9600);
lcd.begin(COLS, ROWS); // Configuramos las filas y las columnas del LCD en este
caso 16 columnas y 2 filas
}
int redValue;
int greenValue;
int blueValue;
int rojoValue;
int verdeValue;
int azulValue;
void loop() {
#define delayTime 10 // fading time between colors

redValue = 255; // choose a value between 1 and 255 to change the color.
greenValue = 0;
blueValue = 0;

rojoValue = 255; // choose a value between 1 and 255 to change the color.
verdeValue = 0;
azulValue = 0;
// this is unnecessary as we've either turned on RED in SETUP
// or in the previous loop ... regardless, this turns RED off
// analogWrite(RED, 0);
// delay(1000);

for(int i = 0; i < 255; i += 1) // fades out red bring green full when i=255
{
redValue -= 1;
rojoValue -= 1;
greenValue += 1;
verdeValue += 1;
// The following was reversed, counting in the wrong directions
// analogWrite(RED, 255 - redValue);
// analogWrite(GREEN, 255 - greenValue);
analogWrite(RED, redValue);
analogWrite(ROJO, rojoValue);
analogWrite(GREEN, greenValue);
analogWrite(VERDE, verdeValue);
delay(delayTime);
}

redValue = 0;
greenValue = 255;
blueValue = 0;

rojoValue = 0;
verdeValue = 255;
azulValue = 0;

for(int i = 0; i < 255; i += 1) // fades out green bring blue full when i=255
{
greenValue -= 1;
verdeValue -= 1;
blueValue += 1;
azulValue += 1;
// The following was reversed, counting in the wrong directions
// analogWrite(GREEN, 255 - greenValue);
// analogWrite(BLUE, 255 - blueValue);
analogWrite(GREEN, greenValue);
analogWrite(VERDE, verdeValue);
analogWrite(BLUE, blueValue);
analogWrite(AZUL, azulValue);
delay(delayTime);
}

redValue = 0;
greenValue = 0;
blueValue = 255;
rojoValue = 0;
verdeValue = 0;
azulValue = 255;

for(int i = 0; i < 255; i += 1) // fades out blue bring red full when i=255
{
// The following code has been rearranged to match the other two similar
sections
blueValue -= 1;
azulValue -= 1;
redValue += 1;
rojoValue += 1;
// The following was reversed, counting in the wrong directions
// analogWrite(BLUE, 255 - blueValue);
// analogWrite(RED, 255 - redValue);
analogWrite(BLUE, blueValue);
analogWrite(AZUL, azulValue);
analogWrite(RED, redValue);
analogWrite(ROJO, rojoValue);
delay(delayTime);
}
int tam_texto=texto_fila.length();// Obtenemos el tamaño del texto

// Desplazamos el texto hacia la derecha


for(int i=1; i<=16;i++)
{
myservo.write(0);// move servos to center position -> 90°
delay(300);
myservo.write(360);// move servos to center position -> 180°
delay(300);
// Limpiamos pantalla
lcd.clear();
//Situamos el cursor
lcd.setCursor(i, 0);
// Escribimos el texto
lcd.print(texto_fila);
// Esperamos
delay(VELOCIDAD);
}

// Mostramos entrada texto por la izquierda


for(int i=tam_texto; i>0 ; i--)
{
String texto = texto_fila.substring(i-1);

// Limpiamos pantalla
lcd.clear();

//Situamos el cursor
lcd.setCursor(0, 0);

// Escribimos el texto
lcd.print(texto);

// Esperamos
delay(VELOCIDAD);
}

// Desplazamos el texto hacia la izquierda en la segunda fila


for(int i=16;i>=1;i--)
{
// Limpiamos pantalla
lcd.clear();

//Situamos el cursor
lcd.setCursor(i, 1);
// Escribimos el texto
lcd.print(texto_fila);

// Esperamos
delay(VELOCIDAD);
}

// Mostramos salida del texto por la izquierda


for(int i=1; i<=tam_texto ; i++)
{
String texto = texto_fila.substring(i-1);

// Limpiamos pantalla
lcd.clear();

//Situamos el cursor
lcd.setCursor(0, 1);

// Escribimos el texto
lcd.print(texto);

// Esperamos
delay(VELOCIDAD);
}
}

You might also like