bo_kont.c


#include <stdio.h>
#include <wiringPi.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>

int btn_pin = 22;//Physical 31
int p_count = 1;
int flag = 0;
char i_c = '0';
char stringCom[12] = "mpc play 1";
char stringComStop[10] = "mpc stop";
int stringDat[9];
int i = 0;
int res = 0;

int decode (int res)
    {
        flag = 1;
        switch (res)
        {
        case 86 : {//PHONO
          p_count = 1;
                  }
                  break;
        case 84 : {//TAPE fr_sl
                  p_count = 1;
                  }
                  break;
    case 3 :  {//TAPE
          p_count = 1;
          }
          break;
        case 54 : {//AUX
           p_count = 1;
          }
                  break;
        case 50 : {//STOP
                  system (stringComStop);
                  flag = 0;
                  }
                  break;
        case 74 : {//T STOP
                  system (stringComStop);
                  flag = 0;
                  }
                  break;
        case 52 : {//OFF
                  system (stringComStop);
                  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;
        default:
                  {
                  flag = 0;
          return 0;
                  }
                }
                if (flag == 1)
                {
                if (p_count > 9)
                  {
                  p_count = 1;
                  }
                if (p_count < 1)
                  {
                  p_count = 9;
                  }
                i_c = p_count + 48;//int to char max 9
                stringCom[9] = i_c;
                system (stringCom);
                }
        return 0;
}

int main (void)
{
  if (wiringPiSetup () == -1)
    return 1 ;
  pinMode (btn_pin, INPUT);
  while (1)
     {
    while (digitalRead (btn_pin) == 1)
        {
        delay(0.5);
        pinMode (btn_pin, INPUT);
        if (digitalRead (btn_pin) == 0)
                {
                delay (1.5);
                for (i = 1; i < 8; i++)
                  {
                  delay(3.4);
                  stringDat[i] = (digitalRead (btn_pin));
                  }
                  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 (50);
        }
      }
   }
  return 0 ;
}

Compile med:   g++ -o bo_kont bo_kont.c -lwiringPi , installer wiringpi med: sudo apt-get install wiringpi

Bemærk: dette er ekspermentel software der er ingen garanti for brugbarhed, det kan derimod sandsynligvis være skadeligt, kun til brug i Danmark.
Bug: hurtige gentagne tryk kan låse program.