bo_kont_dab.ino

int in=8;
int out=9;
int on=10;
int i=0;
int onP=0;
int res=0;
int flag=0;
int p_count=1;
int stringDat[9];
char stringDatCom[9]="00000000";
char stringDatOn[9]="10001010";
char stringAdd[9] = "00000001";
char stringDat1[9] = "10001100";
char stringDat2[9] = "01001100";
char stringDat3[9] = "11001100";
char stringDat4[9] = "00101100";
char stringDat5[9] = "10101100";
char stringDat6[9] = "01101100";
char stringDat7[9] = "11101100";
char stringDat8[9] = "00011100";
char stringDat9[9] = "10011100";
char stringDatSel[9] = "10110000";
char stringDatAup[9] = "01100100";
char stringDatAdown[9] = "00010100";

void setup() {
  // put your setup code here, to run once:
  pinMode(in,INPUT);
  pinMode(out,OUTPUT);
  pinMode(on,INPUT);
  digitalWrite(out, 1);
}

void loop() {
  // put your main code here, to run repeatedly:
  while (digitalRead(in) == 1)
  {
    delayMicroseconds (500);
    if (digitalRead (in) == 0)
      {
        delayMicroseconds (1500);
        for (i = 1; i < 8; i++)
          {
            delayMicroseconds (3100);
            stringDat[i] = (digitalRead (in));
          }
            res = 0;
            for (i = 1; i < 8; i++)
              {
                switch (i)
                  {
                    case 1 : res = stringDat[i] * 64;
                    break;
                    case 2 : res = res + (stringDat[i] * 32);
                    break;
                    case 3 : res = res + (stringDat[i] * 16);
                    break;
                    case 4 : res = res + (stringDat[i] * 8);
                    break;
                    case 5 : res = res + (stringDat[i] * 4);
                    break;
                    case 6 : res = res + (stringDat[i] * 2);
                    break;
                    case 7 : res = res + (stringDat[i] * 1);
                    break;
                    }
              }       
                decode (res); 
                delay (10);
        }
  }
}


int serOut (void)
  {
    digitalWrite (out, 1);
  delay (100);
  digitalWrite (out, 0);
  delay (9);
  digitalWrite (out, 1);
  delayMicroseconds (4500);
   for (i = 0; i < 8; i++)
    {
    if (stringAdd[i] == '1')
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (1600);
        }
    else
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (530);
        }
    }
    for (i = 0; i < 8; i++)
    {
    if (stringAdd[i] == '0')
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (1600);
        }
    else
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (530);
        }
    }
    for (i = 0; i < 8; i++)
    {
    if (stringDatCom[i] == '1')
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (1600);
        }
    else
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (530);
        }
    }
    for (i = 0; i < 8; i++)
    {
    if (stringDatCom[i] == '0')
        {
        digitalWrite (out, 0);
        delayMicroseconds (530);
        digitalWrite (out, 1);
        delayMicroseconds (1600);
        }
    else
        {
         digitalWrite (out, 0);
         delayMicroseconds (530);
         digitalWrite (out, 1);
         delayMicroseconds (530);
        }
    }
    digitalWrite (out, 0);
    delayMicroseconds (560);
    digitalWrite (out, 1);
    delay (20);
    return 0 ;
  }

