1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
int linen1 ;
int receive (int val )
{
char cmd[100];
FILE* fpipe ;
char line [100];
sprintf (cmd, "ousb pwm 1 %i", val );
fpipe =popen (cmd, "r");
pclose (fpipe );
fpipe =popen ( "ousb -r adc 0" , "r" );
fgets (line , sizeof(line) ,fpipe );
pclose (fpipe);
linen1 = atoi (line);
cout<<linen1;
return linen1;
}
int main(int argc, char *argv[])
{
switch (argv[1][0])
{
case 'M' :
char line[100];
FILE* fpipe;
fpipe =popen ("ousb pwm-freq 1 46 " , "r" );
pclose (fpipe);
fpipe = popen( "ousb pwm 1 50 " , "r");
pclose (fpipe);
fpipe =popen ("ousb -r adc 0" , "r");
fgets (line , sizeof(line),fpipe);
pclose (fpipe);
int number,linen;
linen = atoi(line);
cout<<linen;
number = atoi (argv[2]);
if (linen!= number)
{
if (linen > number )
{ int decrement = 50;
for (;;)
{
if (kbhit() && (getch() == 3))
{
return 0;
}
decrement--;
receive(decrement);
}
}
if (linen < number )
{ int increment = 50;
for (;;)
{
if (kbhit() && (getch() == 3))
{
return 0;
}
increment--;
receive(increment);
}
}
}
}
return EXIT_SUCCESS;
}
|