How to use sensor reading for arduino POV scrolling text

Discussion in 'Embedded Systems and Microcontrollers' started by glenn_boy13, Feb 8, 2014.

  1. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    29
    0
    Hello. my project is working now. but I want to scroll the text.

    Code ( (Unknown Language)):
    1. // defining the alphabet
    2.  #include "font.h"
    3.  
    4.  // define the Arduino LED pins in use
    5.  const int LEDpins[] = {
    6.    8,7,6,5,4,3,2};
    7.  
    8.  // number of LEDs
    9.   const int charHeight = sizeof(LEDpins);
    10.   const int charWidth = 5;
    11.  
    12.  
    13.  
    14.  // sensor setup
    15.  const int sensorPIN = 12;  // define the Arduino sensor pin
    16.  
    17. //  boolean sensorFlag = false;  // stores sensor state
    18.   int sensVal;  // variable to store the value coming from the sensor
    19.  
    20.  
    21.  inr randomNum;
    22.  void setup()
    23.  {
    24.    pinMode(13, OUTPUT);
    25.  
    26.     pinMode(2, OUTPUT);
    27.      pinMode(3, OUTPUT);
    28.     pinMode(4, OUTPUT);
    29.     pinMode(5, OUTPUT);
    30.     pinMode(6, OUTPUT);
    31.      pinMode(7 , OUTPUT);
    32.    pinMode(8, OUTPUT);
    33.  
    34.    
    35.   //   Serial.begin(9600);
    36.  }
    37.  
    38.  void reverse_string(char str[])
    39. {
    40.     char c;
    41.     char *p, *q;
    42.  
    43.     p = str;
    44.     if (!p)
    45.         return;
    46.  
    47.     q = p + 1;
    48.     if (*q == '\0')
    49.         return;
    50.  
    51.     c = *p;
    52.     reverse_string(q);
    53.  
    54.     while (*q != '\0') {
    55.         *p = *q;
    56.         p++;
    57.         q++;
    58.     }
    59.     *p = c;
    60.  
    61.     return;
    62. }
    63.  
    64.  void loop()
    65.  {
    66.    
    67.    //try random
    68.    // turn on Led for a circle in middle and proof that arduino is powered
    69.     digitalWrite(13, HIGH);   // set the LED on  
    70.     char textString[] = "DIANA:)";
    71. //     reverse_string(textString);
    72.    sensVal = digitalRead(sensorPIN);  // read the Hall Effect Sensor  
    73.  
    74.     analogWrite(9, 0);
    75.    
    76.  
    77.  //    Serial.println(sensVal);
    78. // delay(500 );  
    79. // had difficulty here
    80. // since it is a switch hall switch probably shoiuld just do digital read
    81.  
    82.  if (sensVal == LOW) {
    83.    
    84.    // printing every letter of the textString
    85.    for (int k=0; k<sizeof(textString); k++){
    86.      printLetter(textString[k]);
    87.    }
    88.  
    89.  }
    90.  }
    91.  
    92.  
    93.  
    94.  
    95.  void printLetter(char ch)
    96.  {
    97.    // make sure the character is within the alphabet bounds (defined by the font.h file)
    98.    // if it's not, make it a blank character
    99.    
    100.    
    101.    
    102.     if (ch < 32 || ch > 126){
    103.      ch = 32;
    104.    }
    105.    // subtract the space character (converts the ASCII number to the font index number)
    106.    ch -= 32;
    107.    // step through each byte of the character array
    108.   for (int i=0; i<charWidth; i++) {
    109.      byte b = font[ch][i];
    110.      
    111.  
    112.  
    113.      // bit shift through the byte and output it to the pin
    114.      for (int j=charHeight; j>=0; j--) {
    115.        digitalWrite(LEDpins[j], !!(b & (1 << j)));
    116.      
    117.      }
    118.      // space between columns
    119.  
    120.  delayMicroseconds(900);
    121.    }
    122.    //clear the LEDs
    123.  
    124. digitalWrite(2 , LOW);   // set the LED on
    125. digitalWrite(3 , LOW);   // set the LED on
    126. digitalWrite(4 ,LOW);   // set the LED on
    127. digitalWrite(5 , LOW);   // set the LED on
    128. digitalWrite(6 , LOW);   // set the LED on
    129.     digitalWrite(7 , LOW);   // set the LED on
    130. digitalWrite(8 , LOW);   // set the LED on
    131.    // space between letters
    132.    delayMicroseconds(2500);
    133.  
    134.  }[/i]


    Here are my findings and the steps that I've already taken, but no help.

    I learned that charWidth is best to have a value of 5. that is constant smiley-grin As it was declared originally by the author of such codes in instructables. Yes, this project is modified by me. My project is a globe and the instructable is a fan.

    Findings:
    1. if the text is: "DIANA ROSE smiley" --- 13 characters or less than that( including white spaces), the result is super fine. super stable.
    2. if the text is longer than 13 characters, the display is still readable but not scrolling. ughhhhhhhhh
    say, my text is: "DIANA ROSE CUSTODIO smiley". first it will display the "DIANA ROSE CUST" then the rest. 2 displays each second.
    3. I also tried to remove the if(sensVal==LOW) and set the text to "DIANA ROSE CUSTODIO", it scrolls a bit but sometimes the 1st and 2nd and last name displays randomly.
    4. I also tried to edit the reading to: "IF(SENSVAL==HIGH)", it was no help too.

    someone from arduino forum said this:

    but I can't implement what he is trying to say. :( I've been trying my best for a long hours now.
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,387
    497
    Are we talking LCD display?
     
  3. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    Marquee type display are very simple. It is actually a beginners programming exercise.

    Here are the basics.

    1. You have a buffer containing some text. Longer than the display allows.

    2. A start variable that point to the start of the display buffer. Initialize this to zero.

    3. A length constant variable for the physical display.

    4. A variable that keeps track of the current position.

    5. Display your characters up to the length of the display. Increment current position for each character display.

    6. Increment the starting position.

    The hard part is to keep track of the current position. If it exceeds the length of the buffer, you will need to reset it to zero.

    If I have some time I will work up a demo but it will have to be for the pic. But if you searched, I am sure you will find plenty of examples.
     
    glenn_boy13 likes this.
  4. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    29
    0
    thumbs up for you sir. thanks, but I can't implement that all :(
    Perhaps I can understand it much better if there is an easy example even if it is in PIC. I've seen many POVs in arduino that keeps track of the current position, they have even computations, but I can't understand them all.

    sir shteii01 - it is a Persistence of Vision display . Not Led Matrices and not LCD.
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    Oh POV. The technique will be very similar to LCD. You have X spaces on LCD and you have X spaces in a POV.
     
  7. glenn_boy13

    Thread Starter New Member

    Dec 19, 2012
    29
    0

    hello sir! I am back, I've already studied the link you have given, but that uses an LCD library.

    I have here a complete code of GLOBE POV in arduino (a persistence of vision that displays globe map and rotating). It uses an interrupt for a reed switch. I know reed switch is the same with the hall effect, the same function I mean.

    I can't understand all of the GLOBE POV codes, I think I can, but that would take a long time. XD.

    my question is: do I need to use an interrupt to? In order for my text to scroll?
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,005
    If you can't understand the code then the project is most likely beyond you capability. Start with a less complex project like LCD.
     
Loading...