sounds like you want to simulate you Arduino code on your PC. this is a common practice because it is so much easier and faster to build/test on a laptop
i use the following with a bunch of sub arduino functions.
readInput() reads a command file that specifies changes to inputs and simulating the results from digitalRead()
#ifndef SIM_H
# define SIM_H
# include <stdio.h>
# include <stdint.h>
# include <unistd.h>
# include <stdlib.h>
# include <string.h>
# include <math.h>
# include "Arduino.h"
# define PROGMEM
#define TWO_PI (3.14159265358979323846*2)
const char *Normal = "\033[0m";
const char *Black = "\033[30m";
const char *Red = "\033[31m";
const char *Green = "\033[32m";
const char *Yellow = "\033[33m";
const char *Blue = "\033[34m";
const char *Magenta = "\033[35m";
const char *Cyan = "\033[36m";
const char *White = "\033[37m";
unsigned int debug = 0;
unsigned int dbg = 0;
char s [100];
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
long
map (
long val,
long fromLow,
long fromHigh,
long toLow,
long toHigh )
{
return toLow + (toHigh - toLow) * (val - fromLow) / (fromHigh - fromLow);
}
// -----------------------------------------------------------------------------
class SoftwareSerial {
public:
SoftwareSerial (int txPin, int rxPin) {};
~SoftwareSerial (void) {};
void begin (int bps) {};
};
// -----------------------------------------------------------------------------
class Servo {
public:
Servo (void) {};
~Servo (void) {};
void attach (int pin) {printf (" Servo: pin %d\n", pin); };
void write (int val) {printf (" Servo: write %d\n", val); };
};
// -----------------------------------------------------------------------------
void
readInput (
char* filename)
{
static FILE *fp = NULL;
char p [80];
char *s = p;
if (NULL == fp) {
fp = fopen (filename, "r");
if (0 > fp) {
perror ("fopen");
exit (1);
}
}
while ((char *)NULL != fgets (p, sizeof(p), fp)) {
#if 0
if (1 >= strlen (p))
return;
#endif
if (3 <= dbg) printf (" %s: %d %s", __func__, strlen (p), p);
if (strstr (p, "pin")) {
int pn;
int val;
sscanf (p, "%*s %d %d", &pn, &val);
if (debug)
printf (" set pin %d to %d\n", pn, val);
pinVal [pn] = val;
}
else if (strstr (p, "anlg")) {
int pn;
int val;
sscanf (p, "%*s %d %d", &pn, &val);
if (debug)
printf (" set pin %d to %d\n", pn, val);
anlgVal [pn] = val;
}
else if (strstr (p, "loop")) {
int nLoop;
sscanf (p, "%*s %d", &nLoop);
while (nLoop--)
loop ();
}
}
printf (" %s: EOF\n", __func__);
exit (0);
}
// -------------------------------------
char *progname;
int main (int argc, char **argv) {
int c;
progname = *argv;
while ((c = getopt(argc, argv, "D:o")) != -1) {
printf (" %s: c %c\n", __func__, c);
switch (c) {
case 'D':
dbg = atoi (optarg);
printf ("%s: dbg %d\n", __func__, dbg);
break;
case 'o':
break;
default:
printf ("Error: unknown option '%c'\n", optopt);
break;
};
}
#define READ_INPUT
#ifdef READ_INPUT
if (optind == argc) {
printf ("Usage: %s filename\n", progname);
exit (1);
}
#endif
setup();
#ifdef READ_INPUT
readInput (argv [optind]);
#endif
}
#endif