// Array for MB8719 standard 40 channels
//
// Individual elements are set in PLL chip pin order, pins 10,11,12,13,14,15, and 16. This corresponds
// to the I/O pins 23,25,27,29,31,33,and 35 from the Arduino Mega that I've chosen here.
//
// To expand the number of channels, add the seven bit values to the array
// and change the "[40]" to the new number of channels.
//
// The current arrangement is for the standard FCC channels in slots 0 through 39,
// including the "A" channel skips and the out of order channels 23,24, and 25.
//
//
int PLL[7]={23,25,27,29,31,33,35};
int CHSEL[7]={24,26,28,30,32,34,36};
// The ONES and TENS arrays control the LED channel display. Pins are arranged in ascending
// order a,b,c,d,e,f,g, such that Arduino pin 37 would connect to segment "a" of the ones digit seven
// segment display.
int ONES[7]={37,39,41,43,45,47,49};
int TENS[7]={38,40,42,44,46,48,50};
// The values here are for the seven segment LED display, and display the numbers 0 through 9, the
// letters A, b, c, d, E, and F, as well as a blanking character. If you ever see the letters,
// you know something's probably wrong or your new code works.
byte SVNSEG[16] [7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},
{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1},{1,1,1,0,1,1,1},
{0,0,1,1,1,1,1},{0,0,0,1,1,0,1},{0,1,1,1,1,0,1},{1,0,0,1,1,1,1},{1,0,0,0,1,1,1},
{0,0,0,0,0,0,0}};
byte CHNL[40] [7]={{1,0,0,1,1,1,1},{1,0,1,0,0,0,0},{1,0,1,0,0,0,1},{1,0,1,0,0,1,1},{1,0,1,0,1,0,0},
{1,0,1,0,1,0,1},{1,0,1,0,1,1,0},{1,0,1,1,0,0,0},{1,0,1,1,0,0,1},{1,0,1,1,0,1,0},
{1,0,1,1,0,1,1},{1,0,1,1,1,0,1},{1,0,1,1,1,1,0},{1,0,1,1,1,1,1},{1,1,0,0,0,0,0},
{1,1,0,0,0,1,0},{1,1,0,0,0,1,1},{1,1,0,0,1,0,0},{1,1,0,0,1,0,1},{1,1,0,0,1,1,1},
{1,1,0,1,0,0,0},{1,1,0,1,0,0,1},{1,1,0,1,1,0,0},{1,1,0,1,0,1,0},{1,1,0,1,0,1,1},
{1,1,0,1,1,0,1},{1,1,0,1,1,1,0},{1,1,0,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,0,0,0,1},
{1,1,1,0,0,1,0},{1,1,1,0,0,1,1},{1,1,1,0,1,0,0},{1,1,1,0,1,0,1},{1,1,1,0,1,1,0},
{1,1,1,0,1,1,1},{1,1,1,1,0,0,0},{1,1,1,1,0,0,1},{1,1,1,1,0,1,0},{1,1,1,1,0,1,1}};
void setup()
{
// "Ones" display
for(int a=0;a<7;a++){
pinMode(ONES[a], OUTPUT);}
// "Tens" display
for(int a=0;a<7;a++){
pinMode(TENS[a], OUTPUT);}
// PLL programming
for(int a=0;a < 7;a++){
pinMode(PLL[a], OUTPUT);}
// Channel select reading
for(int a=0;a < 7;a++){
pinMode(CHSEL[a], INPUT);}
}
void loop ()
{
for(int a=0;a < 7; a++){
digitalRead(CHSEL[a]);}
for(int CH=0; CH < 40; CH++){
for(int CHBIT=0; CHBIT < 7; CHBIT++){
int TEST1=CHNL[CH] [CHBIT];
int TEST2=CHSEL[CHBIT];
if(TEST1 == TEST2){
READCH=CH
}
}
}
if (READCH < CURRCH){
if (CURRCH < 40){
CURRCH++;
}else{
CURRCH=0;
}
}
if (READCH > CURRCH){
if ( CURRCH > 0){
CURRCH--;
}else{
CURRCH=39;
}
}
int CHP1=CURRCH + 1
int ONESchannel=CHP1 % 10;
int TENSchannel=CHP1 / 10;
if (TENSchannel == 0){
TENSchannel=16;}
for(int SVB=0;SVB < 7; SVB++){
digitalWrite(ONES[SVB], SVNSEG[ONESchannel][SVB]);
digitalWrite(TENS[SVB], SVNSEG[TENSchannel][SVB]);}
for(int SCHB=0;SCHB < 7; SCHB++){
digitalWrite(PLL[SCHB], CHNL[CURRCH][SCHB]);}
}