int decode (int res)
  {
    flag = 1;
    if (digitalRead (on) == 1)
      onP = 1;
    else
      onP = 0;
    switch (res)
      {
        case 86 : {//PHONO
          if (onP == 0)
        {
        strcpy (stringDatCom, stringDatOn);
        serOut ();
        p_count = 1;
        }
      strcpy (stringDatCom, stringDatSel);
                  serOut ();
      flag = 0;
                  }
                  break;
        case 84 : {//TAPE fr_sl
      if (onP == 0)
        {
        strcpy (stringDatCom, stringDatOn);
                    serOut ();
        p_count = 1;
        }
                  strcpy (stringDatCom, stringDatSel);
                  serOut ();
                  flag = 0;
                  }
                  break;
  case 3 :  {//NUM
      delay (130);
      flag = 0;
      }
      break;
        case 54 : {//AUX
      if (onP == 0)
        {
        strcpy (stringDatCom, stringDatOn);
                    serOut ();
        p_count = 1;
        }
      strcpy (stringDatCom, stringDatSel);
                  serOut ();
                  flag = 0;
      }
                  break;
    case 50 : {//STOP
                  strcpy (stringDatCom, stringDatSel);
      serOut ();
                  flag = 0;
                  }
                  break;
        case 74 : {//T STOP
                  strcpy (stringDatCom, stringDatSel);
                  serOut ();
                  flag = 0;
                  }
                  break;
        case 52 : {//OFF
      if (onP == 1)
        {
                    strcpy (stringDatCom, stringDatOn);
        serOut ();
        }
                  flag = 0;
                  }
                  break;
        case 106 : p_count ++;//RIGHT ARROW
                  break;
        case 102 : p_count ++;//T RIGHT ARROW
                  break;
        case 12 : p_count --;//LEFT ARROW
                  break;
        case 76 : p_count --;//T LEFT ARROW
                  break;
  case 44 : {//RIGHT DOUBLE ARROW
                  strcpy (stringDatCom, stringDatAup);
                  serOut ();
      flag = 0;
                  }
                  break;
  case 78 : {//T RIGHT DOUBLE ARROW
      strcpy (stringDatCom, stringDatAup);
                  serOut ();
                  flag = 0;
      }
      break;
        case 46 : {//LEFT DOUBLE ARROW
                  strcpy (stringDatCom, stringDatAdown);
                  serOut ();
      flag = 0;
                  }
                  break;
  case 80 : {//T LEFT DOUBLE ARROW
      strcpy (stringDatCom, stringDatAdown);
                  serOut ();
                  flag = 0;
                  }
  case 124: {//1
      strcpy (stringDatCom, stringDat1);
      serOut ();
      flag = 0 ;
      delay (60);
      }
      break;
  case 122: {//2
      strcpy (stringDatCom, stringDat2);
                  serOut ();
      flag = 0;
      delay (60);
      }
      break;
  case 120: {//3
      strcpy (stringDatCom, stringDat3);
                  serOut ();
      flag = 0;
      delay (60);
      }
      break;
  case 118: {//4
                   strcpy (stringDatCom, stringDat4);
                  serOut ();
      flag = 0;
                  delay (60);
                  }
                  break;
        case 116: {//5
                  strcpy (stringDatCom, stringDat5);
                  serOut ();
      flag = 0;
                  delay (60);
                  }
                  break;
        case 114: {//6
                  strcpy (stringDatCom, stringDat6);
                  serOut ();
      flag = 0;
                  delay (60);
                  }
                  break;
  case 112: {//7
                  strcpy (stringDatCom, stringDat7);
                  serOut ();
      flag = 0;
                  delay (60);
                  }
                  break;
  case 110: {//8
                  strcpy (stringDatCom, stringDat8);
                  serOut ();
      flag = 0;
                  delay (60);
                  }
                  break;
        case 108: {//9
                  strcpy (stringDatCom, stringDat9);
                  serOut ();
      flag = 0;
                  delay (60);
                  }
                  break;
  default:  {
      flag = 0;
  return 0;
            }
                }
                if (flag == 1)
                {
                if (p_count > 9)
                  {
                  p_count = 1;
                  }
                if (p_count < 1)
                  {
                  p_count = 9;
                  }
    switch (p_count)
    {
    case 1 : {
      strcpy (stringDatCom, stringDat1);
      serOut ();
      }
      break;
    case 2 : {
      strcpy (stringDatCom, stringDat2);
      serOut ();
      }
      break;
    case 3 : {
      strcpy (stringDatCom, stringDat3);
      serOut ();
      }
      break;
    case 4 : {
      strcpy (stringDatCom, stringDat4);
      serOut ();
      }
      break;
    case 5 : {
      strcpy (stringDatCom, stringDat5);
      serOut ();
      }
      break;
    case 6 : {
      strcpy (stringDatCom, stringDat6);
      serOut ();
      }
      break;
    case 7 : {
      strcpy (stringDatCom, stringDat7);
      serOut ();
      }
      break;
    case 8 : {
      strcpy (stringDatCom, stringDat8);
      serOut ();
      }
      break;
    case 9 : {
      strcpy (stringDatCom, stringDat9);
      serOut ();
      }
      break;
    }
                }
    return 0;
}

Compile med: Arduino ide se www.arduino.cc

Bemærk: dette er eksperimentel software der er ingen garanti for brugbarhed, det kan derimod sandsynligvis være skadeligt, kun til brug i Danmark.