Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  4.  
  5. bool first = true;
  6. char text1[17] = "Salut,";
  7. char text2[17] = "Alexandru!";
  8. char text3[17] = "";
  9. char text4[17] = "";
  10.  
  11. void setup()
  12. {
  13. lcd.begin (16,2);
  14. }
  15.  
  16. void loop()
  17. {
  18. if(first) {
  19. convert(text1, 0);
  20. convert(text2, 1);
  21. lcd.setCursor(0, 0);
  22. lcd.write(text1);
  23. lcd.setCursor(0, 1);
  24. lcd.write(text2);
  25. first = false;
  26. delay(100);
  27. }
  28.  
  29. for(int i = 0; i < 16; i++) {
  30. if(!i) {
  31. text3[i] = text1[15];
  32. continue;
  33. }
  34. text3[i] = text1[i-1];
  35. }
  36.  
  37. for(int i = 15; i >= 0; i--) {
  38. if(i == 15) {
  39. text4[i] = text2[0];
  40. continue;
  41. }
  42. text4[i] = text2[i+1];
  43. }
  44.  
  45. strcpy(text1, text3);
  46. strcpy(text2, text4);
  47. lcd.setCursor(0, 0);
  48. lcd.write(text1);
  49. lcd.setCursor(0, 1);
  50. lcd.write(text2);
  51. delay(100);
  52. }
  53.  
  54. void convert(char text[], int position) {
  55. char fill[17] = "";
  56. int length = strlen(text);
  57.  
  58. for(int i = 0; i < 16 - length; i++) {
  59. strcat(fill," ");
  60. }
  61.  
  62. if(position) {
  63. strcat(fill, text);
  64. strcpy(text, fill);
  65. return;
  66. }
  67. strcat(text, fill);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement