Arduino VFD brightness

From YobiWiki
Jump to navigation Jump to search

Back to Arduino page.

LiquidCrystal is great to control a LCD but it doesn't cover this little extension allowing to control a vacuum-fluorescent display (VFD) by software.
Here is how to do:
It is using the library

You can download the code [{{#file: testVFD.pde}} as testVFD.pde]

/*
  LiquidCrystal Library - demo
  Extension to control brightness of a Samsung 16T202DA1J VFD
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Adds definitions for VFD:
#define VFD_25pc  0x03
#define VFD_50pc  0x02
#define VFD_75pc  0x01
#define VFD_100pc 0x00
void vfd_brightness(int brightness) {
  // unfortunately lcd._displayfunction is private so we've to redefine it
  int _displayfunction = LCD_4BITMODE | LCD_2LINE | LCD_5x8DOTS;
  lcd.command(LCD_FUNCTIONSET | _displayfunction | brightness);
}

void setup() {
  // set up the LCD's number of rows and columns: 
  lcd.begin(2, 16);
  lcd.print("hello, world!");
}

void loop() {
  vfd_brightness(VFD_100pc);
  delay(200);
  vfd_brightness(VFD_75pc);
  delay(200);
  vfd_brightness(VFD_50pc);
  delay(200);
  vfd_brightness(VFD_25pc);
  delay(200);
  vfd_brightness(VFD_50pc);
  delay(200);
  vfd_brightness(VFD_75pc);
  delay(200);
}