Search

ArachnidLabs minishift arduino example scrolling text

ArachnidLabs minishift arduino example scrolling text

As an addon from my last post, I have made a scrolling text display system.

It is a work in process and I think I have the logic backwards. I definitely need more boards to stack so I can see it to full effect!
You need to grab Adafruit’s glcdfont.c from https://github.com/adafruit/Adafruit-GFX-Library/raw/master/glcdfont.c

See it running at http://youtu.be/baRenpdT_Ew

edit: Silly me, I had coded it with the board upside down! No wonder my scroll was going the wrong way :P
The code below has been corrected.

file: minishift_text.pde

//Sample code to display text on the @ArachnidLabs minishift
// Written by Gregory Fenton, http://labby.co.uk

/*
Wiring:
latchPin connected to CS   (pin 4) of minishift
clockPin connected to SCK  (pin 3) of minishift
dataPin  connected to MOSI (pin 5) of minishift
*/

#include "glcdfont.c" // Adafruit glcdfont

int latchPin = 2;
int clockPin = 3;
int dataPin = 4;

char s[256] = "ArachnidLabs minishift example by Gregory Fenton, labby.co.uk";

void displayByte(int b)
{
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, b);
    digitalWrite(latchPin, HIGH);
}

void displayChar(int c)
{
  int i;
  if(c > 31 && c < 127)
  {
    for(i = 0; i < 5; i++)
    {
      displayByte(pgm_read_byte(font+(c * 5) + i));
      delay(50);
    }
    displayByte(0);
  }
}

void setup() {
  Serial.begin(9600);
  int i;
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  //clear display by sending 256 blank bytes
  //256 is arbitrary and should be changed to the number of
  //columns in your display
  for(i = 0; i < 256; i++)
  {
    displayByte(0);
  }
}

void loop() {
  // Display the numbers 0 to 255 in binary
  int i = 0, l;
  char c;
  
  while(Serial.available())
  {
    c = Serial.read();
    s[i++] = c;
    if(!Serial.available())
    {
      
      Serial.flush();
      s[i++] = 0;
      Serial.println(s);
    }
  }
  
  for(i = 0; s[i] != 0; i++);
  l = i;
  
  for(i = 0; i < l; i++)
  {
    displayChar(s[i]);
    if(Serial.available())
      break;
  }
  displayChar(' ');
}

Related posts

Leave a Comment