Here is a fairly straightforward conversion of the BS2 program. I haven't had a chance to compile this so there might be a few syntax errors.
/*
* HC4LED.BS2 converted from PBASIC 2.5 to Arduino Wiring/Processing by
wandrson@yahoo.com * This program demonstrates the use of the HC4LED display module
* HC4LED Pinout:
* Pin1 = +5VDC (White wire)
* Pin2 = Gnd
* Pin3 = Blank (Must connect to Gnd to enable display)
* Pin4 = No Connection
* Pin5 = Clock (Connect to pin 1 for this demo program)
* Pin6 = Data (Connect to pin 0 for this demo program)
*
*
* To display values:
* Set the "zeros" variable to 0=No leading zeros; or 1=Show leading zeros
* Set the variable "value" to 0 to 9999
* Then use "GOSUB DisplayValue" to show the value on the display
*
* Each segment of the display is addressable, so you can create letters
* and symbols.
* To display custom symbols:
* Set the variables "segments(0)" thru "segments(3)" (segments(0) is on the left)
* simply add the segment values that you want on
* Then use "GOSUB DisplaySegments" to show the segments on the display
*
* ---4---
* | |
* 2 8
* | |
* |---1---|
* | |
* 64 16
* | |
* --32---
*
* For example "F" would be 4+2+1+64 = 71
*
*/
int Clock=13;
int Dat = 11;
int vWord; // Holds value to display
byte cnt; // Used by display routines
byte segment[4]; // Used by display routines & customer chars
int digits[] = {126, 24, 109, 61, 27, 55, 119, 28, 127, 31 }; // define numbers 0-9
void setup()
{
pinMode(Dat, OUTPUT);
pinMode(Clock, OUTPUT);
}
/*
* Call with:
* segments(0) thru segments(3) set to custom character values
* segments(0) is on the left; segments(3) is on the right
*/
void DisplaySegments()
{
shiftOut(Dat, Clock, MSBFIRST, segment[3]);
shiftOut(Dat, Clock, MSBFIRST, segment[2]);
shiftOut(Dat, Clock, MSBFIRST, segment[1]);
shiftOut(Dat, Clock, MSBFIRST, segment[0]);
digitalWrite(Dat, (segment[0] & 1));
digitalWrite(Clock, HIGH);
// Clock MUST remain high for at LEAST 1 millisecond for the
// new data to be latched onto the display.
delay(1);
}
/*
* Call with:
* parm = (value to display)
*/
void DisplayValue(int parm)
{
int dig3;
int dig2;
int dig1;
int dig0;
if (parm < 10000) {
dig3 = parm / 1000;
dig2 = (parm - (dig3 * 1000))/100;
dig1 = (parm - (dig3 * 1000) - (dig2 * 100))/10;
dig0 = (parm - (dig3 * 1000) - (dig2 * 100) - (dig1 * 10));
segment[0] = digits[dig0];
segment[1] = digits[dig1];
segment[2] = digits[dig2];
segment[3] = digits[dig3];
}
}
void loop()
{
int value;
while(1) // Repeat forever
{
for (value = 0; value <=1000; value++) // Count from 0 to 1000
{
DisplayValue(value); // Count from 0 to 1000
delay(1000); // Display count on HC4LED module
}
delay(10000); // Wait 1 second
segment[0] = 28; // Setup to display "72°F"
segment[1] = 109; // 2
segment[2] = 15; // °
segment[3] = 71; // F
DisplaySegments(); // Display custom characters
delay(20000); // Wait 2 seconds
} // Repeat forever
}