Hi guys, i am new to arduino and i have worked out the following. What i need help is that i am stuck with trying to get my name scrolling backwards instead. Right now it is going from Left to right and down to row 2 left to right, what i'm trying to do is now instead of going from left to right i would like it to go backwards. Thanks! Any help is greatly appreciated
/*********************
Example code for the Adafruit RGB Character LCD Shield and Library
This code displays text on the shield, and also reads the buttons on the keypad.
When a button is pressed, the backlight changes color.
**********************/
// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7
String name="Choy kai Yoon", name_part="";
uint8_t name_length=name.length();
uint8_t count=name_length;
void setup() {
// Debugging output
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD. We track how long it takes since
// this library has been optimized a bit and we're proud of it :)
int time = millis();
//lcd.print("Hello, world!");
time = millis() - time;
//Serial.print("Took "); Serial.print(time); Serial.println(" ms");
lcd.setBacklight(WHITE);
setup_scroll();
}
void setup_scroll() {
lcd.cursor();
}
uint8_t i=0, row=0, column=16;
void loop() {
lcd.setCursor(i,(row+0)%2);
lcd.print(name);
if (i==16)
{ i=0;
row=(row+1)%2;
count=name_length;
}
delay(1000);
lcd.clear();
if (i>=(16-name_length))
{ count--;
name_part=name.substring(count);
lcd.setCursor(0,(row+1)%2);
lcd.print(name_part);
}
//lcd.setCursor(10, (row+1)%2);
//lcd.print(i);
//lcd.setCursor(14, (row+1)%2);
//lcd.print(count);
Serial.println(name+"\t"+name_part);
String stringTemp = "i= " + String(i) + " count= " + String(count);
Serial.println(stringTemp);
uint8_t buttons = lcd.readButtons();
if (buttons) {
lcd.clear();
lcd.setCursor(0,0);
if (buttons & BUTTON_UP) {
lcd.print("UP ");
lcd.setBacklight(RED);
}
if (buttons & BUTTON_DOWN) {
lcd.print("DOWN ");
lcd.setBacklight(YELLOW);
}
if (buttons & BUTTON_LEFT) {
lcd.print("LEFT ");
lcd.setBacklight(GREEN);
}
if (buttons & BUTTON_RIGHT) {
lcd.print("RIGHT ");
lcd.setBacklight(TEAL);
}
if (buttons & BUTTON_SELECT) {
lcd.print("SELECT ");
lcd.setBacklight(VIOLET);
}
}
i++;
}